-
Notifications
You must be signed in to change notification settings - Fork 10k
Expand file tree
/
Copy pathjsj.ts
More file actions
74 lines (66 loc) · 2.27 KB
/
Copy pathjsj.ts
File metadata and controls
74 lines (66 loc) · 2.27 KB
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
import { load } from 'cheerio';
import type { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/jsj/:channelId?',
categories: ['university'],
example: '/nwpu/jsj/1599',
parameters: { channelId: '栏目 ID,默认为 1599(通知公告)' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['jsj.nwpu.edu.cn/snew/list.jsp'],
target: '/jsj/1599',
},
],
name: '计算机学院通知公告',
maintainers: [],
handler,
};
async function handler(ctx) {
const channelId = ctx.req.param('channelId') || '1599';
const baseUrl = 'https://jsj.nwpu.edu.cn';
const listUrl = `${baseUrl}/snew/list.jsp`;
const response = await ofetch(listUrl, {
query: {
urltype: 'tree.TreeTempUrl',
wbtreeid: channelId,
},
});
const $ = load(response);
// 内容在 <UL> 下的 <LI> 中,格式为: <LI><SPAN>日期</SPAN><A href="...">标题</A></LI>
const items = $('div.cno-right > UL > LI')
.toArray()
.map((el) => {
const $el = $(el);
const span = $el.find('SPAN').first();
const a = $el.find('A').first();
const dateText = span.text().trim();
// 链接格式: ../info/1599/29115.htm
const href = a.attr('href');
if (!href) {
return null;
}
// 转换为完整 URL: https://jsj.nwpu.edu.cn/info/1599/29115.htm
const link = `${baseUrl}/${href.replaceAll('../', '')}`;
return {
title: a.text().trim(),
link,
pubDate: dateText ? parseDate(dateText) : undefined,
};
})
.filter((item): item is { title: string; link: string; pubDate: Date | undefined } => item !== null && !!item.title);
return {
title: '西北工业大学计算机学院通知公告',
link: `${baseUrl}/snew/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=${channelId}`,
item: items,
};
}