From 3c432eb7e0784ff0aae24dad1b424f0c77d580b9 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 17:02:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=B3=95=E5=9B=BD?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=B9=BF=E6=92=AD=E7=94=B5=E5=8F=B0=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E6=96=B0=E9=97=BB=20(#8533)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/multimedia.md | 6 +++++ lib/v2/rfi/maintainer.js | 3 +++ lib/v2/rfi/news.js | 49 ++++++++++++++++++++++++++++++++++++++++ lib/v2/rfi/radar.js | 13 +++++++++++ lib/v2/rfi/router.js | 3 +++ 5 files changed, 74 insertions(+) create mode 100644 lib/v2/rfi/maintainer.js create mode 100644 lib/v2/rfi/news.js create mode 100644 lib/v2/rfi/radar.js create mode 100644 lib/v2/rfi/router.js diff --git a/docs/multimedia.md b/docs/multimedia.md index 909e66dc3..ee2654374 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -924,6 +924,12 @@ pageClass: routes +## 法国国际广播电台 + +### 滚动新闻 + + + ## 高清电台 ### 最新电影 diff --git a/lib/v2/rfi/maintainer.js b/lib/v2/rfi/maintainer.js new file mode 100644 index 000000000..169cca9bc --- /dev/null +++ b/lib/v2/rfi/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news': ['nczitzk'], +}; diff --git a/lib/v2/rfi/news.js b/lib/v2/rfi/news.js new file mode 100644 index 000000000..d25a46fb8 --- /dev/null +++ b/lib/v2/rfi/news.js @@ -0,0 +1,49 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.rfi.fr'; + const currentUrl = `${rootUrl}/cn/滚动新闻`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.article__title') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${item.parent().parent().attr('href')}`, + pubDate: parseDate(item.prev().find('time').attr('datetime')), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('.t-content__body').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '滚动新闻 - 法国国际广播电台', + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/rfi/radar.js b/lib/v2/rfi/radar.js new file mode 100644 index 000000000..3e03c60a6 --- /dev/null +++ b/lib/v2/rfi/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'rfi.fr': { + _name: '法国国际广播电台', + '.': [ + { + title: '滚动新闻', + docs: 'https://docs.rsshub.app/multimedia.html#fa-guo-guo-ji-guang-bo-dian-tai-gun-dong-xin-wen', + source: ['/'], + target: '/rfi/news', + }, + ], + }, +}; diff --git a/lib/v2/rfi/router.js b/lib/v2/rfi/router.js new file mode 100644 index 000000000..69a5972f6 --- /dev/null +++ b/lib/v2/rfi/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news', require('./news')); +};