From 83ea0a8b6acb8c5fa89f557f8587fda41e571995 Mon Sep 17 00:00:00 2001 From: Toby Tso <7851076+tpnonthealps@users.noreply.github.com> Date: Mon, 30 Nov 2020 03:16:42 +0800 Subject: [PATCH] feat: add i-CABLE instant news (#6242) --- docs/traditional-media.md | 24 +++++++++++++ lib/router.js | 3 ++ lib/routes/icable/category.js | 67 +++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 lib/routes/icable/category.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 524e733a9a..6647de8a78 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -131,6 +131,30 @@ pageClass: routes +## i-CABLE 有線新聞 + + + +细则: + +- `:category` 栏目参数: + + - `all`: 全站 + - `local`: 本地(港聞) + - `international`: 國際(兩岸國際) + - `finance`: 財經 + - `china`: 兩岸(有線中國組) + - `sports`: 體育 + +- `:option?` 可开启的选项: + + - `plain`: 全文输出(纯文字) + - `withphoto`: 全文输出 (含题图) **(不指定 `:option?` 时将预设为此项)** + +- 全文输出转换为简体字: `?opencc=t2s` + (`opencc` 是 RSSHub 的通用参数,详情请参阅[「中文简繁体转换」](https://docs.rsshub.app/parameter.html#zhong-wen-jian-fan-ti-zhuan-huan)) + + ## NHK ### News Web Easy diff --git a/lib/router.js b/lib/router.js index 19198abebc..0af2655671 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3512,6 +3512,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news')); router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt')); router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic')); +// i-Cable +router.get('/icable/:category/:option?', require('./routes/icable/category')); + // ProcessOn router.get('/processon/popular/:cate?/:sort?', require('./routes/processon/popular')); diff --git a/lib/routes/icable/category.js b/lib/routes/icable/category.js new file mode 100644 index 0000000000..8722c9057a --- /dev/null +++ b/lib/routes/icable/category.js @@ -0,0 +1,67 @@ +const got = require('@/utils/got'); + +function desc(item, option) { + if (option === 'brief') { + return `

#${item.group_name} (${item.created_at})
在 app 打開|閱讀全文

`; + } else if (option === 'withphoto') { + return `

${item.desc}

`; + } else if (option === 'plain') { + return item.desc; + } else { + return '暂不支持此类型,请到 https://github.com/DIYgod/RSSHub/issues 反馈'; + } +} + +module.exports = async (ctx) => { + const category = ctx.params.category; + const option = ctx.params.option || 'withphoto'; + + const response = await got({ + method: 'get', + url: `http://cablenews.i-cable.com/ci/news/listing/api`, + headers: { + Referer: `http://cablenews.i-cable.com/ci/news/listing`, + }, + }); + + const data = response.data; + let result; + let feedTitle; + if (category === 'all') { + result = data; + feedTitle = 'i-CABLE 即時新聞'; + } else if (category === 'local') { + result = data.filter((w) => w.group_id === '4'); + feedTitle = '本地 - i-CABLE 即時新聞'; + } else if (category === 'international') { + result = data.filter((w) => w.group_id === '5'); + feedTitle = '國際 - i-CABLE 即時新聞'; + } else if (category === 'finance') { + result = data.filter((w) => w.group_id === '6'); + feedTitle = '財經 - i-CABLE 即時新聞'; + } else if (category === 'china') { + result = data.filter((w) => w.group_id === '7'); + feedTitle = '兩岸 - i-CABLE 即時新聞'; + } else if (category === 'sports') { + result = data.filter((w) => w.group_id === '8'); + feedTitle = '體育 - i-CABLE 即時新聞'; + } else { + result = [{ desc: '暂不支持此类型,请到 https://github.com/DIYgod/RSSHub/issues 反馈' }]; + } + + const items = result.map((item) => ({ + title: item.title, // 文章标题 + author: '有線新聞', // 文章作者 + description: desc(item, option), + pubDate: `${item.created_at} +0800`, // 文章发布时间 + guid: item.id, // 文章唯一标示, 必须唯一, 可选, 默认为文章链接 + link: `http://cablenews.i-cable.com/ci/videopage/news/${item.id}`, // 指向文章的链接 + })); + + ctx.state.data = { + title: feedTitle, // feedTitle + link: 'http://cablenews.i-cable.com/ci/news/listing', // feedURL + description: '有線新聞 - 走在事實最前線', // feedDesc + item: items, + }; +};