fix(route): github trending (#12320)

This commit is contained in:
Tony
2023-04-15 10:29:22 -05:00
committed by GitHub
parent 6dbd99b386
commit 642ac174e9
2 changed files with 9 additions and 11 deletions

View File

@@ -11,7 +11,7 @@ module.exports = {
'/starred_repos/:user': ['LanceZhu'],
'/stars/:user/:repo': ['HenryQW'],
'/topics/:name/:qs?': ['queensferryme'],
'/trending/:since/:language?/:spoken_language?': ['DIYgod', 'jameschensmith'],
'/trending/:since/:language/:spoken_language?': ['DIYgod', 'jameschensmith'],
'/user/followers/:user': ['HenryQW'],
'/wiki/:user/:repo/:page?': ['TonyRL'],
};

View File

@@ -6,7 +6,7 @@ const path = require('path');
module.exports = async (ctx) => {
if (!config.github || !config.github.access_token) {
throw 'GitHub trending RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>';
throw Error('GitHub trending RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
}
const since = ctx.params.since;
const language = ctx.params.language === 'any' ? '' : ctx.params.language;
@@ -23,15 +23,13 @@ module.exports = async (ctx) => {
const $ = cheerio.load(trendingPage);
const articles = $('article');
const trendingRepos = articles
.map((_, item) => {
const [owner, name] = $(item).find('h1').text().split('/');
const trendingRepos = articles.toArray().map((item) => {
const [owner, name] = $(item).find('h2').text().split('/');
return {
name: name.trim(),
owner: owner.trim(),
};
})
.get();
});
const { data: repoData } = await got({
method: 'post',