-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Open
Nemocccc
wants to merge
6
commits into
DIYgod:master
Choose a base branch
from
Nemocccc:master
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.
+362
−650
Open
feat(route): add opengithub-weekly-rank route, display the journal of opengithub on github trending #21084
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fec3394
add opengithub-weekly-rank route, display the journal of opengithub o…
Nemocccc cb066da
chore: trigger deployment
Nemocccc b36877b
Merge branch 'DIYgod:master' into master
Nemocccc b77f0c0
Merge branch 'DIYgod:master' into master
Nemocccc 6161d73
add opengithub-weekly-rank route, display the journal of opengithub o…
Nemocccc 4c81e51
add opengithub-weekly-rank route, display the journal of opengithub o…
Nemocccc 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
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,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每周趋势', | ||
| }, | ||
| }; |
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,101 @@ | ||
| import MarkdownIt from 'markdown-it'; | ||
|
|
||
| import { config } from '@/config'; | ||
| import type { Route } from '@/types'; | ||
| import got from '@/utils/got'; | ||
| import { parseDate } from '@/utils/parse-date'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/weekly-rank', | ||
| categories: ['programming'], | ||
| example: '/opengithub-trending/weekly-rank', | ||
| 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-rank', | ||
| }, | ||
| ], | ||
| name: 'Weekly Rank', | ||
| maintainers: ['Nemocccc'], | ||
| description: '追踪 OpenGithubs 每周发布的开源项目排行榜', | ||
| handler, | ||
| }; | ||
|
|
||
| async function handler() { | ||
| const repoUrl = 'https://api.github.com/repos/OpenGithubs/github-weekly-rank/contents'; | ||
| const headers: Record<string, string> = {}; | ||
|
|
||
| if (config.github?.accessToken) { | ||
| headers.Authorization = `token ${config.github.accessToken}`; | ||
| } | ||
|
|
||
| const yearResponse = await got(repoUrl, { headers }); | ||
| const years = yearResponse.data | ||
| .filter((item: any) => item.type === 'dir' && /^\d{4}$/.test(item.name)) | ||
| .toSorted((a: any, b: any) => b.name.localeCompare(a.name)) | ||
| .slice(0, 2); | ||
|
|
||
| const getMonthData = async (yearItem: any) => { | ||
| const monthResponse = await got(`${repoUrl}/${yearItem.name}`, { headers }); | ||
| return { | ||
| year: yearItem.name, | ||
| months: monthResponse.data | ||
| .filter((item: any) => item.type === 'dir') | ||
| .toSorted((a: any, b: any) => b.name.localeCompare(a.name)) | ||
| .slice(0, 3), | ||
| }; | ||
| }; | ||
|
|
||
| const monthData = await Promise.all(years.map((year) => getMonthData(year))); | ||
|
|
||
| const getDayData = async (year: string, monthItem: any) => { | ||
| const dayResponse = await got(`${repoUrl}/${year}/${monthItem.name}`, { headers }); | ||
| return { | ||
| year, | ||
| month: monthItem.name, | ||
| days: dayResponse.data | ||
| .filter((item: any) => item.type === 'file' && item.name.endsWith('.md')) | ||
| .toSorted((a: any, b: any) => b.name.localeCompare(a.name)) | ||
| .slice(0, 5), | ||
| }; | ||
| }; | ||
|
|
||
| const dayPromises = monthData.flatMap(({ year, months }: any) => months.map((monthItem: any) => getDayData(year, monthItem))); | ||
|
|
||
| const allDayData = await Promise.all(dayPromises); | ||
|
|
||
| const md = new MarkdownIt(); | ||
|
|
||
| const getFileItem = async (year: string, month: string, dayItem: any) => { | ||
| const fileName = dayItem.name.replace('.md', ''); | ||
| const fileUrl = `https://raw.githubusercontent.com/OpenGithubs/github-weekly-rank/main/${year}/${month}/${dayItem.name}`; | ||
| const fileContent = await got(fileUrl); | ||
|
|
||
| return { | ||
| title: `GitHub Weekly Rank - ${fileName}`, | ||
| description: md.render(fileContent.data), | ||
| link: `https://github.com/OpenGithubs/github-weekly-rank/blob/main/${year}/${month}/${fileName}.md`, | ||
| pubDate: parseDate(`${year}-${month}-${fileName.slice(6)}`), | ||
| }; | ||
| }; | ||
|
|
||
| const filePromises = allDayData.flatMap(({ year, month, days }: any) => days.map((dayItem: any) => getFileItem(year, month, dayItem))).slice(0, 20); | ||
|
|
||
| const items = await Promise.all(filePromises); | ||
|
|
||
| return { | ||
| title: 'OpenGithubs Weekly Rank', | ||
| link: 'https://github.com/OpenGithubs/github-weekly-rank', | ||
| description: 'OpenGithubs 每周开源项目排行榜', | ||
| item: items, | ||
| }; | ||
| } |
Oops, something went wrong.
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.
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.