From da6a97f7e1ca7ef8a59718c09305ffcb8072048d Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Sat, 28 May 2022 03:24:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=80=81=E8=99=8E?= =?UTF-8?q?=E7=A4=BE=E5=8C=BA=20(#9839)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 老虎社区 * fix(route): change to use JSON data * docs: fix heading line break * fix(radar): docs url * fix: item.link --- docs/finance.md | 7 +++++++ lib/v2/laohu8/maintainer.js | 3 +++ lib/v2/laohu8/personal.js | 32 ++++++++++++++++++++++++++++++++ lib/v2/laohu8/radar.js | 13 +++++++++++++ lib/v2/laohu8/router.js | 3 +++ 5 files changed, 58 insertions(+) create mode 100644 lib/v2/laohu8/maintainer.js create mode 100644 lib/v2/laohu8/personal.js create mode 100644 lib/v2/laohu8/radar.js create mode 100644 lib/v2/laohu8/router.js diff --git a/docs/finance.md b/docs/finance.md index 4b3aecf3f..3bfa32667 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -193,6 +193,13 @@ pageClass: routes ## 金十数据 + +## 老虎社区 + +### 个人主页 + + + ## 麦肯锡中国 diff --git a/lib/v2/laohu8/maintainer.js b/lib/v2/laohu8/maintainer.js new file mode 100644 index 000000000..e2166a81c --- /dev/null +++ b/lib/v2/laohu8/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/personal/:id': ['Fatpandac'], +}; diff --git a/lib/v2/laohu8/personal.js b/lib/v2/laohu8/personal.js new file mode 100644 index 000000000..178b91b8f --- /dev/null +++ b/lib/v2/laohu8/personal.js @@ -0,0 +1,32 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const rootUrl = 'https://www.laohu8.com'; + +module.exports = async (ctx) => { + const id = ctx.params.id; + const url = `${rootUrl}/personal/${id}`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const author = $('h2.personal-name').text(); + const data = JSON.parse($('#__APP_DATA__').text()).tweetList; + + const items = await Promise.all( + data.map((item) => + ctx.cache.tryGet(item.link, () => ({ + title: item.title, + description: String(item.htmlText).replace(/\n/g, '

'), + link: `${rootUrl}/post/${item.id}`, + pubDate: parseDate(item.gmtCreate), + })) + ) + ); + + ctx.state.data = { + title: `老虎社区 - ${author} 个人社区`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/laohu8/radar.js b/lib/v2/laohu8/radar.js new file mode 100644 index 000000000..777bc92c8 --- /dev/null +++ b/lib/v2/laohu8/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'laohu8.com': { + _name: '老虎社区', + '.': [ + { + title: '个人主页', + docs: 'https://docs.rsshub.app/finance.html#lao-hu-she-qu', + source: '/personal/:id', + target: '/laohu8/personal/:id', + }, + ], + }, +}; diff --git a/lib/v2/laohu8/router.js b/lib/v2/laohu8/router.js new file mode 100644 index 000000000..347dc65d7 --- /dev/null +++ b/lib/v2/laohu8/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/personal/:id', require('./personal')); +};