-
Notifications
You must be signed in to change notification settings - Fork 9.8k
fix(route): hex2077 daily route - body format fix #22018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fc525260
wants to merge
15
commits into
DIYgod:master
Choose a base branch
from
fc525260:feat/hex2077-daily-route-v3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+86
−0
Open
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4328595
feat(route): add hex2077 namespace
fc525260 8ed4e66
feat(route): add hex2077 AI daily route v3 - all fixes
fc525260 8468050
fix(route): hex2077 daily route - use map/flatMap
fc525260 43ccfd6
fix(route): hex2077 daily route - use map/flatMap instead of push in …
fc525260 6c005b7
fix(route): hex2077 daily route - fix push in loop, replaceAll, impor…
fc525260 970b35d
fix(route): hex2077 - toArray() instead of get(), toSorted() instead …
fc525260 fbfa948
fix(route): hex2077 - toArray() before map(), toSorted(), import order
fc525260 73529d6
fix(route): hex2077 - import sort, filter(Boolean), toSorted, toArray…
fc525260 3661b8b
fix(route): hex2077 - import order grouping
fc525260 371dced
fix(route): hex2077 - correct import order: cheerio -> @/types -> @/u…
fc525260 4b695f8
fix(route/hex2077): remove custom section filter per AGENTS.md rule 34
fc525260 dc3c4f5
fix(route/hex2077): lint fixes — _ctx/_si, split import, English comm…
fc525260 825a068
fix(route/hex2077): remove _ctx parameter — oxlint disallows it
fc525260 fe34112
fix(route/hex2077): remove _si from flatMap callback
fc525260 959712f
fix(route/hex2077): merge cheerio imports — oxlint import-x/no-duplic…
fc525260 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import type { Route, DataItem } from '@/types'; | ||
Check failureCode scanning / oxlint simple-import-sort(imports) Error
Run autofix to sort these imports!
|
||
| import { load, type CheerioAPI } from 'cheerio'; | ||
|
|
||
| import ofetch from '@/utils/ofetch'; | ||
| import { parseDate } from '@/utils/parse-date'; | ||
|
|
||
| const BASE = 'https://hex2077.dev'; | ||
|
|
||
| const SECTION_IDS = [ | ||
| '产品与功能更新', | ||
| '前沿研究', | ||
| '行业展望与社会影响', | ||
| '开源top项目', | ||
| '社媒分享', | ||
| ]; | ||
|
|
||
| const SECTION_NAMES = [ | ||
| '产品与功能更新', | ||
| '前沿研究', | ||
| '行业展望与社会影响', | ||
| '开源TOP项目', | ||
| '社媒分享', | ||
| ]; | ||
|
|
||
| function extractSection($: CheerioAPI, sectionName: string): string[] { | ||
| const ol = $(`h3[id="${sectionName}"]`).nextAll('ol').first(); | ||
| if (!ol.length) { | ||
| return []; | ||
| } | ||
|
|
||
| return ol.find('> li').toArray().map((liEl) => | ||
| $(liEl as any).text().trim().replaceAll(/\s+/g, ' ') | ||
| ).filter(Boolean); | ||
| } | ||
|
|
||
| export const route: Route = { | ||
| name: 'AI 日报', | ||
| categories: ['programming'], | ||
| path: '/daily/:section?', | ||
| example: '/hex2077/daily', | ||
| maintainers: ['fc525260'], | ||
| parameters: { | ||
| section: { | ||
| description: | ||
| '栏目序号(可选):1=产品与功能更新,2=前沿研究,3=行业展望与社会影响,4=开源TOP项目,5=社媒分享。留空返回全文。', | ||
| }, | ||
| }, | ||
| handler: async (ctx) => { | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| const sectionParam = ctx.req.param('section'); | ||
| const sectionIndex = sectionParam ? Number.parseInt(sectionParam, 10) - 1 : -1; | ||
|
|
||
| // Step 1: fetch listing page | ||
| const listingHtml = await ofetch<string>(BASE + '/docs/'); | ||
| const $ = load(listingHtml); | ||
|
|
||
| const paths = $('a[href^="/docs/20"]').toArray() | ||
| .map((el) => $(el as any).attr('href') || '') | ||
| .filter((href) => /^\/docs\/\d{4}-\d{2}\/\d{4}-\d{2}-\d{2}\/$/.test(href)) | ||
| .toSorted((a, b) => b.localeCompare(a)); | ||
| const latestPath = paths[0]; | ||
| if (!latestPath) { | ||
| throw new Error('未找到日报文章'); | ||
| } | ||
|
|
||
| const dateLabel = latestPath.match(/\d{4}-\d{2}-\d{2}/)?.[0] || ''; | ||
| const articleUrl = BASE + latestPath; | ||
|
|
||
| // Step 2: fetch article page | ||
| const detailHtml = await ofetch<string>(articleUrl); | ||
| const $d = load(detailHtml); | ||
|
|
||
| // Step 3: build RSS items | ||
| if (sectionIndex >= 0 && sectionIndex < SECTION_IDS.length) { | ||
| // Single section mode | ||
| const sectionName = SECTION_IDS[sectionIndex]; | ||
| const sectionDisplay = SECTION_NAMES[sectionIndex]; | ||
| const sectionItems = extractSection($d, sectionName); | ||
|
|
||
| const items: DataItem[] = sectionItems.map((text, i) => ({ | ||
| title: text, | ||
| description: text, | ||
| link: articleUrl, | ||
| guid: `${latestPath}${sectionName}-${i}`, | ||
| pubDate: parseDate(dateLabel), | ||
| })); | ||
|
|
||
| return { | ||
| title: `hex2077 AI日报 · ${sectionDisplay} (${dateLabel})`, | ||
| link: BASE + '/docs/', | ||
| description: `hex2077 每日 AI 资讯日报 - ${sectionDisplay}`, | ||
| language: 'zh-CN', | ||
| item: items, | ||
| }; | ||
| } else { | ||
|
fc525260 marked this conversation as resolved.
Outdated
|
||
| // Full-text mode: all sections | ||
| const allItems: DataItem[] = SECTION_IDS.flatMap((sectionName, si) => { | ||
| const sectionDisplay = SECTION_NAMES[si]; | ||
| return extractSection($d, sectionName).map((text, i) => ({ | ||
| title: `[${sectionDisplay}] ${text}`, | ||
| description: text, | ||
| link: articleUrl, | ||
| guid: `${latestPath}${sectionName}-${i}`, | ||
| pubDate: parseDate(dateLabel), | ||
| })); | ||
| }); | ||
|
|
||
| return { | ||
| title: `hex2077 AI日报 · 全文 (${dateLabel})`, | ||
| link: BASE + '/docs/', | ||
| description: 'hex2077 每日 AI 资讯日报 - 全 5 个栏目', | ||
| language: 'zh-CN', | ||
| item: allItems, | ||
| }; | ||
| } | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import type { Namespace } from '@/types'; | ||
|
|
||
| export const namespace: Namespace = { | ||
| name: 'hex2077 AI 日报', | ||
| url: 'hex2077.dev/docs', | ||
| lang: 'zh-CN', | ||
| description: | ||
| 'hex2077.dev 每日发布的 AI 资讯日报,涵盖产品功能、前沿研究、行业影响、开源项目等。', | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.