/
blogs.ts
97 lines (81 loc) · 2.7 KB
/
blogs.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { defaultDomain, getRootUrl } from './utils';
export const route: Route = {
path: '/blogs/:category?',
categories: ['anime'],
example: '/18comic/blogs',
parameters: { category: '分类,见下表,默认为空即全部' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['jmcomic.group/'],
},
],
name: '文庫',
maintainers: ['nczitzk'],
handler,
url: 'jmcomic.group/',
description: `分类
| 全部 | 紳夜食堂 | 遊戲文庫 | JG GAMES | 模型山下 |
| ---- | -------- | -------- | -------- | -------- |
| | dinner | raiders | jg | figure |`,
};
async function handler(ctx) {
const category = ctx.req.param('category') ?? '';
const { domain = defaultDomain } = ctx.req.query();
const rootUrl = getRootUrl(domain);
const currentUrl = `${rootUrl}/blogs${category ? `/${category}` : ''}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = load(response.data);
let items = $('.title')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.parent().attr('href')}`,
guid: `https://18comic.org${item.parent().attr('href')}`,
};
});
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.guid, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = load(detailResponse.data);
item.pubDate = parseDate(content('.date').first().text());
content('.d-flex').remove();
item.author = content('.blog_name_id').first().text();
item.description = content('.blog_content').html();
item.category = content('.panel-heading dropdown-toggle')
.toArray()
.map((c) => $(c).text());
return item;
})
)
);
return {
title: $('title')
.text()
.replace(/最新的/, $('.article-nav .active').text()),
link: currentUrl,
item: items,
description: $('meta[property="og:description"]').attr('content'),
};
}