fix(route): blockbeats (#11713)
* update blockbeats routes * remove yarn.lock * restored yarn.lock * updated route * Update lib/v2/blockbeats/index.js * Updated blockbeats route with suggestions from @TonyRL ---------
This commit is contained in:
parent
6bed7cbf49
commit
f5423a8d38
|
|
@ -2961,11 +2961,11 @@ column 为 third 时可选的 category:
|
|||
|
||||
### 新闻快讯
|
||||
|
||||
<Route author="Fatpandac" example="/blockbeats/flash" path="/blockbeats/:channel?" :paramsDesc="['类型,见下表,默认为快讯']">
|
||||
<Route author="Fatpandac jameshih" example="/blockbeats/newsflash" path="/blockbeats/:channel?" :paramsDesc="['类型,见下表,默认为快讯']">
|
||||
|
||||
| 快讯 | 新闻 |
|
||||
| :---: | :--: |
|
||||
| flash | news |
|
||||
| 快讯 | 文章 |
|
||||
| :-------: | :-----: |
|
||||
| newsflash | article |
|
||||
|
||||
</Route>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,50 +1,43 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseRelativeDate } = require('@/utils/parse-date');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const newflashApi = 'https://api.theblockbeats.info/v3/newsflash/select';
|
||||
const articleApi = 'https://api.theblockbeats.info/v3/Information/newsall';
|
||||
|
||||
const rootUrl = 'https://www.theblockbeats.info';
|
||||
|
||||
const channelMap = {
|
||||
flash: '快讯',
|
||||
news: '新闻',
|
||||
newsflash: '快讯',
|
||||
article: '文章',
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const channel = ctx.params.channel ?? 'flash';
|
||||
const channel = ctx.params.channel ?? 'newsflash';
|
||||
const { data: response } = await got(channel === 'newsflash' ? newflashApi : articleApi);
|
||||
const { data } = channel === 'newsflash' ? response.data : response;
|
||||
const 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'),
|
||||
}));
|
||||
|
||||
const response = await got.get(rootUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('div.news-item')
|
||||
.map((_, item) => {
|
||||
const title = $(item).find('a').attr('title');
|
||||
const link = rootUrl + $(item).find('a').attr('href');
|
||||
const pubDate = parseRelativeDate($(item).find('div.article-time').text());
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
pubDate,
|
||||
};
|
||||
})
|
||||
.filter((_, item) => item.title && item.link.includes(channel))
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got.get(item.link);
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content(`div.${channel}-content`).html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
if (channel !== 'newsflash') {
|
||||
await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got(item.link);
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
item.description = content('div.news-content').html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: `TheBlockBeats - ${channelMap[channel]}`,
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
item: list,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
module.exports = {
|
||||
'/:channel?': ['Fatpandac'],
|
||||
'/:channel?': ['Fatpandac', 'jameshih'],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ module.exports = {
|
|||
title: '快讯',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#lu-dong-xin-wen-kuai-xun',
|
||||
source: ['/'],
|
||||
target: '/blockbeats/flash',
|
||||
target: '/blockbeats/newsflash',
|
||||
},
|
||||
{
|
||||
title: '新闻',
|
||||
title: '文章',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#lu-dong-xin-wen-kuai-xun',
|
||||
source: ['/'],
|
||||
target: '/blockbeats/news',
|
||||
target: '/blockbeats/article',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue