diff --git a/docs/traditional-media.md b/docs/traditional-media.md index ab639f15f..10e929b8a 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1152,6 +1152,18 @@ Type 栏目: +## 華視 + +### 新聞 + + + +| 即時 | 氣象 | 政治 | 國際 | 社會 | 運動 | 生活 | 財經 | 台語 | 地方 | 產業 | 綜合 | 藝文 | 娛樂 | +| ---- | ------- | -------- | ------------- | ------- | ------ | ---- | ----- | --------- | ----- | -- | ------- | ---- | --------- | +| real | weather | politics | international | society | sports | life | money | taiwanese | local | pr | general | arts | entertain | + + + ## 环球网 ### 分类 diff --git a/lib/v2/cts/maintainer.js b/lib/v2/cts/maintainer.js new file mode 100644 index 000000000..5c4aa089d --- /dev/null +++ b/lib/v2/cts/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category': ['miles170'], +}; diff --git a/lib/v2/cts/news.js b/lib/v2/cts/news.js new file mode 100644 index 000000000..e77d0ae89 --- /dev/null +++ b/lib/v2/cts/news.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const asyncPool = require('tiny-async-pool'); + +module.exports = async (ctx) => { + const category = ctx.params.category; + const currentUrl = `https://news.cts.com.tw/${category}/index.html`; + const response = await got(currentUrl); + const $ = cheerio.load(response.data); + const items = []; + for await (const data of asyncPool(5, $('#newslist-top a[title]').slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20), (item) => { + item = $(item); + const link = item.attr('href'); + return ctx.cache.tryGet(link, async () => { + const response = await got(link); + const $ = cheerio.load(response.data); + const author = $('.artical-content p:eq(0)').text().trim(); + $('.artical-content p:eq(0), .artical-content .flexbox').remove(); + + return { + title: item.attr('title'), + author, + description: $('.artical-content').html(), + category: $('meta[property="article:section"]').attr('content'), + pubDate: parseDate($('meta[property="article:published_time"]').attr('content')), + link, + }; + }); + })) { + items.push(data); + } + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + description: $('meta[name="description"]').attr('content'), + item: items, + }; +}; diff --git a/lib/v2/cts/radar.js b/lib/v2/cts/radar.js new file mode 100644 index 000000000..6dc1db927 --- /dev/null +++ b/lib/v2/cts/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'cts.com.tw': { + _name: '華視', + news: [ + { + title: '新聞', + docs: 'https://docs.rsshub.app/traditional-media.html#hua-shi-xin-wen', + source: '/:category/index.html', + target: '/cts/:category', + }, + ], + }, +}; diff --git a/lib/v2/cts/router.js b/lib/v2/cts/router.js new file mode 100644 index 000000000..b9311da83 --- /dev/null +++ b/lib/v2/cts/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category', require('./news')); +};