Skip to content

Commit 1c75a3a

Browse files
committed
Add support for more category
1 parent 1941de1 commit 1c75a3a

File tree

2 files changed

+74
-50
lines changed

2 files changed

+74
-50
lines changed

docs/traditional-media.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,13 +1100,61 @@ category 对应的关键词有
11001100

11011101
香港经济日报已有提供简单 RSS,详细可前往官方网站: <https://www.hket.com/rss>
11021102

1103-
此路由主要补全官方 RSS 全文输出
1103+
此路由主要补全官方 RSS 全文输出及完善分类输出
11041104

1105-
<Route author="TonyRL" example="/hket/sran001" path="/hket/:category?" :paramsDesc="['分类,默认为全部新闻']">
1105+
<Route author="TonyRL" example="/hket/sran001" path="/hket/:category?" :paramsDesc="['分类,默认为全部新闻,可在 URL 中找到,部分见下表']" radar="1" rssbud="1">
11061106

1107-
| sran001 | sran008 | sran010 | sran011 | srac002 | srat006 |
1107+
| sran001 | sran008 | sran010 | sran011 | sran012 | srat006 |
11081108
| -------- | -------- | -------- | -------- | -------- | -------- |
1109-
| 全部新闻 | 财经地产 | 科技信息 | 国际新闻 | 两岸新闻 | 香港新闻 |
1109+
| 全部新闻 | 财经地产 | 科技信息 | 国际新闻 | 商业新闻 | 香港新闻 |
1110+
1111+
| sran009 | sran009-1 | sran009-2 | sran009-3 | sran009-4 | sran009-5 | sran009-6 |
1112+
| -------- | --------- | --------- | ---------- | --------- | --------- | --------- |
1113+
| 即时财经 | 股市 | 新股 IPO | 新经济追踪 | 当炒股 | 宏观解读 | Hot Talk |
1114+
1115+
| sran011-1 | sran011-2 | sran011-3 |
1116+
| --------- | ------------ | ------------ |
1117+
| 环球政治 | 环球经济金融 | 环球社会热点 |
1118+
1119+
| sran016 | sran016-1 | sran016-2 | sran016-3 | sran016-4 | sran016-5 |
1120+
| ---------- | ---------- | ---------- | ---------- | ---------- | -------------- |
1121+
| 大湾区主页 | 大湾区发展 | 大湾区工作 | 大湾区买楼 | 大湾区消费 | 大湾区投资理财 |
1122+
1123+
| srac002 | srac003 | srac004 | srac005 |
1124+
| -------- | -------- | -------- | -------- |
1125+
| 即时中国 | 经济脉搏 | 国情动向 | 社会热点 |
1126+
1127+
| srat001 | srat008 | srat055 | srat069 | srat070 |
1128+
| ------- | ------- | -------- | -------- | --------- |
1129+
| 话题 | 观点 | 休闲消费 | 娱乐新闻 | TOPick TV |
1130+
1131+
| srat052 | srat052-1 | srat052-2 | srat052-3 |
1132+
| -------- | --------- | ---------- | --------- |
1133+
| 健康主页 | 食用安全 | 医生诊症室 | 保健美颜 |
1134+
1135+
| srat053 | srat053-1 | srat053-2 | srat053-3 | srat053-4 |
1136+
| -------- | --------- | --------- | --------- | ---------- |
1137+
| 亲子主页 | 儿童健康 | 育儿经 | 教育 | 亲子好去处 |
1138+
1139+
| srat053-6 | srat053-61 | srat053-62 | srat053-63 | srat053-64 |
1140+
| ----------- | ---------- | ---------- | ---------- | ---------- |
1141+
| Band 1 学堂 | 幼稚园 | 中小学 | 尖子教室 | 海外升学 |
1142+
1143+
| srat072-1 | srat072-2 | srat072-3 | srat072-4 |
1144+
| ---------- | ---------- | ---------------- | ----------------- |
1145+
| 健康身心活 | 抗癌新方向 | 「糖」「心」解密 | 风湿不再 你我自在 |
1146+
1147+
| sraw007 | sraw009 | sraw010 | sraw011 | sraw012 | sraw014 | sraw018 | sraw019 |
1148+
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
1149+
| 全部博客 | Bloggers | 收息攻略 | 精明消费 | 退休规划 | 个人增值 | 财富管理 | 绿色金融 |
1150+
1151+
| sraw015 | sraw015-07 | sraw015-08 | sraw015-09 | sraw015-10 |
1152+
| -------- | ---------- | ---------- | ---------- | ---------- |
1153+
| 移民百科 | 海外置业 | 移民攻略 | 移民点滴 | 海外理财 |
1154+
1155+
| sraw020 | sraw020-1 | sraw020-2 | sraw020-3 | sraw020-4 |
1156+
| -------- | ------------ | --------- | --------- | --------- |
1157+
| ESG 主页 | ESG 趋势政策 | ESG 投资 | ESG 企业 | ESG 社会 |
11101158

11111159
</Route>
11121160

lib/v2/hket/index.js

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,30 @@ const timezone = require('@/utils/timezone');
55
const path = require('path');
66
const { art } = require('@/utils/render');
77

8-
const categories = {
9-
sran001: {
10-
baseUrl: `https://inews.hket.com`,
11-
link: `https://inews.hket.com/sran001/全部`,
12-
title: '全部',
8+
const urlMap = {
9+
srac: {
10+
baseUrl: 'https://china.hket.com',
1311
},
14-
sran008: {
15-
baseUrl: `https://inews.hket.com`,
16-
description: '財經新聞, 地產資訊',
17-
link: `https://inews.hket.com/sran008/財金`,
18-
title: '財經地產',
12+
sran: {
13+
baseUrl: 'https://inews.hket.com',
1914
},
20-
sran010: {
21-
baseUrl: `https://inews.hket.com`,
22-
description: '科技資訊',
23-
link: `https://inews.hket.com/sran010/科技`,
24-
title: '科技',
15+
srat: {
16+
baseUrl: 'https://topick.hket.com',
2517
},
26-
sran011: {
27-
baseUrl: `https://inews.hket.com`,
28-
description: '國際形勢',
29-
link: `https://inews.hket.com/sran011/國際`,
30-
title: '國際',
31-
},
32-
srac002: {
33-
baseUrl: `https://china.hket.com`,
34-
description: '中國及台灣新聞',
35-
link: `https://china.hket.com/srac002/即時中國`,
36-
title: '兩岸',
37-
},
38-
srat006: {
39-
baseUrl: `https:///topick.hket.com`,
40-
description: '香港新聞, 時事',
41-
link: `https://topick.hket.com/srat006/新聞`,
42-
title: '香港',
18+
sraw: {
19+
baseUrl: 'https://wealth.hket.com',
4320
},
4421
};
4522

4623
module.exports = async (ctx) => {
4724
const category = ctx.params.category ?? 'sran001';
48-
const cat = categories[category];
25+
const baseUrl = urlMap[category.substring(0, 4)].baseUrl;
4926

5027
const response = await got({
5128
method: 'get',
52-
url: cat.link,
29+
url: baseUrl + '/' + category,
5330
header: {
54-
Referer: `https://www.hket.com/`,
31+
Referer: 'https://www.hket.com',
5532
},
5633
});
5734

@@ -64,7 +41,7 @@ module.exports = async (ctx) => {
6441
title: item.text().trim(),
6542
link: item.attr('href').startsWith('/')
6643
? // remove tracking parameters
67-
cat.baseUrl + item.attr('href').split('?')[0].substring(0, item.attr('href').lastIndexOf('/'))
44+
baseUrl + item.attr('href').split('?')[0].substring(0, item.attr('href').lastIndexOf('/'))
6845
: item.attr('href').split('?')[0].substring(0, item.attr('href').lastIndexOf('/')),
6946
};
7047
})
@@ -78,23 +55,22 @@ module.exports = async (ctx) => {
7855
method: 'get',
7956
url: item.link,
8057
header: {
81-
Referer: cat.link,
58+
Referer: baseUrl + '/' + category,
8259
},
8360
});
8461
const content = cheerio.load(article.data);
85-
const categories = [];
8662

8763
// extract categories
88-
content('.contentTags-container > .hotkey-container-wrapper > .hotkey-container > a').each((_, e) => {
89-
categories.push(content(e).text().trim());
90-
});
64+
const categories = content('.contentTags-container > .hotkey-container-wrapper > .hotkey-container > a')
65+
.toArray()
66+
.map((e) => content(e).text().trim());
9167

9268
// remove unwanted elements
93-
content('#ad_MobileInArticle, #ad_MobileMain, #Native01, #Native02, #Native03').remove();
69+
content('p.adunit').remove();
9470
content('div.template-default.hket-row.detail-widget.show-xs-img.relatedContents-container').remove();
9571
content('div.template-default.hket-row.no-padding.detail-widget').remove();
96-
content('div.contentTags-container').remove();
9772
content('div.gallery-related-container').remove();
73+
content('div.contentTags-container').remove();
9874
content('div.article-details-center-sharing-btn').remove();
9975
content('source').remove();
10076
content('span').each((_, e) => {
@@ -127,9 +103,9 @@ module.exports = async (ctx) => {
127103
);
128104

129105
ctx.state.data = {
130-
title: `${cat.title}新聞RSS - 香港經濟日報 hket.com`,
131-
link: cat.link,
132-
description: `訂閱${cat.title}新聞RSS,獲取最新${cat.description} - RSS - 香港經濟日報 hket.com`,
106+
title: String($('head meta[name=title]').attr('content').trim()),
107+
link: baseUrl + '/' + category,
108+
description: String($('head meta[name=description]').attr('content').trim()),
133109
item: items,
134110
language: 'zh-hk',
135111
};

0 commit comments

Comments
 (0)