feat(route/bangumi): support follow ranks for book/music/real pages (#15471)

* feat(route/bangumi): support follow ranks for book/music/real pages

* feat(route/bangumi):  update lib/routes/bangumi/tv/other/followrank.ts

---------
This commit is contained in:
Zhoukun Cheng
2024-05-06 20:57:23 +08:00
committed by GitHub
parent 31ded7d292
commit cc0207ff08
+29 -16
View File
@@ -1,12 +1,13 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { config } from '@/config';
import ofetch from '@/utils/ofetch';
export const route: Route = {
path: '/tv/followrank',
path: '/:type/followrank',
categories: ['anime'],
example: '/bangumi/tv/followrank',
parameters: {},
example: '/bangumi/anime/followrank',
parameters: { type: '类型:anime - 动画, book - 图书, music - 音乐, game - 游戏, real - 三次元' },
features: {
requireConfig: false,
requirePuppeteer: false,
@@ -17,26 +18,29 @@ export const route: Route = {
},
radar: [
{
source: ['bgm.tv/anime'],
source: ['bgm.tv/:type'],
target: '/:type/followrank',
},
],
name: '成员关注动画榜',
maintainers: ['honue'],
name: '成员关注榜',
maintainers: ['honue', 'zhoukuncheng'],
handler,
url: 'bgm.tv/anime',
};
async function handler() {
const url = 'https://bgm.tv/anime';
const response = await got({
url,
method: 'get',
async function handler(ctx) {
let type = ctx.req.param('type');
if (!type || type === 'tv') {
type = 'anime';
}
const url = `https://bgm.tv/${type}`;
const response = await ofetch(url, {
headers: {
'User-Agent': config.trueUA,
},
});
const $ = load(response.body);
const $ = load(response);
const items = [
...$('#columnB > div:nth-child(4) > table > tbody')
@@ -58,10 +62,19 @@ async function handler() {
})),
];
const RANK_TYPES = {
tv: '动画',
anime: '动画',
book: '图书',
music: '音乐',
game: '游戏',
real: '三次元',
};
return {
title: 'Bangumi 成员关注动画榜',
title: `BangumiTV 成员关注${RANK_TYPES[type]}`,
link: url,
item: items,
description: `Bangumi 首页-成员关注动画`,
description: `BangumiTV 首页-成员关注${RANK_TYPES[type]}`,
};
}