feat(route): 首席经济学家 (#9543)
* Add chinacef router. * Update the document. * Move to V2. * Fix document errors and improve the code.
This commit is contained in:
@@ -237,6 +237,12 @@ pageClass: routes
|
||||
|
||||
</Route>
|
||||
|
||||
## 首席经济学家论坛
|
||||
|
||||
### 最新更新文章列表
|
||||
|
||||
<Route author="FledgeXu" example="/chinacef" path="/chinacef"/>
|
||||
|
||||
## 淘股吧股票论坛
|
||||
|
||||
### 论坛总版
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
const utils = require('./utils');
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'http://www.chinacef.cn';
|
||||
const regex = /^\/index\.php\/index\/article\/article_id\/\d+/g;
|
||||
const timeRegex = /(\d{4}-\d{2}-\d{2})/g;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const articlesLinkListNode = $('a[target=_black]')
|
||||
.filter((_, item) => item.attribs.href.match(regex))
|
||||
.map((_, item) => item.attribs.href);
|
||||
const articlesLinkList = Array.from(new Set(articlesLinkListNode));
|
||||
|
||||
const out = await Promise.all(
|
||||
articlesLinkList.map(async (item) => {
|
||||
const articlesLink = rootUrl + item;
|
||||
const $ = await await ctx.cache.tryGet(articlesLink, async () => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: articlesLink,
|
||||
});
|
||||
return cheerio.load(response.data);
|
||||
});
|
||||
|
||||
// Clean article style
|
||||
$('*[style]').removeAttr('style');
|
||||
$('br').remove();
|
||||
$('span:empty').remove();
|
||||
$('p:empty').remove();
|
||||
$('p').each((_, el) => {
|
||||
if ($(el).html().trim() === '') {
|
||||
$(el).remove();
|
||||
}
|
||||
});
|
||||
|
||||
const title = $('span[class=contenttitle]').first().text().trim();
|
||||
const author = $('a[rel=author]').first().text().trim();
|
||||
const time = $('a[rel=author]').parent().text().match(timeRegex)[0];
|
||||
const pubDate = parseDate(time, 'YYYY-MM-DD');
|
||||
const description = $('div[class=newsmaintext]').html();
|
||||
|
||||
const element = {
|
||||
title,
|
||||
author,
|
||||
pubDate,
|
||||
description: utils.renderDesc(description),
|
||||
link: articlesLink,
|
||||
};
|
||||
return element;
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '首席经济学家论坛',
|
||||
description: '首席经济学家最近更新的文章',
|
||||
link: rootUrl,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/chinacef': ['FledgeXu'],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'chinacef.cn': {
|
||||
_name: '首席经济学家论坛',
|
||||
'.': [
|
||||
{
|
||||
title: '最新文章列表',
|
||||
docs: 'https://docs.rsshub.app/finance.html#shou-xi-jing-ji-xue-jia-lun-tan',
|
||||
source: ['/'],
|
||||
target: '/chinacef',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/', require('./index'));
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
{{@ desc }}
|
||||
@@ -0,0 +1,11 @@
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
const renderDesc = (desc) =>
|
||||
art(path.join(__dirname, 'templates/description.art'), {
|
||||
desc,
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
renderDesc,
|
||||
};
|
||||
Reference in New Issue
Block a user