diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 88971d963..c7f924ea3 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -571,6 +571,18 @@ category 对应的关键词有 +## 台湾中央通讯社 + +### 分类 + + + +| 即時 | 政治 | 國際 | 兩岸 | 產經 | 證券 | 科技 | 生活 | 社會 | 地方 | 文化 | 運動 | 娛樂 | +| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | +| aall | aipl | aopl | acn | aie | asc | ait | ahel | asoc | aloc | acul | aspt | amov | + + + ## 网易新闻专栏 ### 栏目 diff --git a/lib/router.js b/lib/router.js index 5eed4c74b..53165c732 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3257,6 +3257,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index')); // CGTN router.get('/cgtn/top', require('./routes/cgtn/top')); +// 台湾中央通讯社 +router.get('/cna/:id?', require('./routes/cna/index')); + // 华为心声社区 router.get('/huawei/xinsheng/:caty?/:order?/:keyword?', require('./routes/huawei/xinsheng/index')); diff --git a/lib/routes/cna/index.js b/lib/routes/cna/index.js new file mode 100644 index 000000000..52f974371 --- /dev/null +++ b/lib/routes/cna/index.js @@ -0,0 +1,49 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + ctx.params.id = ctx.params.id || 'aall'; + + const rootUrl = `https://www.cna.com.tw/list/${ctx.params.id}.aspx`; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + const list = $('#jsMainList li a div h2') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: item.parents('a').attr('href'), + pubDate: new Date(item.next().text() + ' GMT+8').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); + const topImage = content('.fullPic').html(); + + item.description = (topImage === null ? '' : topImage) + content('.paragraph').eq(0).html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: rootUrl, + item: items, + }; +};