diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index 02891c97a..e699841e2 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -44,6 +44,22 @@ Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/1062 +## RTHK + +### News + +RTHK offical provides full text RSS, check the offical website for detail information: + +This route adds the missing photo and Link element. (Offical RSS doesn't have Link element may cause issue on some RSS client) + + + +| local | greaterchina | international | finance | sport | +| ---------- | ------------------ | ------------- | ------------ | ---------- | +| Local News | Greater China News | World News | Finance News | Sport News | + + + ## The Economist ### Category diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 58c51cb69..b086f6818 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -360,6 +360,22 @@ category 对应的关键词有 +## 香港電台 + +### 新聞 + +香港電台官方已有提供全文 RSS,詳細可前往官方網站: + +此路由主要補回官方 RSS 缺少的圖片以及 Link 元素。(官方 RSS 沒有 Link 元素可能導致某些 RSS 客戶端出現問題) + + + +| local | greaterchina | international | finance | sport | +| -------- | ------------ | ------------- | -------- | -------- | +| 本地新聞 | 大中華新聞 | 國際新聞 | 財經新聞 | 體育新聞 | + + + ## 新京报 ### 栏目 diff --git a/lib/router.js b/lib/router.js index ef58964b9..b73003a59 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2101,6 +2101,9 @@ router.get('/mlog-club/projects', require('./routes/mlog-club/projects')); // Chrome 网上应用店 router.get('/chrome/webstore/extensions/:id', require('./routes/chrome/extensions')); +// RTHK +router.get('/rthk-news/:lang/:category', require('./routes/rthk-news/index')); + // yahoo router.get('/yahoo-news/:region/:category?', require('./routes/yahoo-news/index')); diff --git a/lib/routes/rthk-news/index.js b/lib/routes/rthk-news/index.js new file mode 100644 index 000000000..cf2a4f1de --- /dev/null +++ b/lib/routes/rthk-news/index.js @@ -0,0 +1,60 @@ +const got = require('@/utils/got'); +const parser = require('@/utils/rss-parser'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + let category = ctx.params.category.toLowerCase(); + const language = ctx.params.lang.toLowerCase(); + let languageUrlKey; + switch (language) { + case 'hk': + languageUrlKey = 'c'; + break; + case 'en': + languageUrlKey = 'e'; + break; + default: + languageUrlKey = 'c'; + break; + } + if (languageUrlKey !== 'c' || category !== 'greaterchina') { + category = languageUrlKey + category; + } + const rssUrl = `https://rthk.hk/rthk/news/rss/${languageUrlKey}_expressnews_${category}.xml`; + const feed = await parser.parseURL(rssUrl); + const title = feed.title; + const link = feed.link; + const description = feed.description; + + const items = await Promise.all( + feed.items.map(async (item) => { + const description = await ctx.cache.tryGet(item.guid, async () => { + const response = await got({ + method: 'get', + url: item.guid, + }); + const $ = cheerio.load(response.data); + + const $descriptionRoot = cheerio.load('
'); + $descriptionRoot('div.img-root').append($('div.itemImageContainer img.imgPhotoAfterLoad')); + $descriptionRoot('div.content-root').append(item.content.replace(/\r\n/g, '
')); + + return $descriptionRoot.html(); + }); + const single = { + title: item.title, + description, + pubDate: item.pubDate, + link: item.guid, + }; + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title, + link, + description, + item: items, + }; +};