/
news.ts
77 lines (66 loc) 路 1.96 KB
/
news.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
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/news',
categories: ['new-media'],
example: '/sakurazaka46/news',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['sakurazaka46.com/s/s46/news/list', 'sakurazaka46.com/'],
},
],
name: 'Sakurazaka46 News 娅诲潅 46 鏂伴椈',
maintainers: ['nczitzk'],
handler,
url: 'sakurazaka46.com/s/s46/news/list',
};
async function handler(ctx) {
const rootUrl = 'https://sakurazaka46.com';
const currentUrl = `${rootUrl}/s/s46/news/list`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = load(response.data);
let items = $('.com-news-part .box a')
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('.lead').text(),
link: `${rootUrl}${item.attr('href').split('?')[0]}`,
pubDate: parseDate(item.find('.date').text()),
};
});
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = load(detailResponse.data);
item.description = content('.article').html();
return item;
})
)
);
return {
title: $('title').text(),
link: currentUrl,
item: items,
};
}