feat: add 央视网图片《镜象》 (#6826)

This commit is contained in:
Ethan Shen
2021-02-04 10:39:14 +08:00
committed by GitHub
parent 3fc8ff105c
commit 6f339909ec
3 changed files with 53 additions and 0 deletions

View File

@@ -903,6 +903,10 @@ category 对应的关键词有
<Route author="xfangbao" example="/xwlb" path="/xwlb/index" />
### 央视网图片《镜象》
<Route author="nczitzk" example="/cctv/photo/jx" path="/cctv/photo/jx" />
## 朝日新聞中文網(繁體中文版)
### 新聞分類

View File

@@ -382,8 +382,10 @@ router.get('/mihoyo/bh2/:type', require('./routes/mihoyo/bh2'));
// 新闻联播
router.get('/cctv/xwlb', require('./routes/cctv/xwlb'));
// 央视新闻
router.get('/cctv/:category', require('./routes/cctv/category'));
router.get('/cctv/photo/jx', require('./routes/cctv/jx'));
router.get('/cctv-special/:id?', require('./routes/cctv/special'));
// 财新博客

47
lib/routes/cctv/jx.js Normal file
View File

@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://photo.cctv.com';
const currentUrl = `${rootUrl}/jx/`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.textr a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.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('.tujitop').html();
return item;
})
)
);
ctx.state.data = {
title: '央视网图片《镜象》',
link: currentUrl,
item: items,
};
};