-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
gs.ts
224 lines (214 loc) · 5.48 KB
/
gs.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import { Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
const rootURL = 'https://gs.bjtu.edu.cn';
const urlCms = `${rootURL}/cms/item/?tag=`;
const urlZszt = `${rootURL}/cms/zszt/item/?cat=`;
const title = ' - 北京交通大学研究生院';
const zsztRegex = /_zszt/;
const struct = {
noti_zs: {
selector: {
list: '.tab-content li',
},
tag: 1,
name: '通知公告_招生',
},
noti: {
selector: {
list: '.tab-content li',
},
tag: 2,
name: '通知公告',
},
news: {
selector: {
list: '.tab-content li',
},
tag: 3,
name: '新闻动态',
},
zsxc: {
selector: {
list: '.tab-content li',
},
tag: 4,
name: '招生宣传',
},
py: {
selector: {
list: '.tab-content li',
},
tag: 5,
name: '培养',
},
zs: {
selector: {
list: '.tab-content li',
},
tag: 6,
name: '招生',
},
xw: {
selector: {
list: '.tab-content li',
},
tag: 7,
name: '学位',
},
ygb: {
selector: {
list: '.tab-content li',
},
tag: 8,
name: '研工部',
},
ygbtzgg: {
selector: {
list: '.tab-content li',
},
tag: 9,
name: '通知公告 - 研工部',
},
ygbnews: {
selector: {
list: '.tab-content li',
},
tag: 10,
name: '新闻动态 - 研工部',
},
ygbnewscover: {
selector: {
list: '.tab-content li',
},
tag: 11,
name: '新闻封面 - 研工部',
},
all: {
selector: {
list: '.tab-content li',
},
tag: 12,
name: '文章列表',
},
bszs_zszt: {
selector: {
list: '.mainleft_box li',
},
tag: 2,
name: '博士招生 - 招生专题',
},
sszs_zszt: {
selector: {
list: '.mainleft_box li',
},
tag: 3,
name: '硕士招生 - 招生专题',
},
zsjz_zszt: {
selector: {
list: '.mainleft_box li',
},
tag: 4,
name: '招生简章 - 招生专题',
},
zcfg_zszt: {
selector: {
list: '.mainleft_box li',
},
tag: 5,
name: '政策法规 - 招生专题',
},
};
const getItem = (item, selector) => {
const newsInfo = item.find('a');
const newsDate = item
.find('span')
.text()
.match(/\d{4}(-|\/|.)\d{1,2}\1\d{1,2}/)[0];
const infoTitle = newsInfo.text();
const link = rootURL + newsInfo.attr('href');
return cache.tryGet(link, async () => {
const resp = await ofetch(link);
const $$ = load(resp);
const infoText = $$(selector).html();
return {
title: infoTitle,
pubDate: parseDate(newsDate),
link,
description: infoText,
};
}) as any;
};
export const route: Route = {
path: '/gs/:type?',
categories: ['university'],
example: '/bjtu/gs/noti',
parameters: { type: 'Article type' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['gs.bjtu.edu.cn'],
},
],
name: '研究生院',
maintainers: ['E1nzbern'],
handler,
description: `
| 文章来源 | 参数 |
| ----------------- | ------------ |
| 通知公告_招生 | noti_zs |
| 通知公告 | noti |
| 新闻动态 | news |
| 招生宣传 | zsxc |
| 培养 | py |
| 招生 | zs |
| 学位 | xw |
| 研工部 | ygb |
| 通知公告 - 研工部 | ygbtzgg |
| 新闻动态 - 研工部 | ygbnews |
| 新闻封面 - 研工部 | ygbnewscover |
| 文章列表 | all |
| 博士招生 - 招生专题 | bszs_zszt |
| 硕士招生 - 招生专题 | sszs_zszt |
| 招生简章 - 招生专题 | zsjz_zszt |
| 政策法规 - 招生专题 | zcfg_zszt |
:::tip 文章来源
文章来源的命名均来自研究生院网站标题。
最常用的几项有“通知公告_招生”、“通知公告”、“博士招生 - 招生专题”、“硕士招生 - 招生专题”。
:::`,
};
async function handler(ctx) {
const { type = 'noti' } = ctx.req.param();
let url = urlCms;
let selectorArticle = 'div.main_left.main_left_list';
if (zsztRegex.test(type)) {
url = urlZszt;
selectorArticle = 'div.mainleft_box';
}
const urlAddr = `${url}${struct[type].tag}`;
const resp = await ofetch(urlAddr);
const $ = load(resp);
const list = $(struct[type].selector.list);
const items = await Promise.all(
list.toArray().map((i) => {
const item = $(i);
return getItem(item, selectorArticle);
})
);
return {
title: `${struct[type].name}${title}`,
link: urlAddr,
item: items,
allowEmpty: true,
};
}