From 369d2902e86117e03ee44625a3f06b2179c03ad0 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 2 Feb 2022 02:52:14 +0800 Subject: [PATCH] feat(route): add Radio-Canada.ca latest news (#8275) * feat(route): add Radio-Canada.ca latest news * fix typo * fix typo * update lib/v2/radio-canada/radar.js Co-authored-by: Tony * update docs/en/new-media.md Co-authored-by: Tony * update docs/new-media.md Co-authored-by: Tony Co-authored-by: Tony --- docs/en/new-media.md | 12 +++++++++ docs/new-media.md | 12 +++++++++ lib/v2/radio-canada/latest.js | 43 +++++++++++++++++++++++++++++++ lib/v2/radio-canada/maintainer.js | 3 +++ lib/v2/radio-canada/radar.js | 13 ++++++++++ lib/v2/radio-canada/router.js | 3 +++ 6 files changed, 86 insertions(+) create mode 100644 lib/v2/radio-canada/latest.js create mode 100644 lib/v2/radio-canada/maintainer.js create mode 100644 lib/v2/radio-canada/radar.js create mode 100644 lib/v2/radio-canada/router.js diff --git a/docs/en/new-media.md b/docs/en/new-media.md index e62df65a6..63453c092 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -494,6 +494,18 @@ Compared to the official one, this feed: +## Radio-Canada.ca + +### Latest News + + + +| Français | English | Español | 简体中文 | 繁體中文 | العربية | ਪੰਜਾਬੀ | Tagalog | +| -------- | ------- | ------- | -------- | -------- | ------- | ------ | ------- | +| fr | en | es | zh-hans | zh-hant | ar | pa | tl | + + + ## Research Gate ### Publications diff --git a/docs/new-media.md b/docs/new-media.md index 667a32eaa..23a455523 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1858,6 +1858,18 @@ others = 热点新闻 + 滚动新闻 +## 加拿大国际广播电台 + +### 最新消息 + + + +| Français | English | Español | 简体中文 | 繁體中文 | العربية | ਪੰਜਾਬੀ | Tagalog | +| -------- | ------- | ------- | -------- | -------- | ------- | ------ | ------- | +| fr | en | es | zh-hans | zh-hant | ar | pa | tl | + + + ## 贾真的电商 108 将 ### 「108 将」实战分享 diff --git a/lib/v2/radio-canada/latest.js b/lib/v2/radio-canada/latest.js new file mode 100644 index 000000000..789a48307 --- /dev/null +++ b/lib/v2/radio-canada/latest.js @@ -0,0 +1,43 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const language = ctx.params.language ?? 'en'; + + const rootUrl = 'https://ici.radio-canada.ca'; + const apiRootUrl = 'https://services.radio-canada.ca'; + const currentUrl = `${apiRootUrl}/neuro/sphere/v1/rci/${language}/continuous-feed?pageSize=50`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const list = response.data.data.lineup.items.map((item) => ({ + title: item.title, + category: item.kicker, + link: `${rootUrl}${item.url}`, + pubDate: parseDate(item.date), + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + item.description = detailResponse.data.match(/"body":{"html":"(.*)","attachments"/)[1].replace(/\\n/g, ''); + + return item; + }) + ) + ); + + ctx.state.data = { + title: response.data.meta.title, + link: response.data.metric.metrikContent.omniture.url, + item: items, + }; +}; diff --git a/lib/v2/radio-canada/maintainer.js b/lib/v2/radio-canada/maintainer.js new file mode 100644 index 000000000..57f1d832a --- /dev/null +++ b/lib/v2/radio-canada/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/latest/:language?': ['nczitzk'], +}; diff --git a/lib/v2/radio-canada/radar.js b/lib/v2/radio-canada/radar.js new file mode 100644 index 000000000..60ba06c2a --- /dev/null +++ b/lib/v2/radio-canada/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'ici.radio-canada.ca': { + _name: 'Radio Canada', + '.': [ + { + title: 'Latest News', + docs: 'https://docs.rsshub.app/new-media.html#jia-na-da-guo-ji-guang-bo-dian-tai-zui-xin-xiao-xi', + source: ['/rci/:lang', '/'], + target: '/radio-canada/latest/:language?', + }, + ], + }, +}; diff --git a/lib/v2/radio-canada/router.js b/lib/v2/radio-canada/router.js new file mode 100644 index 000000000..89de189ec --- /dev/null +++ b/lib/v2/radio-canada/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/latest/:language?', require('./latest')); +};