mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 12:21:31 +08:00
fix(route): fix GitHub route parameter conflict at trending.js and refactor to V2 (#8923)
* Fix(route): fix route parameter conflict at trending.js and change to V2 * Fix(route): modify the judgment condition of language parameter * Fix(docs): Update docs/programming.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Fix(docs): Update docs/en/programming.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix(docs/route): add author and sort routes * Fix(route): Update docs/en/programming.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Fix(route): sort routes Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
43
lib/v2/github/trending.js
Normal file
43
lib/v2/github/trending.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const since = ctx.params.since;
|
||||
const language = ctx.params.language === 'any' ? '' : ctx.params.language;
|
||||
const spoken_language = ctx.params.spoken_language ?? '';
|
||||
const url = `https://github.com/trending/${encodeURIComponent(language)}?since=${since}&spoken_language_code=${spoken_language}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
headers: {
|
||||
Referer: url,
|
||||
},
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('article');
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: url,
|
||||
item:
|
||||
list &&
|
||||
list
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('h1').text(),
|
||||
author: item.find('h1').text().split('/')[0].trim(),
|
||||
description: `${item.find('.pr-4').text()}<br>
|
||||
<br>Language: ${item.find('span[itemprop="programmingLanguage"]').text() ?? 'unknown'}
|
||||
<br>Star: ${item.find('.Link--muted').eq(0).text().trim()}
|
||||
<br>Fork: ${item.find('.Link--muted').eq(1).text().trim()}`,
|
||||
link: `https://github.com${item.find('h1 a').attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user