@@ -5,53 +5,30 @@ const timezone = require('@/utils/timezone');
55const path = require ( 'path' ) ;
66const { 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
4623module . 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