diff --git a/docs/new-media.md b/docs/new-media.md index 410056f86..10c3d93da 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2961,11 +2961,11 @@ column 为 third 时可选的 category: ### 新闻快讯 - + -| 快讯 | 新闻 | -| :---: | :--: | -| flash | news | +| 快讯 | 文章 | +| :-------: | :-----: | +| newsflash | article | diff --git a/lib/v2/blockbeats/index.js b/lib/v2/blockbeats/index.js index d4466f2e7..0f702671e 100644 --- a/lib/v2/blockbeats/index.js +++ b/lib/v2/blockbeats/index.js @@ -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, }; }; diff --git a/lib/v2/blockbeats/maintainer.js b/lib/v2/blockbeats/maintainer.js index 27645c3d7..76c0d2149 100644 --- a/lib/v2/blockbeats/maintainer.js +++ b/lib/v2/blockbeats/maintainer.js @@ -1,3 +1,3 @@ module.exports = { - '/:channel?': ['Fatpandac'], + '/:channel?': ['Fatpandac', 'jameshih'], }; diff --git a/lib/v2/blockbeats/radar.js b/lib/v2/blockbeats/radar.js index fff37fce8..ed0160c90 100644 --- a/lib/v2/blockbeats/radar.js +++ b/lib/v2/blockbeats/radar.js @@ -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', }, ], },