/
weekly.ts
54 lines (52 loc) 路 1.6 KB
/
weekly.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
import { Route } from '@/types';
import { originUrl, getArticleDesc } from './utils';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/weekly',
categories: ['picture'],
example: '/jpxgmn/weekly',
radar: [
{
source: ['www.12356782.xyz/'],
target: '/weekly',
},
],
name: '鏈懆鐑棬',
maintainers: ['Urabartin'],
handler,
};
async function handler() {
const response = await ofetch.raw(originUrl);
const baseUrl = new URL(response.url).origin;
const $ = load(response._data);
const items = $('aside div:nth-child(2) li')
.toArray()
.map((item) => {
const fullTitle = $(item).find('a').attr('title') || '';
const result = fullTitle.match(/([^.]+)\.\D+([\d-]+)/);
const ret = {
title: fullTitle,
link: new URL($(item).find('a').attr('href'), baseUrl).href,
};
if (result !== null) {
ret.title = result[1];
ret.pubDate = parseDate(result[2]);
}
return ret;
});
return {
title: `鏋佸搧鎬ф劅缇庡コ - 鏈懆鐑棬鎺ㄨ崘`,
link: response.url,
item: await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
item.description = await getArticleDesc(item.link);
return item;
})
)
),
};
}