/
tag.ts
49 lines (47 loc) · 1.39 KB
/
tag.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { SUB_NAME_PREFIX, SUB_URL } from './const';
import loadArticle from './article';
export const route: Route = {
path: '/tag/:tag',
categories: ['picture'],
example: '/8kcos/tag/cosplay',
parameters: { tag: '标签名' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['8kcosplay.com/tag/:tag'],
},
],
name: '标签',
maintainers: ['KotoriK'],
handler,
url: '8kcosplay.com/',
};
async function handler(ctx) {
const limit = Number.parseInt(ctx.req.query('limit'));
const tag = ctx.req.param('tag');
const url = `${SUB_URL}tag/${tag}/`;
const resp = await got(url);
const $ = load(resp.body);
const itemRaw = $('li.item').toArray();
return {
title: `${SUB_NAME_PREFIX}-${$('span[property=name]:not(.hide)').text()}`,
link: url,
item: await Promise.all(
(limit ? itemRaw.slice(0, limit) : itemRaw).map((e) => {
const { href } = load(e)('h2 > a')[0].attribs;
return cache.tryGet(href, () => loadArticle(href));
})
),
};
}