feat: add i-CABLE instant news (#6242)

This commit is contained in:
Toby Tso
2020-11-29 19:16:42 +00:00
committed by GitHub
parent c3cfd17962
commit 83ea0a8b6a
3 changed files with 94 additions and 0 deletions
+24
View File
@@ -131,6 +131,30 @@ pageClass: routes
</Route>
## i-CABLE 有線新聞
<Route author="tpnonthealps" example="/icable/all" path="/icable/:category/:option?" :paramsDesc="['栏目', '选项(不指定时预设为「全文输出 (含题图)」的 `withphoto` )']">
细则:
- `: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))
</Route>
## NHK
### News Web Easy
+3
View File
@@ -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'));
+67
View File
@@ -0,0 +1,67 @@
const got = require('@/utils/got');
function desc(item, option) {
if (option === 'brief') {
return `<p>#${item.group_name} (${item.created_at})<br><a href="https://ott-news.i-cable.com/zh-hk/l/open-content?cid=${item.id}&ct=1">在 app 打開</a>|<a href="http://cablenews.i-cable.com/ci/videopage/news/${item.id}">閱讀全文</a></p>`;
} else 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 反馈';
}
}
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,
};
};