Merge pull request #6587 from nczitzk/feature/cgtn

feat: add cgtn editors'pick
This commit is contained in:
NeverBehave
2021-01-10 19:38:56 -05:00
committed by GitHub
4 changed files with 58 additions and 0 deletions
+4
View File
@@ -79,6 +79,10 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
<RouteEn author="nczitzk" example="/cgtn/top" path="/cgtn/top"/>
### Editors' Pick
<RouteEn author="nczitzk" example="/cgtn/pick" path="/cgtn/pick"/>
## China Labour Bulletin
### Commentary and Analysis
+4
View File
@@ -134,6 +134,10 @@ pageClass: routes
<Route author="nczitzk" example="/cgtn/top" path="/cgtn/top"/>
### Editors' Pick
<Route author="nczitzk" example="/cgtn/pick" path="/cgtn/pick"/>
## cnBeta
### 最新
+4
View File
@@ -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'));
+46
View File
@@ -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,
};
};