feat: add back blockbeats (#14113)

* feat: add back blockbeats

* fix: path
This commit is contained in:
Tony
2023-12-26 01:20:52 +08:00
committed by GitHub
parent bbee9f247d
commit 7d50fff9c2
5 changed files with 88 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const domain = 'theblockbeats.info';
const rootUrl = `https://www.${domain}`;
const apiBase = `https://api.${domain}`;
const channelMap = {
newsflash: {
title: '快讯',
link: `${rootUrl}/newsflash`,
api: `${apiBase}/v5/newsflash/select`,
},
article: {
title: '文章',
link: `${rootUrl}/article`,
api: `${apiBase}/v5/Information/newsall`,
},
};
module.exports = async (ctx) => {
const { channel = 'newsflash' } = ctx.params;
const { data: response } = await got(channelMap[channel].api);
const { data } = channel === 'newsflash' ? response.data : response;
let list = data.map((item) => ({
title: item.title,
link: `${rootUrl}/${channel === 'newsflash' ? 'flash' : 'news'}/${item.id}`,
description: item.content ?? item.im_abstract,
pubDate: parseDate(item.add_time, 'X'),
}));
if (channel !== 'newsflash') {
list = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
item.description = $('div.news-content').html();
return item;
})
)
);
}
ctx.state.data = {
title: `TheBlockBeats - ${channelMap[channel].title}`,
link: channelMap[channel].link,
item: list,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:channel?': ['Fatpandac', 'jameshih'],
};
+19
View File
@@ -0,0 +1,19 @@
module.exports = {
'theblockbeats.info': {
_name: '律动',
rszhaopin: [
{
title: '快讯',
docs: 'https://docs.rsshub.app/routes/finance#lv-dong',
source: ['/'],
target: '/theblockbeats/newsflash',
},
{
title: '文章',
docs: 'https://docs.rsshub.app/routes/finance#lv-dong',
source: ['/'],
target: '/theblockbeats/article',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:channel?', require('./index'));
};
+10
View File
@@ -481,6 +481,16 @@ TokenInsight also provides official RSS, you can take a look at [https://api.tok
<Route author="Fatpandac" example="/laohu8/personal/3527667596890271" path="/laohu8/personal/:id" paramsDesc={['用户 ID,见网址链接']} radar="1" />
## 律动 {#lv-dong}
### 新闻快讯 {#lv-dong-xin-wen-kuai-xun}
<Route author="Fatpandac jameshih" example="/theblockbeats/newsflash" path="/theblockbeats/:channel?" paramsDesc={['类型,见下表,默认为快讯']}>
| 快讯 | 文章 |
| :-------: | :-----: |
| newsflash | article |
</Route>
## 麦肯锡 {#mai-ken-xi}
### 洞见 {#mai-ken-xi-dong-jian}