适配绝大多数 BBC 频道 (#842)
This commit is contained in:
+8
-4
@@ -1276,11 +1276,15 @@ Category 列表:
|
||||
|
||||
### BBC
|
||||
|
||||
<route name="BBC" author="HenryQW" example="/bbc/chinese" path="/bbc/:channel?" :paramsDesc="['分类, 缺省为环球新闻']">
|
||||
<route name="BBC" author="HenryQW" example="/bbc/chinese" path="/bbc/:channel?" :paramsDesc="['分类, 缺省为热门']">
|
||||
|
||||
| 中文网 | 环球新闻 |
|
||||
| ------- | -------- |
|
||||
| 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`.
|
||||
|
||||
</route>
|
||||
|
||||
|
||||
+8
-4
@@ -266,11 +266,15 @@ For airport IATA code please refer to [Wikipedia List of airports by IATA code](
|
||||
|
||||
### BBC
|
||||
|
||||
<routeEn name="BBC" author="HenryQW" example="/bbc/chinese" path="/bbc/:channel?" :paramsDesc="['channel, default to `world`']">
|
||||
<routeEn name="BBC" author="HenryQW" example="/bbc/chinese" path="/bbc/:channel?" :paramsDesc="['channel, default to `top stories`']">
|
||||
|
||||
| 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.
|
||||
|
||||
</routeEn>
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
+22
-19
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user