diff --git a/docs/en/new-media.md b/docs/en/new-media.md index bce314739..c2b1fc6a8 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -47,6 +47,12 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more +## CGTN + +### Most Read & Most Share + + + ## Engadget ### Chinese diff --git a/docs/new-media.md b/docs/new-media.md index 57dd59424..40c029561 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -102,6 +102,12 @@ pageClass: routes +## CGTN + +### Most Read & Most Share + + + ## cnBeta ### 最新 diff --git a/lib/router.js b/lib/router.js index e68414ed7..84fbb9f7a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3213,6 +3213,9 @@ router.get('/feixuew/:id?', require('./routes/feixuew/index')); // 1X router.get('/1x/:type?/:caty?', require('./routes/1x/index')); +// CGTN +router.get('/cgtn/most/:type?/:time?', require('./routes/cgtn/most')); + // AppSales router.get('/appsales/:caty?/:time?', require('./routes/appsales/index')); diff --git a/lib/routes/cgtn/most.js b/lib/routes/cgtn/most.js new file mode 100644 index 000000000..f2b3828d6 --- /dev/null +++ b/lib/routes/cgtn/most.js @@ -0,0 +1,49 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + ctx.params.type = ctx.params.type || 'read'; + ctx.params.time = ctx.params.time || 'all'; + + const rootUrl = `https://www.cgtn.com/most-${ctx.params.type}`; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + const list = $(`#${ctx.params.time}Items div.most-read-item-box div.cg-title`) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.text(), + link: a.attr('href'), + pubDate: new Date(parseInt(a.attr('data-time'))).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('#cmsMainContent').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `CGTN - Most ${ctx.params.type}`, + link: rootUrl, + item: items, + }; +};