diff --git a/docs/en/new-media.md b/docs/en/new-media.md index d0b372cc8b..4ef729a37d 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -79,6 +79,10 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more +### Editors' Pick + + + ## China Labour Bulletin ### Commentary and Analysis diff --git a/docs/new-media.md b/docs/new-media.md index 2152676b55..5e624f41ae 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -134,6 +134,10 @@ pageClass: routes +### Editors' Pick + + + ## cnBeta ### 最新 diff --git a/lib/router.js b/lib/router.js index b1c725a657..622506a924 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3343,8 +3343,12 @@ router.get('/fulinian/:caty?', require('./routes/fulinian/index')); // CGTN router.get('/cgtn/most/:type?/:time?', require('./routes/cgtn/most')); + +router.get('/cgtn/pick', require('./routes/cgtn/pick')); + router.get('/cgtn/opinions', require('./routes/cgtn/opinions')); + // AppSales router.get('/appsales/:caty?/:time?', require('./routes/appsales/index')); diff --git a/lib/routes/cgtn/pick.js b/lib/routes/cgtn/pick.js new file mode 100644 index 0000000000..ea4dce2376 --- /dev/null +++ b/lib/routes/cgtn/pick.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.cgtn.com/'; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + const list = $('.titleArea') + .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 - Editors' Pick", + link: rootUrl, + item: items, + }; +};