feat: blockbeats article subcategory (#16617)

This commit is contained in:
Tony 2024-09-03 22:09:22 +08:00 committed by GitHub
parent 8cc3349163
commit 98ca20567e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 74 deletions

View File

@ -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,
};
}

View File

@ -1,6 +0,0 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'BlockBeats 律动',
url: 'www.theblockbeats.info',
};

View File

@ -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,
},
});