From 98ca20567ecc0b73f6e2b1ec3ca5118001b3b9b1 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 3 Sep 2024 22:09:22 +0800 Subject: [PATCH] feat: blockbeats article subcategory (#16617) --- lib/routes/blockbeats/article-choice.ts | 64 ------------------------- lib/routes/blockbeats/namespace.ts | 6 --- lib/routes/theblockbeats/index.ts | 13 +++-- 3 files changed, 9 insertions(+), 74 deletions(-) delete mode 100644 lib/routes/blockbeats/article-choice.ts delete mode 100644 lib/routes/blockbeats/namespace.ts diff --git a/lib/routes/blockbeats/article-choice.ts b/lib/routes/blockbeats/article-choice.ts deleted file mode 100644 index 2b8345387..000000000 --- a/lib/routes/blockbeats/article-choice.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Route } from '@/types'; -import cache from '@/utils/cache'; -import got from '@/utils/got'; -import { load } from 'cheerio'; - -export const route: Route = { - path: '/article-choice', - categories: ['new-media'], - example: '/blockbeats/article-choice', - name: '文章精选', - maintainers: ['DIYgod'], - handler, - radar: [ - { - source: ['www.theblockbeats.info/article_choice'], - target: '/article-choice', - }, - ], -}; - -async function handler() { - const response = await got('https://www.theblockbeats.info/article_choice'); - - const $ = load(response.data); - - const items = await Promise.all( - $('.article-item') - .toArray() - .map(async (item) => { - const $item = $(item); - const pubDate = new Date($item.find('.item-time').text()).toUTCString(); - let link = $item.find('.article-item-title').attr('href'); - const category = $item - .find('.item-label') - .toArray() - .map((tag) => $(tag).text().replaceAll(/^#/g, '')); - const author = $item.find('.article-item-author-name').text(); - const title = $item.find('.article-item-title').text(); - let description = ''; - if (link) { - link = `https://www.theblockbeats.info${link}`; - description = (await cache.tryGet(link, async () => { - const detailResponse = await got(link); - const content = load(detailResponse.data); - return content('.news-content').html() || ''; - })) as string; - } - return { - title, - pubDate, - link, - category, - author, - description, - }; - }) - ); - - return { - title: 'BlockBeats - 文章精选', - link: 'https://www.theblockbeats.info/article_choice', - item: items, - }; -} diff --git a/lib/routes/blockbeats/namespace.ts b/lib/routes/blockbeats/namespace.ts deleted file mode 100644 index 34feaef38..000000000 --- a/lib/routes/blockbeats/namespace.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { Namespace } from '@/types'; - -export const namespace: Namespace = { - name: 'BlockBeats 律动', - url: 'www.theblockbeats.info', -}; diff --git a/lib/routes/theblockbeats/index.ts b/lib/routes/theblockbeats/index.ts index 56a92e3b1..472dbf64e 100644 --- a/lib/routes/theblockbeats/index.ts +++ b/lib/routes/theblockbeats/index.ts @@ -40,10 +40,10 @@ const channelMap = { }; export const route: Route = { - path: '/:channel?', + path: '/:channel?/:original?', categories: ['finance'], example: '/theblockbeats/newsflash', - parameters: { channel: '类型,见下表,默认为快讯' }, + parameters: { channel: '类型,见下表,默认为快讯', original: '文章类型,仅 `channel` 为 `article` 时有效,见下表,留空为全部' }, name: '新闻快讯', maintainers: ['Fatpandac', 'jameshih'], handler, @@ -61,15 +61,20 @@ export const route: Route = { ], description: `| 快讯 | 文章 | | :-------: | :-----: | - | newsflash | article |`, + | newsflash | article | + + | 全部 | 深度 | 精选 | 热点追踪 | + | :--: | :--: | :--: | :---: | + | | -2 | 1 | 2 |`, }; async function handler(ctx) { - const { channel = 'newsflash' } = ctx.req.param(); + const { channel = 'newsflash', original } = ctx.req.param(); const response = await ofetch(channelMap[channel].api, { query: { limit: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20, + original: channel === 'article' ? original : undefined, }, });