Files
RSSHub/lib/v2/github/trending.js
Fatpandac 03481653fa 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>
2022-02-03 00:37:01 +08:00

44 lines
1.5 KiB
JavaScript

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(),
};
};