fix(route)(icable): category filters for i-CABLE (#7557)

This commit is contained in:
Toby Tso 2021-09-24 11:38:12 +08:00 committed by GitHub
parent d8aa7357e5
commit f5fb3aee8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 29 deletions

View File

@ -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))

View File

@ -1,14 +1,13 @@
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
function desc(item, option) {
if (option === 'brief') {
return `<p>#${item.group_name} (${item.created_at})<br><a href="http://cablenews.i-cable.com/ci/news/article/37/${item.id}">閱讀全文</a></p>`;
} else if (option === 'withphoto') {
if (option === 'withphoto') {
return `<img src="${item.pic_url}"><p>${item.desc}</p>`;
} else if (option === 'plain') {
return item.desc;
} else {
return '暂不支持此类型,请到 https://github.com/DIYgod/RSSHub/issues 反馈';
throw Error(`Invalid option <code>${option}</code>. Please refer to <a href="https://docs.rsshub.app/traditional-media.html#i-cable-you-xian-xin-wen">the documention</a>.`);
}
}
@ -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 <code>${category}</code>. Please refer to <a href="https://docs.rsshub.app/traditional-media.html#i-cable-you-xian-xin-wen">the documention</a>.`);
}
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,
};
};