Files
RSSHub/lib/v2/hellogithub/ranking.js
mokevip8 e4c6dabf70 feat(route): 增加HelloGithub的RSS订阅 (#8879)
* 增加HelloGithub的RSS订阅

* refactor: migrate to v2

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
2022-03-04 13:21:50 +08:00

40 lines
1.0 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
let type;
switch (ctx.params.type) {
case 'db':
type = 'db-engines';
break;
case 'webserver':
type = 'netcraft';
break;
default:
type = 'tiobe';
break;
}
const rootUrl = 'https://hellogithub.com/report/' + type;
ctx.state.data = {
title: 'HelloGitHub - ranking',
link: rootUrl,
item: await ctx.cache.tryGet(rootUrl, async () => {
const response = await got({
method: 'get',
url: rootUrl,
});
const $ = cheerio.load(response.data);
const content = $('.content');
const title = $('.header').find('h1');
return [
{
title: title.text(),
link: rootUrl,
description: content.html(),
},
];
}),
};
};