-
Notifications
You must be signed in to change notification settings - Fork 8.9k
feat(trendshift): add trendshift routes #19719
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
Rjnishant530
wants to merge
6
commits into
DIYgod:master
Choose a base branch
from
Rjnishant530:trending
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.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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,7 @@ | ||
| import type { Namespace } from '@/types'; | ||
|
|
||
| export const namespace: Namespace = { | ||
| name: 'TrendShift', | ||
| url: 'trendshift.io', | ||
| lang: 'en', | ||
| }; |
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,93 @@ | ||
| import { Data, Route } from '@/types'; | ||
| import got from '@/utils/got'; | ||
| import { load } from 'cheerio'; | ||
|
||
|
|
||
| export const route: Route = { | ||
| path: '/trending/:language?/:range?', | ||
| categories: ['programming'], | ||
| example: '/trendshift/trending', | ||
| parameters: { | ||
| range: 'Trending range: 1, 7, 30, 360, default all days', | ||
| language: 'Programming language: javascript, typescript, python, etc., or default all languages', | ||
| limit: 'Number of repositories: 25, 50, 100, default 25', | ||
| }, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['trendshift.io/'], | ||
| }, | ||
| ], | ||
| name: 'Trending Repositories', | ||
| maintainers: ['Rjnishant530'], | ||
| handler, | ||
| url: 'trendshift.io/', | ||
| }; | ||
|
|
||
| async function handler(ctx) { | ||
| const range = ctx.req.param('range') || undefined; | ||
| const language = ctx.req.param('language') || undefined; | ||
| const limit = ctx.req.query('limit') || undefined; | ||
|
|
||
| const params = new URLSearchParams(); | ||
| if (range) { | ||
| params.set('trending-range', range); | ||
| } | ||
| if (language) { | ||
| params.set('trending-language', language); | ||
| } | ||
| if (limit) { | ||
| params.set('trending-limit', limit); | ||
| } | ||
| const url = `https://trendshift.io/?${params.toString()}`; | ||
| const { data } = await got(url); | ||
| const $ = load(data); | ||
|
|
||
| const items = $('.bg-white.rounded-lg.border.border-gray-300.px-4.py-3.shadow-sm') | ||
| .toArray() | ||
| .map((item) => { | ||
| const $item = $(item); | ||
| const titleLink = $item.find('a.text-primary').first(); | ||
| const title = titleLink.text().trim(); | ||
| const repoLink = titleLink.attr('href'); | ||
| const description = $item.find('.text-gray-500.text-xs').last().text().trim(); | ||
|
|
||
| // Extract stars and forks from the stats section | ||
|
|
||
| const starsText = $item.find('.lucide.lucide-star').parent().text().trim(); | ||
| const forksText = $item.find('.lucide.lucide-git-fork').parent().text().trim(); | ||
|
|
||
| // Extract language from the language indicator | ||
| const languageDiv = $item.find('.text-gray-500.flex.items-center.text-xs').first(); | ||
| const languageSpan = languageDiv.contents().text().trim(); | ||
|
|
||
| const githubLink = $item.find('a[href*="github.com"]').attr('href'); | ||
|
|
||
| return { | ||
| title: title || 'Repository', | ||
| description: `${description}\n\nStars: ${starsText}\nForks: ${forksText}\nLanguage: ${languageSpan}`, | ||
| link: githubLink || `https://trendshift.io${repoLink}`, | ||
| category: [languageSpan].filter(Boolean), | ||
| }; | ||
| }) | ||
| .filter((item) => item.title !== 'Repository'); | ||
|
|
||
| const rangeText = range ? `${range} days` : 'All Time'; | ||
| const languageText = language ?? 'All Languages'; | ||
|
|
||
| return { | ||
| title: `TrendShift - Trending Repositories (${rangeText}, ${languageText})`, | ||
| link: url, | ||
| item: items, | ||
| description: `Trending GitHub repositories on TrendShift for ${rangeText} in ${languageText}`, | ||
| logo: 'https://trendshift.io/favicon.ico', | ||
| icon: 'https://trendshift.io/favicon.ico', | ||
| language: 'en-us', | ||
| } as Data; | ||
| } | ||
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.