From 8f7da3eb2ef5bfb8c7e23e0740c0c3d530360f2b Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Mon, 8 Oct 2018 04:08:17 +0100 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E7=BB=9D=E5=A4=A7=E5=A4=9A?= =?UTF-8?q?=E6=95=B0=20BBC=20=E9=A2=91=E9=81=93=20(#842)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 12 ++++++++---- docs/en/README.md | 12 ++++++++---- routes/bbc/chinese.js | 37 ------------------------------------- routes/bbc/index.js | 41 ++++++++++++++++++++++------------------- 4 files changed, 38 insertions(+), 64 deletions(-) delete mode 100644 routes/bbc/chinese.js diff --git a/docs/README.md b/docs/README.md index 99b28874d..fd4c3affc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1276,11 +1276,15 @@ Category 列表: ### BBC - + -| 中文网 | 环球新闻 | -| ------- | -------- | -| chinese | world | +通过提取文章全文, 以提供比官方源更佳的阅读体验. + +支持大部分频道, 频道名称见[官方频道 RSS](https://www.bbc.co.uk/news/10628494). + +- 频道为单一路径, 如`https://feeds.bbci.co.uk/news/business/rss.xml` 则为 `/bbc/business`. +- 频道包含多重路径, 如 `https://feeds.bbci.co.uk/news/world/asia/rss.xml` 则替换 `/` 为 `-` `/bbc/world-asia`. +- 例外: BBC 中文网为 `/bbc/chinese`. diff --git a/docs/en/README.md b/docs/en/README.md index 9ef1b88d2..bcb41b66e 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -266,11 +266,15 @@ For airport IATA code please refer to [Wikipedia List of airports by IATA code]( ### BBC - + -| Chinese | World News | -| ------- | ---------- | -| chinese | world | +Provides better reading experience (full text articles) over the official ones. + +Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/10628494). Eg, `business` for `https://feeds.bbci.co.uk/news/business/rss.xml`. + +- Channel with a single path, such as `https://feeds.bbci.co.uk/news/business/rss.xml`, use `/bbc/business`. +- Channel contains multiple paths, such as `https://feeds.bbci.co.uk/news/world/asia/rss.xml`, replace `/` with `-`, `/bbc/world-asia`. +- Exemption: use `/bbc/chinese` for BBC News Chinese. diff --git a/routes/bbc/chinese.js b/routes/bbc/chinese.js deleted file mode 100644 index e31264449..000000000 --- a/routes/bbc/chinese.js +++ /dev/null @@ -1,37 +0,0 @@ -const axios = require('../../utils/axios'); -const cheerio = require('cheerio'); -const utils = require('./utils'); -const Parser = require('rss-parser'); -const parser = new Parser(); - -module.exports = async (ctx) => { - const feed = await parser.parseURL('http://feeds.bbci.co.uk/zhongwen/simp/rss.xml'); - - const items = await Promise.all( - feed.items.splice(0, 10).map(async (item) => { - const response = await axios({ - method: 'get', - url: item.link, - }); - - const $ = cheerio.load(response.data); - - const description = utils.ProcessFeed($, item.link).html(); - - const single = { - title: item.title, - description, - pubDate: item.pubDate, - link: item.link, - }; - return Promise.resolve(single); - }) - ); - - ctx.state.data = { - title: 'BBC News 中文', - link: 'https://www.bbc.com/zhongwen/simp', - description: 'BBC News 中文', - item: items, - }; -}; diff --git a/routes/bbc/index.js b/routes/bbc/index.js index c43207702..b948d0556 100644 --- a/routes/bbc/index.js +++ b/routes/bbc/index.js @@ -8,27 +8,30 @@ module.exports = async (ctx) => { let feed, title, link; if (ctx.params.channel) { - switch (ctx.params.channel.toLowerCase()) { - case 'chinese': - feed = await parser.parseURL('http://feeds.bbci.co.uk/zhongwen/simp/rss.xml'); - title = 'BBC 中文网'; - link = 'https://www.bbc.com/zhongwen/simp'; - break; - case 'world': - feed = await parser.parseURL('http://feeds.bbci.co.uk/news/world/rss.xml'); - title = 'BBC News World'; - link = 'https://www.bbc.co.uk/news/world'; - break; - default: - feed = await parser.parseURL('http://feeds.bbci.co.uk/news/world/rss.xml'); - title = 'BBC News World'; - link = 'https://www.bbc.co.uk/news/world'; - break; + let channel = ctx.params.channel.toLowerCase(); + channel = channel.split('-').join('/'); + + if (channel === 'chinese') { + feed = await parser.parseURL('https//feeds.bbci.co.uk/zhongwen/simp/rss.xml'); + title = 'BBC News 中文网'; + link = 'https://www.bbc.com/zhongwen/simp'; + } else { + try { + feed = await parser.parseURL(`https://feeds.bbci.co.uk/news/${channel}/rss.xml`); + title = `BBC News ${channel}`; + link = `https://www.bbc.co.uk/news/${channel}`; + } catch (error) { + ctx.state.data = { + title: `BBC News ${channel} doesn't exist`, + description: `BBC News ${channel} doesn't exist`, + }; + return; + } } } else { - feed = await parser.parseURL('http://feeds.bbci.co.uk/news/world/rss.xml'); - title = 'BBC News World'; - link = 'https://www.bbc.co.uk/news/world'; + feed = await parser.parseURL('https://feeds.bbci.co.uk/news/rss.xml'); + title = 'BBC News Top Stories'; + link = 'https://www.bbc.co.uk/news'; } const items = await Promise.all(