feat(route): add 老虎社区 (#9839)

* feat(route): add 老虎社区

* fix(route): change to use JSON data

* docs: fix heading line break

* fix(radar): docs url

* fix: item.link
This commit is contained in:
Fatpandac 2022-05-28 03:24:22 +08:00 committed by GitHub
parent f12289fa60
commit da6a97f7e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 0 deletions

View File

@ -193,6 +193,13 @@ pageClass: routes
## 金十数据
<Route author="laampui" example="/jinshi/index" path="/jinshi/index" />
## 老虎社区
### 个人主页
<Route author="Fatpandac" example="/laohu8/personal/3527667596890271" path="/laohu8/personal/:id" :paramsDesc="['用户 ID见网址链接']" rssbud="1" radar="1"/>
## 麦肯锡中国
<Route author="laampui" example="/mckinsey/autos" path="/mckinsey/:category?" :paramsDesc="['默认为全部,见下表']">

View File

@ -0,0 +1,3 @@
module.exports = {
'/personal/:id': ['Fatpandac'],
};

32
lib/v2/laohu8/personal.js Normal file
View File

@ -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, '<br><br>'),
link: `${rootUrl}/post/${item.id}`,
pubDate: parseDate(item.gmtCreate),
}))
)
);
ctx.state.data = {
title: `老虎社区 - ${author} 个人社区`,
link: url,
item: items,
};
};

13
lib/v2/laohu8/radar.js Normal file
View File

@ -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',
},
],
},
};

3
lib/v2/laohu8/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/personal/:id', require('./personal'));
};