From 0ac081aad0bb8d5c97ebfcc5fc5a6cffda82e2f7 Mon Sep 17 00:00:00 2001 From: elxy Date: Sun, 6 Mar 2022 00:22:59 +0800 Subject: [PATCH] feat(route): add BBC News Labs (#8934) * Add(route): add BBC News Labs * refactor: migrate to v2 Co-authored-by: TonyRL --- docs/en/programming.md | 6 ++++++ docs/programming.md | 6 ++++++ lib/v2/bbcnewslabs/maintainer.js | 3 +++ lib/v2/bbcnewslabs/news.js | 32 ++++++++++++++++++++++++++++++++ lib/v2/bbcnewslabs/radar.js | 13 +++++++++++++ lib/v2/bbcnewslabs/router.js | 3 +++ 6 files changed, 63 insertions(+) create mode 100644 lib/v2/bbcnewslabs/maintainer.js create mode 100644 lib/v2/bbcnewslabs/news.js create mode 100644 lib/v2/bbcnewslabs/radar.js create mode 100644 lib/v2/bbcnewslabs/router.js diff --git a/docs/en/programming.md b/docs/en/programming.md index e2319832d..783703cd0 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -60,6 +60,12 @@ Category +## BBC News Labs + +### News + + + ## Codeforces ### Latest contests diff --git a/docs/programming.md b/docs/programming.md index 5abbea528..5f162496b 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -74,6 +74,12 @@ Rated 对象 +## BBC News Labs + +### News + + + ## Codeforces #### 最新比赛 diff --git a/lib/v2/bbcnewslabs/maintainer.js b/lib/v2/bbcnewslabs/maintainer.js new file mode 100644 index 000000000..b8793db0e --- /dev/null +++ b/lib/v2/bbcnewslabs/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news': ['elxy'], +}; diff --git a/lib/v2/bbcnewslabs/news.js b/lib/v2/bbcnewslabs/news.js new file mode 100644 index 000000000..a44ab9461 --- /dev/null +++ b/lib/v2/bbcnewslabs/news.js @@ -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, + }; +}; diff --git a/lib/v2/bbcnewslabs/radar.js b/lib/v2/bbcnewslabs/radar.js new file mode 100644 index 000000000..30faa90e0 --- /dev/null +++ b/lib/v2/bbcnewslabs/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/bbcnewslabs/router.js b/lib/v2/bbcnewslabs/router.js new file mode 100644 index 000000000..630036b8e --- /dev/null +++ b/lib/v2/bbcnewslabs/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/news', require('./news')); +};