feat(route): add 巴伦周刊中文版 (#8675)
This commit is contained in:
parent
552de81efc
commit
fcee9cd197
|
|
@ -38,6 +38,20 @@ pageClass: routes
|
|||
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | ---------- |
|
||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|
||||
|
||||
## 巴伦周刊中文版
|
||||
|
||||
### 栏目
|
||||
|
||||
<Route author="nczitzk" example="/barronschina" path="/barronschina/:id?" :paramsDesc="['栏目 id,默认为快讯']">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
栏目 id 留空则返回快讯,在对应页地址栏 `columnId=` 后可以看到。
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 北京证券交易所
|
||||
|
||||
### 栏目
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id ?? '';
|
||||
|
||||
const rootUrl = 'http://www.barronschina.com.cn';
|
||||
const currentUrl = `${rootUrl}/index/${id ? `column/article?columnId=${id}` : 'shortNews'}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const items = id
|
||||
? await Promise.all(
|
||||
$('.title')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('.title').text(),
|
||||
link: `${rootUrl}${item.parent().attr('href')}`,
|
||||
};
|
||||
})
|
||||
.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.cont_main').html();
|
||||
item.pubDate = timezone(parseDate(content('.timeTag').text()), +8);
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
)
|
||||
: $('dd')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const title = item.find('strong').text();
|
||||
item.find('strong').remove();
|
||||
|
||||
const description = item.find('.short').html();
|
||||
item.find('.short').remove();
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
link: currentUrl,
|
||||
pubDate: timezone(parseDate(`${item.parent().find('dt').text()} ${item.text()}`), +8),
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text().split(',')[0],
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/:id?': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'barronschina.com.cn': {
|
||||
_name: '巴伦周刊中文版',
|
||||
'.': [
|
||||
{
|
||||
title: '栏目',
|
||||
docs: 'https://docs.rsshub.app/finance.html#ba-lun-zhou-kan-zhong-wen-ban-lan-mu',
|
||||
source: ['/'],
|
||||
target: '/barronschina/:category?',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:id?', require('./index'));
|
||||
};
|
||||
Loading…
Reference in New Issue