fix(route): 新华社新闻 (#8559)

This commit is contained in:
Ethan Shen 2021-11-27 17:09:04 +08:00 committed by GitHub
parent ceaff4c420
commit 884520931c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 11 deletions

View File

@ -3958,7 +3958,7 @@ router.get('/tianyancha/hot', lazyloadRouteHandler('./routes/tianyancha/hot'));
router.get('/kingarthur/:type', lazyloadRouteHandler('./routes/kingarthur/index'));
// 新华网
router.get('/news/whxw', lazyloadRouteHandler('./routes/news/whxw'));
// router.get('/news/whxw', lazyloadRouteHandler('./routes/news/whxw'));
// 游讯网
router.get('/yxdown/recommend', lazyloadRouteHandler('./routes/yxdown/recommend'));

View File

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

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

@ -0,0 +1,13 @@
module.exports = {
'news.cn': {
_name: '新华网',
'.': [
{
title: '新华社新闻',
docs: 'https://docs.rsshub.app/new-media.html#xin-hua-wang-xin-hua-she-xin-wen',
source: ['/'],
target: '/news/whxw',
},
],
},
};

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

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

View File

@ -13,39 +13,47 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
const list = $('h3 a')
.slice(0, 35)
.map((_, item) => {
let items = $('h3 a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
let detailResponse;
try {
detailResponse = await got(item.link);
} catch (error) {
item.status = 404;
}
if (item.status !== 404) {
const content = cheerio.load(detailResponse.data);
const date = content('.header-time.left').text();
const author =
content('.editor').text() ||
content('.editor').text() ??
content('.p-jc')
.text()
.replace(/[\r\n]/g, '');
item.author = author.match(/责任编辑.(.*)/)[1].trim();
.replace(/[\r\n]/g, '')
.replace(' ', ':')
.trim();
item.author = author.split(':').pop().replace('】', '');
content('#articleEdit').remove();
item.description = content('#detail').html();
item.pubDate = timezone(parseDate(date, 'YYYYMM/DD HH:mm:ss'), +8);
}
delete item.status;
return item;
})
)