diff --git a/lib/router.js b/lib/router.js index a5230e1d8..458ec48bc 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/v2/news/maintainer.js b/lib/v2/news/maintainer.js new file mode 100644 index 000000000..4aa7f5af7 --- /dev/null +++ b/lib/v2/news/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/whxw': ['nczitzk'], +}; diff --git a/lib/v2/news/radar.js b/lib/v2/news/radar.js new file mode 100644 index 000000000..42ccaaa1d --- /dev/null +++ b/lib/v2/news/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/news/router.js b/lib/v2/news/router.js new file mode 100644 index 000000000..00ce0528e --- /dev/null +++ b/lib/v2/news/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/whxw', require('./whxw')); +}; diff --git a/lib/routes/news/whxw.js b/lib/v2/news/whxw.js similarity index 77% rename from lib/routes/news/whxw.js rename to lib/v2/news/whxw.js index 30532efa9..ad5641562 100644 --- a/lib/routes/news/whxw.js +++ b/lib/v2/news/whxw.js @@ -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; }) )