feat(route): add BBC News Labs (#8934)

* Add(route): add BBC News Labs

* refactor: migrate to v2

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
elxy 2022-03-06 00:22:59 +08:00 committed by GitHub
parent 3b53c4430e
commit 0ac081aad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 0 deletions

View File

@ -60,6 +60,12 @@ Category
<RouteEn author="nczitzk" example="/atcoder/post" path="/atcoder/post/:language?/:keyword?" :paramsDesc="['Language, `jp` as Japanese or `en` as English, English by default', 'Keyword']"/>
## BBC News Labs
### News
<RouteEn author="elxy" example="/bbcnewslabs/news" path="/bbcnewslabs/news"/>
## Codeforces
### Latest contests

View File

@ -74,6 +74,12 @@ Rated 对象
<Route author="nczitzk" example="/atcoder/post" path="/atcoder/post/:language?/:keyword?" :paramsDesc="['语言,可选 `jp` 即日语 或 `en` 即英语,默认为英语', '关键字,默认为空']"/>
## BBC News Labs
### News
<Route author="elxy" example="/bbcnewslabs/news" path="/bbcnewslabs/news"/>
## Codeforces
#### 最新比赛

View File

@ -0,0 +1,3 @@
module.exports = {
'/news': ['elxy'],
};

View File

@ -0,0 +1,32 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://bbcnewslabs.co.uk';
const response = await got({
method: 'get',
url: `${rootUrl}/news`,
});
const $ = cheerio.load(response.data);
const items = $('a[href^="/news/20"]')
.slice()
.map((_, item) => {
item = $(item);
return {
title: item.find('h3[class^="thumbnail-module--thumbnailTitle--"]').text(),
description: item.find('span[class^="thumbnail-module--thumbnailDescription--"]').text(),
pubDate: parseDate(item.find('span[class^="thumbnail-module--thumbnailType--"]').text()),
link: rootUrl + item.attr('href'),
};
})
.get();
ctx.state.data = {
title: 'News - BBC News Labs',
link: rootUrl,
item: items,
};
};

View File

@ -0,0 +1,13 @@
module.exports = {
'bbcnewslabs.co.uk': {
_name: 'BBC News Labs',
'.': [
{
title: 'News',
docs: 'https://docs.rsshub.app/programming.html#bbc-news-labs',
source: '/',
target: '/bbcnewslabs/news',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/news', require('./news'));
};