feat(route): add 中国共产党新闻网 24 小时滚动新闻 (#6931)

* feat: add 中国共产党新闻网 24 小时滚动新闻

* fix typo

* fix typo

* fix router.js

* fix router.js
This commit is contained in:
Ethan Shen
2021-03-14 01:10:06 -05:00
committed by GitHub
parent 45accb0286
commit 2c8aa2dec7
3 changed files with 58 additions and 0 deletions
+4
View File
@@ -716,6 +716,10 @@ category 对应的关键词有
<Route author="LogicJake" example="/people/xjpjh" path="/people/xjpjh/:keyword?/:year?" :paramsDesc="['关键词,默认不填','年份,默认 all']"/>
### 中国共产党新闻网 24 小时滚动新闻
<Route author="nczitzk" example="/people/cpc/24h" path="/people/cpc/24h"/>
## 人民日报社 国际金融报
### 栏目
+1
View File
@@ -1557,6 +1557,7 @@ router.get('/banyuetan/:name', require('./routes/banyuetan'));
router.get('/people/opinion/:id', require('./routes/people/opinion'));
router.get('/people/env/:id', require('./routes/people/env'));
router.get('/people/xjpjh/:keyword?/:year?', require('./routes/people/xjpjh'));
router.get('/people/cpc/24h', require('./routes/people/cpc/24h'));
// 北极星电力网
router.get('/bjx/huanbao', require('./routes/bjx/huanbao'));
+53
View File
@@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
module.exports = async (ctx) => {
const rootUrl = 'http://cpc.people.com.cn';
const currentUrl = `${rootUrl}/GB/87228/index.html`;
const response = await got({
method: 'get',
url: currentUrl,
responseType: 'buffer',
});
const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
const list = $('.fl ul li a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const link = item.attr('href');
return {
title: item.text(),
link: `${link.indexOf('http') < 0 ? rootUrl : ''}${link}`,
};
})
.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,
responseType: 'buffer',
});
const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk'));
item.description = content('.show_text').html();
item.pubDate = new Date(content('meta[name="publishdate"]').attr('content')).toUTCString();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};