From f5fb3aee8e7546563230043094ced5d9b161311a Mon Sep 17 00:00:00 2001 From: Toby Tso <7851076+tpnonthealps@users.noreply.github.com> Date: Fri, 24 Sep 2021 11:38:12 +0800 Subject: [PATCH] fix(route)(icable): category filters for i-CABLE (#7557) --- docs/traditional-media.md | 11 ++++----- lib/routes/icable/category.js | 43 ++++++++++++++++------------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/docs/traditional-media.md b/docs/traditional-media.md index f08e7d3de..0f5f7508e 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -192,16 +192,15 @@ pageClass: routes - `:category` 栏目参数: - `all`: 全站 - - `local`: 本地(港聞) - - `international`: 國際(兩岸國際) - - `finance`: 財經 - - `china`: 兩岸(有線中國組) + - `local`: 港聞 + - `international`: 兩岸國際 + - `china`: 有線中國組 - `sports`: 體育 - `:option?` 可开启的选项: - - `plain`: 全文输出(纯文字) - - `withphoto`: 全文输出 (含题图) **(不指定 `:option?` 时将预设为此项)** + - `plain`: 全文输出为纯文字 + - `brief`: 输出为 100 字简讯 - 全文输出转换为简体字:`?opencc=t2s` (`opencc` 是 RSSHub 的通用参数,详情请参阅 [「中文简繁体转换」](https://docs.rsshub.app/parameter.html#zhong-wen-jian-fan-ti-zhuan-huan)) diff --git a/lib/routes/icable/category.js b/lib/routes/icable/category.js index a4fe28a77..caa4bbf90 100644 --- a/lib/routes/icable/category.js +++ b/lib/routes/icable/category.js @@ -1,14 +1,13 @@ const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); function desc(item, option) { - if (option === 'brief') { - return `

#${item.group_name} (${item.created_at})
閱讀全文

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

${item.desc}

`; } else if (option === 'plain') { return item.desc; } else { - return '暂不支持此类型,请到 https://github.com/DIYgod/RSSHub/issues 反馈'; + throw Error(`Invalid option ‘${option}’. Please refer to the documention.`); } } @@ -31,37 +30,35 @@ module.exports = async (ctx) => { result = data; feedTitle = 'i-CABLE 即時新聞'; } else if (category === 'local') { - result = data.filter((w) => w.group_id === '4'); - feedTitle = '本地 - i-CABLE 即時新聞'; + result = data.filter((w) => w.group_id === '128'); + 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 即時新聞'; + result = data.filter((w) => w.group_id === '136'); + feedTitle = '兩岸國際 - i-CABLE 即時新聞'; } else if (category === 'china') { - result = data.filter((w) => w.group_id === '7'); - feedTitle = '兩岸 - i-CABLE 即時新聞'; + result = data.filter((w) => w.group_id === '18'); + feedTitle = '有線中國組 - i-CABLE 即時新聞'; } else if (category === 'sports') { - result = data.filter((w) => w.group_id === '8'); + result = data.filter((w) => w.group_id === '321'); feedTitle = '體育 - i-CABLE 即時新聞'; } else { - result = [{ desc: '暂不支持此类型,请到 https://github.com/DIYgod/RSSHub/issues 反馈' }]; + throw Error(`Invalid category ‘${category}’. Please refer to the documention.`); } const items = result.map((item) => ({ - title: item.title, // 文章标题 - author: '有線新聞', // 文章作者 + title: item.title, + author: '有線新聞', + category: item.group_name, description: desc(item, option), - pubDate: `${item.created_at} +0800`, // 文章发布时间 - guid: item.id, // 文章唯一标示, 必须唯一, 可选, 默认为文章链接 - link: `http://cablenews.i-cable.com/ci/news/article/37/${item.id}`, // 指向文章的链接 + pubDate: timezone(new Date(`${item.created_at}`), +8), + guid: item.id, + link: `http://cablenews.i-cable.com/ci/news/article/37/${item.id}`, })); ctx.state.data = { - title: feedTitle, // feedTitle - link: 'http://cablenews.i-cable.com/ci/news/listing', // feedURL - description: '有線新聞 - 走在事實最前線', // feedDesc + title: feedTitle, + link: 'http://cablenews.i-cable.com/ci/news/listing', + description: '有線新聞 - 走在事實最前線', item: items, }; };