-
Notifications
You must be signed in to change notification settings - Fork 9.5k
feat(route): add opengithub-weekly-rank route, display the journal of opengithub on github trending #21084
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
base: master
Are you sure you want to change the base?
feat(route): add opengithub-weekly-rank route, display the journal of opengithub on github trending #21084
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { Namespace } from '@/types'; | ||
|
|
||
| export const namespace: Namespace = { | ||
| name: 'opengithub-trending', | ||
| url: 'github.com/OpenGithubs/github-weekly-rank/', | ||
| description: `OpenGithubs Weekly 是一个开源项目, | ||
| 旨在每周分享 GitHub 上最受欢迎的开源项目。 | ||
| `, | ||
| lang: 'zh-CN', | ||
| zh: { | ||
| name: 'github每周趋势', | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import type { Route } from '@/types'; | ||
| import got from '@/utils/got'; | ||
| import { parseDate } from '@/utils/parse-date'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/weekly', | ||
| categories: ['programming'], | ||
| example: '/opengithub-trending/weekly', | ||
| parameters: {}, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['github.com/OpenGithubs/github-weekly-rank'], | ||
| target: '/opengithub-trending/weekly', | ||
| }, | ||
| ], | ||
| name: 'Weekly Rank', | ||
| maintainers: ['Nemocccc'], | ||
| description: '追踪 OpenGithubs 每周发布的开源项目排行榜', | ||
| handler, | ||
| }; | ||
|
|
||
| async function handler() { | ||
| const repoUrl = 'https://api.github.com/repos/OpenGithubs/github-weekly-rank/contents'; | ||
|
|
||
| const yearResponse = await got(repoUrl); | ||
| const years = yearResponse.data | ||
| .filter((item: any) => item.type === 'dir' && /^\d{4}$/.test(item.name)) | ||
| .sort((a: any, b: any) => b.name.localeCompare(a.name)) | ||
Check warningCode scanning / ESLint Prefer `Array#toSorted()` over `Array#sort()`. Warning
Use Array#toSorted() instead of Array#sort().
|
||
| .slice(0, 2); | ||
|
|
||
| const monthPromises = years.map((yearItem: any) => | ||
| got(repoUrl + '/' + yearItem.name).then((monthResponse) => ({ | ||
| year: yearItem.name, | ||
| months: monthResponse.data | ||
| .filter((item: any) => item.type === 'dir') | ||
| .sort((a: any, b: any) => b.name.localeCompare(a.name)) | ||
Check warningCode scanning / ESLint Prefer `Array#toSorted()` over `Array#sort()`. Warning
Use Array#toSorted() instead of Array#sort().
|
||
| .slice(0, 3), | ||
| })) | ||
| ); | ||
|
|
||
| const monthData = await Promise.all(monthPromises); | ||
|
|
||
| const dayPromises = monthData.flatMap(({ year, months }: any) => | ||
| months.map((monthItem: any) => | ||
| got(repoUrl + '/' + year + '/' + monthItem.name).then((dayResponse) => ({ | ||
| year, | ||
| month: monthItem.name, | ||
| days: dayResponse.data | ||
| .filter((item: any) => item.type === 'file' && item.name.endsWith('.md')) | ||
| .sort((a: any, b: any) => b.name.localeCompare(a.name)) | ||
Check warningCode scanning / ESLint Prefer `Array#toSorted()` over `Array#sort()`. Warning
Use Array#toSorted() instead of Array#sort().
|
||
| .slice(0, 5), | ||
| })) | ||
| ) | ||
| ); | ||
|
|
||
| const allDayData = await Promise.all(dayPromises); | ||
|
|
||
| const filePromises = allDayData.flatMap(({ year, month, days }: any) => | ||
| days.map((dayItem: any) => { | ||
| const fileName = dayItem.name.replace('.md', ''); | ||
| const fileUrl = 'https://raw.githubusercontent.com/OpenGithubs/github-weekly-rank/main/' + year + '/' + month + '/' + dayItem.name; | ||
| return got(fileUrl).then((fileContent) => ({ | ||
|
Comment on lines
+33
to
+70
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an option to accept GitHub token for a higher API limit. |
||
| title: 'GitHub Weekly Rank - ' + fileName, | ||
| description: fileContent.data, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use markdown-it to render the markdown content. |
||
| link: 'https://github.com/OpenGithubs/github-weekly-rank/blob/main/' + year + '/' + month + '/' + fileName + '.md', | ||
| pubDate: parseDate(year + '-' + month + '-' + fileName.slice(6)), | ||
| })); | ||
| }) | ||
| ); | ||
|
|
||
| const items = (await Promise.all(filePromises)).slice(0, 20); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there are more than 20 promises, they will still be resolved, but they will not be returned, which simply wastes time and resources. |
||
|
|
||
| return { | ||
| title: 'OpenGithubs Weekly Rank', | ||
| link: 'https://github.com/OpenGithubs/github-weekly-rank', | ||
| description: 'OpenGithubs 每周开源项目排行榜', | ||
| item: items, | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use namespace
itcinstead.