feat(route): add 中国经济50人论坛的专家文章页面 (#7273)

* 生成中国经济50人论坛专家文章的RSS

* 添加路由

* 修正link url重复斜杠的问题

* refactor: migrate to v2

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
sddiky 2022-02-19 04:24:57 +08:00 committed by GitHub
parent f7899272c7
commit 8b8bd685a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 0 deletions

View File

@ -1934,6 +1934,12 @@ others = 热点新闻 + 滚动新闻
</Route>
## 经济 50 人论坛
### 专家文章
<Route author="sddiky" example="/50forum" path="/50forum"/>
## 鲸跃汽车
### 首页

View File

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

13
lib/v2/50forum/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'50forum.org.cn': {
_name: '经济 50 人论坛',
'.': [
{
title: '专家文章',
docs: 'https://docs.rsshub.app/new-media.html#jing-ji-50-ren-lun-tan',
source: ['/home/article/index/category/zhuanjia.html', '/'],
target: '/50forum',
},
],
},
};

3
lib/v2/50forum/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/', require('./zhuanjia'));
};

View File

@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const rootUrl = 'http://www.50forum.org.cn';
const response = await got({
method: 'get',
url: `${rootUrl}/home/article/index/category/zhuanjia.html`,
});
const data = response.data;
if (!data) {
return;
}
const $ = cheerio.load(data);
let out = $('div.container div.list_list.mtop10 ul li')
.find('a')
.toArray()
.map((item) => {
item = $(item);
const link = rootUrl + item.attr('href');
const reg = /^(.+)\[(.+)\](.+)$/;
const keyword = reg.exec(item.text().trim());
return {
title: keyword[1],
author: keyword[2],
link,
};
});
out = await Promise.all(
out.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const result = await got(item.link);
const $ = cheerio.load(result.data);
item.description = $('div.list_content').html();
item.pubDate = timezone(parseDate($('span#publish_time').text(), 'YYYY-MM-DD HH:mm'), +8);
return item;
})
)
);
ctx.state.data = {
title: `中国经济50人论坛专家文章`,
link: 'http://www.50forum.org.cn/home/article/index/category/zhuanjia.html',
description: '中国经济50人论坛专家文章',
item: out,
};
};