diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 5955668956..acd2283f28 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -716,6 +716,10 @@ category 对应的关键词有 +### 中国共产党新闻网 24 小时滚动新闻 + + + ## 人民日报社 国际金融报 ### 栏目 diff --git a/lib/router.js b/lib/router.js index bba91dd169..acc1379c36 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/people/cpc/24h.js b/lib/routes/people/cpc/24h.js new file mode 100644 index 0000000000..7053c83dc3 --- /dev/null +++ b/lib/routes/people/cpc/24h.js @@ -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, + }; +};