diff --git a/docs/en/finance.md b/docs/en/finance.md index 2ebc25d453..d60061b65b 100644 --- a/docs/en/finance.md +++ b/docs/en/finance.md @@ -27,6 +27,10 @@ pageClass: routes +### Authors + + + ## CFD ### Indices Dividend Adjustment (GBP) diff --git a/lib/v2/bloomberg/authors.js b/lib/v2/bloomberg/authors.js new file mode 100644 index 0000000000..e226144461 --- /dev/null +++ b/lib/v2/bloomberg/authors.js @@ -0,0 +1,14 @@ +const { asyncPoolAll, parseArticle } = require('./utils'); +const parser = require('@/utils/rss-parser'); + +module.exports = async (ctx) => { + const { id, slug } = ctx.params; + const feed = await parser.parseURL(`https://www.bloomberg.com/authors/${id}/${slug}.rss`); + const item = await asyncPoolAll(1, feed.items, (item) => parseArticle(item, ctx)); + ctx.state.data = { + title: `Bloomberg - ${feed.title.split(' - ', 2)[0]}`, + link: feed.link, + language: feed.language, + item, + }; +}; diff --git a/lib/v2/bloomberg/index.js b/lib/v2/bloomberg/index.js index 4ac3c0889f..9ab1056856 100644 --- a/lib/v2/bloomberg/index.js +++ b/lib/v2/bloomberg/index.js @@ -1,5 +1,4 @@ -const { rootUrl, parseNewsList, parseArticle } = require('./utils'); -const asyncPool = require('tiny-async-pool'); +const { rootUrl, asyncPoolAll, parseNewsList, parseArticle } = require('./utils'); const site_title_mapping = { '/': 'News', bpol: 'Politics', @@ -15,14 +14,6 @@ const site_title_mapping = { citylab: 'CityLab', }; -const asyncPoolAll = async (...args) => { - const results = []; - for await (const result of asyncPool(...args)) { - results.push(result); - } - return results; -}; - module.exports = async (ctx) => { const { site } = ctx.params; const currentUrl = site ? `${rootUrl}/${site}/sitemap_news.xml` : `${rootUrl}/sitemap_news.xml`; diff --git a/lib/v2/bloomberg/maintainer.js b/lib/v2/bloomberg/maintainer.js index b0f1e5315e..17c8230dcc 100644 --- a/lib/v2/bloomberg/maintainer.js +++ b/lib/v2/bloomberg/maintainer.js @@ -1,4 +1,5 @@ module.exports = { + '/authors/:id/:slug': ['josh'], '/:site?': ['bigfei'], '/': ['bigfei'], }; diff --git a/lib/v2/bloomberg/radar.js b/lib/v2/bloomberg/radar.js index f91cca2a11..5e302bd11d 100644 --- a/lib/v2/bloomberg/radar.js +++ b/lib/v2/bloomberg/radar.js @@ -1,13 +1,19 @@ module.exports = { 'bloomberg.com': { - _name: 'bloomberg', + _name: 'Bloomberg', www: [ { - title: 'Bloomberg', - docs: 'https://docs.rsshub.app/finance.html##bloomberg-news', + title: 'News', + docs: 'https://docs.rsshub.app/finance.html#bloomberg-news', source: ['/:site', '/'], target: '/bloomberg/:site?', }, + { + title: 'Authors', + docs: 'https://docs.rsshub.app/finance.html#bloomberg', + source: ['/*/authors/:id/:slug', '/authors/:id/:slug'], + target: '/bloomberg/authors/:id/:slug', + }, ], }, }; diff --git a/lib/v2/bloomberg/router.js b/lib/v2/bloomberg/router.js index 12005eff60..a310c8fd5b 100644 --- a/lib/v2/bloomberg/router.js +++ b/lib/v2/bloomberg/router.js @@ -1,4 +1,5 @@ module.exports = function (router) { + router.get('/authors/:id/:slug', require('./authors')); router.get('/:site', require('./index')); router.get('/', require('./index')); }; diff --git a/lib/v2/bloomberg/utils.js b/lib/v2/bloomberg/utils.js index e8ce1f4f33..7526910324 100644 --- a/lib/v2/bloomberg/utils.js +++ b/lib/v2/bloomberg/utils.js @@ -1,5 +1,6 @@ const cheerio = require('cheerio'); const path = require('path'); +const asyncPool = require('tiny-async-pool'); const { parseDate } = require('@/utils/parse-date'); const got = require('@/utils/got'); @@ -388,8 +389,17 @@ const processBody = async (body_html, story_json) => { return $.html(); }; +const asyncPoolAll = async (...args) => { + const results = []; + for await (const result of asyncPool(...args)) { + results.push(result); + } + return results; +}; + module.exports = { rootUrl, + asyncPoolAll, parseNewsList, parseArticle, };