feat(route): add Good.news (#11057)

This commit is contained in:
Ethan Shen 2022-10-11 09:12:45 +08:00 committed by GitHub
parent d9af18326f
commit cf1c3025c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 0 deletions

View File

@ -524,6 +524,12 @@ Country
<Route author="nczitzk" example="/disinformationindex/blog" path="/disinformationindex/blog"/>
## Good.news
### 今日要闻
<Route author="nczitzk" example="/good" path="/good" />
## GQ
### GQ 台湾

52
lib/v2/good/index.js Normal file
View File

@ -0,0 +1,52 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://good.news';
const response = await got({
method: 'get',
url: rootUrl,
});
const $ = cheerio.load(response.data);
let items = $('.content-structure')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 50)
.toArray()
.map((item) => {
item = $(item);
const a = item.find('h4 a');
return {
title: a.text(),
link: a.attr('href'),
pubDate: parseDate(item.find('.content-left').text()),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('div[contentscore]').html();
return item;
})
)
);
ctx.state.data = {
title: 'good.news - 今日要闻',
link: rootUrl,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/': ['nczitzk'],
};

13
lib/v2/good/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'good.news': {
_name: 'Good.news',
'.': [
{
title: '今日要闻',
docs: 'https://docs.rsshub.app/new-media.html#good-news-jin-ri-yao-wen',
source: ['/'],
target: '/good',
},
],
},
};

3
lib/v2/good/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/', require('./index'));
};