From 781c4270a3da3b53ed6fb8f3edbc64902dea38e6 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Tue, 20 Dec 2022 22:02:50 +0800 Subject: [PATCH] feat(route): add paradigm writing (#11478) * feat(router): add paradigm writing * Update lib/v2/paradigm/writing.js * Update lib/v2/paradigm/writing.js --- docs/en/finance.md | 6 +++++ docs/finance.md | 6 +++++ lib/v2/paradigm/maintainer.js | 3 +++ lib/v2/paradigm/radar.js | 13 +++++++++++ lib/v2/paradigm/router.js | 3 +++ lib/v2/paradigm/writing.js | 44 +++++++++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 lib/v2/paradigm/maintainer.js create mode 100644 lib/v2/paradigm/radar.js create mode 100644 lib/v2/paradigm/router.js create mode 100644 lib/v2/paradigm/writing.js diff --git a/docs/en/finance.md b/docs/en/finance.md index 6bbfffacc..2ebc25d45 100644 --- a/docs/en/finance.md +++ b/docs/en/finance.md @@ -61,6 +61,12 @@ pageClass: routes +## Paradigm + +### Writing + + + ## Seeking Alpha ### Summary diff --git a/docs/finance.md b/docs/finance.md index 7dfae0225..cab69b74d 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -104,6 +104,12 @@ pageClass: routes +## Paradigm + +### Writing + + + ## Seeking Alpha ### Summary diff --git a/lib/v2/paradigm/maintainer.js b/lib/v2/paradigm/maintainer.js new file mode 100644 index 000000000..9ce7d5076 --- /dev/null +++ b/lib/v2/paradigm/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/writing': ['Fatpandac'], +}; diff --git a/lib/v2/paradigm/radar.js b/lib/v2/paradigm/radar.js new file mode 100644 index 000000000..07477c1e1 --- /dev/null +++ b/lib/v2/paradigm/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'paradigm.xyz': { + _name: 'Paradigm', + '.': [ + { + title: 'Writing', + docs: 'https://docs.rsshub.app/finance.html#paradigm', + source: ['/writing'], + target: '/paradigm/writing', + }, + ], + }, +}; diff --git a/lib/v2/paradigm/router.js b/lib/v2/paradigm/router.js new file mode 100644 index 000000000..76d1ccbb3 --- /dev/null +++ b/lib/v2/paradigm/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/writing', require('./writing')); +}; diff --git a/lib/v2/paradigm/writing.js b/lib/v2/paradigm/writing.js new file mode 100644 index 000000000..5c5e3ce0f --- /dev/null +++ b/lib/v2/paradigm/writing.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const baseUrl = 'https://www.paradigm.xyz'; + +module.exports = async (ctx) => { + const url = `${baseUrl}/writing`; + + const response = await got(url); + const $ = cheerio.load(response.data); + + const nextData = JSON.parse($('#__NEXT_DATA__').text()); + const buildId = nextData.buildId; + const list = nextData.props.pageProps.posts.map((item) => ({ + title: item.title, + link: `${baseUrl}${item.slug}`, + api: `${baseUrl}/_next/data/${buildId}${item.slug}.json`, + author: item.authors.map((author) => author.name).join(', '), + pubDate: parseDate(item.originalDate), + category: item.tags, + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got(item.api); + const $ = cheerio.load(response.data.pageProps.content, null, false); + + // Remove the TOC + $('.toc').remove(); + item.description = $.html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: 'Paradigm - Writing', + link: url, + item: items, + }; +};