/
index.ts
57 lines (49 loc) 路 1.48 KB
/
index.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
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: '/',
radar: [
{
source: ['niaogebiji.com/', 'niaogebiji.com/bulletin'],
target: '',
},
],
name: 'Unknown',
maintainers: ['WenryXu'],
handler,
url: 'niaogebiji.com/',
};
async function handler() {
const baseUrl = 'https://www.niaogebiji.com';
const { data: response } = await got(`${baseUrl}/pc/index/getMoreArticle`);
if (response.return_code !== '200') {
throw new Error(response.return_msg);
}
const postList = response.return_data.map((item) => ({
title: item.title,
description: item.summary,
author: item.author,
pubDate: parseDate(item.published_at, 'X'),
updated: parseDate(item.updated_at, 'X'),
category: [item.catname, ...item.tag_list],
link: new URL(item.link, baseUrl).href,
}));
const result = await Promise.all(
postList.map((item) =>
cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = load(response);
item.description = $('.pc_content').html();
return item;
})
)
);
return {
title: '楦熷摜绗旇',
link: baseUrl,
item: result,
};
}