dsh-ustc-campus 0.2.14 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +74 -71
- package/dist/client.js +5946 -1061
- package/package.json +63 -24
- package/src/account-data.mjs +194 -0
- package/src/bb-actions.mjs +3 -1
- package/src/bb.mjs +15 -9
- package/src/campus-transit.mjs +58 -52
- package/src/client.mjs +74 -633
- package/src/concurrency.mjs +13 -0
- package/src/custom-feeds.mjs +519 -0
- package/src/exams.mjs +21 -7
- package/src/feed.mjs +525 -137
- package/src/grades.mjs +30 -16
- package/src/host.mjs +52 -81
- package/src/library-spaces.mjs +39 -35
- package/src/material.mjs +2268 -65
- package/src/mcp-host.mjs +56 -5
- package/src/mcp.mjs +136 -27
- package/src/recommender.mjs +1319 -0
- package/src/school.mjs +218 -154
- package/src/snapshot-cache.mjs +98 -0
- package/src/state.mjs +152 -16
- package/src/youth-actions.mjs +52 -58
- package/src/youth.mjs +55 -26
package/src/feed.mjs
CHANGED
|
@@ -7,6 +7,23 @@ import {
|
|
|
7
7
|
sanitizeText,
|
|
8
8
|
shanghaiEpoch
|
|
9
9
|
} from './public-fetch.mjs';
|
|
10
|
+
import { createRecommender } from './recommender.mjs';
|
|
11
|
+
import { mapLimited } from './concurrency.mjs';
|
|
12
|
+
|
|
13
|
+
export const FEED_CATEGORY_LABELS = Object.freeze({
|
|
14
|
+
campus: '学校要闻与综合公告',
|
|
15
|
+
academic: '本科教务与考试',
|
|
16
|
+
research: '科研进展与成果',
|
|
17
|
+
student: '学工资助与学生事务',
|
|
18
|
+
activity: '团学文化与第二课堂',
|
|
19
|
+
lecture: '学术讲座与图书馆培训',
|
|
20
|
+
tech: '开源社区与技术活动',
|
|
21
|
+
service: '校园网络、医疗、财务与安保',
|
|
22
|
+
exchange: '国际交流与校际访学',
|
|
23
|
+
college: '学院通知与学部动态'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const FEED_CATEGORIES = Object.freeze(Object.keys(FEED_CATEGORY_LABELS));
|
|
10
27
|
|
|
11
28
|
/**
|
|
12
29
|
* Fixed public sources. No caller-supplied URL is ever fetched.
|
|
@@ -20,6 +37,7 @@ export const FEED_SOURCES = Object.freeze({
|
|
|
20
37
|
id: 'news',
|
|
21
38
|
label: '中国科大新闻网',
|
|
22
39
|
kind: 'news',
|
|
40
|
+
category: 'campus',
|
|
23
41
|
parser: 'news',
|
|
24
42
|
url: 'https://news.ustc.edu.cn/xwbl.htm',
|
|
25
43
|
origin: 'https://news.ustc.edu.cn/',
|
|
@@ -29,6 +47,7 @@ export const FEED_SOURCES = Object.freeze({
|
|
|
29
47
|
id: 'teach',
|
|
30
48
|
label: '教务处教学通知',
|
|
31
49
|
kind: 'notice',
|
|
50
|
+
category: 'academic',
|
|
32
51
|
parser: 'list',
|
|
33
52
|
url: 'https://www.teach.ustc.edu.cn/category/notice/notice-teaching',
|
|
34
53
|
origin: 'https://www.teach.ustc.edu.cn/',
|
|
@@ -38,6 +57,7 @@ export const FEED_SOURCES = Object.freeze({
|
|
|
38
57
|
id: 'teach-exam',
|
|
39
58
|
label: '教务处考试通知',
|
|
40
59
|
kind: 'notice',
|
|
60
|
+
category: 'academic',
|
|
41
61
|
parser: 'list',
|
|
42
62
|
url: 'https://www.teach.ustc.edu.cn/category/notice/notice-exam',
|
|
43
63
|
origin: 'https://www.teach.ustc.edu.cn/',
|
|
@@ -47,6 +67,7 @@ export const FEED_SOURCES = Object.freeze({
|
|
|
47
67
|
id: 'ustc',
|
|
48
68
|
label: '科大通知公告',
|
|
49
69
|
kind: 'notice',
|
|
70
|
+
category: 'campus',
|
|
50
71
|
parser: 'ustc-notice',
|
|
51
72
|
url: 'https://www.ustc.edu.cn/tzgg.htm',
|
|
52
73
|
origin: 'https://www.ustc.edu.cn/',
|
|
@@ -56,6 +77,7 @@ export const FEED_SOURCES = Object.freeze({
|
|
|
56
77
|
id: 'youth',
|
|
57
78
|
label: '校团委通知公告',
|
|
58
79
|
kind: 'notice',
|
|
80
|
+
category: 'activity',
|
|
59
81
|
parser: 'list',
|
|
60
82
|
url: 'https://young.ustc.edu.cn/15063/list.htm',
|
|
61
83
|
origin: 'https://young.ustc.edu.cn/',
|
|
@@ -65,6 +87,7 @@ export const FEED_SOURCES = Object.freeze({
|
|
|
65
87
|
id: 'stuhome',
|
|
66
88
|
label: '学工动态',
|
|
67
89
|
kind: 'news',
|
|
90
|
+
category: 'student',
|
|
68
91
|
parser: 'list',
|
|
69
92
|
url: 'https://stuhome.ustc.edu.cn/2315/list.htm',
|
|
70
93
|
origin: 'https://stuhome.ustc.edu.cn/',
|
|
@@ -74,6 +97,7 @@ export const FEED_SOURCES = Object.freeze({
|
|
|
74
97
|
id: 'library',
|
|
75
98
|
label: '图书馆服务公告',
|
|
76
99
|
kind: 'news',
|
|
100
|
+
category: 'service',
|
|
77
101
|
parser: 'list',
|
|
78
102
|
url: 'https://lib.ustc.edu.cn/category/%E6%9C%8D%E5%8A%A1%E5%85%AC%E5%91%8A/',
|
|
79
103
|
origin: 'https://lib.ustc.edu.cn/',
|
|
@@ -83,6 +107,7 @@ export const FEED_SOURCES = Object.freeze({
|
|
|
83
107
|
id: 'library-lecture',
|
|
84
108
|
label: '图书馆讲座培训',
|
|
85
109
|
kind: 'event',
|
|
110
|
+
category: 'lecture',
|
|
86
111
|
parser: 'library-lecture',
|
|
87
112
|
url: 'https://lib.ustc.edu.cn/category/%E8%AE%B2%E5%BA%A7%E5%9F%B9%E8%AE%AD/',
|
|
88
113
|
origin: 'https://lib.ustc.edu.cn/',
|
|
@@ -92,39 +117,213 @@ export const FEED_SOURCES = Object.freeze({
|
|
|
92
117
|
id: 'lug',
|
|
93
118
|
label: 'USTC LUG 活动',
|
|
94
119
|
kind: 'event',
|
|
120
|
+
category: 'tech',
|
|
95
121
|
parser: 'lug',
|
|
96
122
|
url: 'https://lug.ustc.edu.cn/wiki/lug/events/',
|
|
97
123
|
origin: 'https://lug.ustc.edu.cn/',
|
|
98
124
|
hosts: Object.freeze(['lug.ustc.edu.cn'])
|
|
125
|
+
}),
|
|
126
|
+
'news-research': Object.freeze({
|
|
127
|
+
id: 'news-research',
|
|
128
|
+
label: '中国科大科研进展',
|
|
129
|
+
kind: 'news',
|
|
130
|
+
category: 'research',
|
|
131
|
+
parser: 'news',
|
|
132
|
+
url: 'https://news.ustc.edu.cn/kyjz.htm',
|
|
133
|
+
origin: 'https://news.ustc.edu.cn/',
|
|
134
|
+
hosts: Object.freeze(['news.ustc.edu.cn'])
|
|
135
|
+
}),
|
|
136
|
+
'teach-exchange': Object.freeze({
|
|
137
|
+
id: 'teach-exchange',
|
|
138
|
+
label: '教务处交流交换',
|
|
139
|
+
kind: 'notice',
|
|
140
|
+
category: 'exchange',
|
|
141
|
+
parser: 'list',
|
|
142
|
+
url: 'https://www.teach.ustc.edu.cn/category/notice/notice-exchange',
|
|
143
|
+
origin: 'https://www.teach.ustc.edu.cn/',
|
|
144
|
+
hosts: Object.freeze(['www.teach.ustc.edu.cn', 'teach.ustc.edu.cn'])
|
|
145
|
+
}),
|
|
146
|
+
'teach-info': Object.freeze({
|
|
147
|
+
id: 'teach-info',
|
|
148
|
+
label: '教务处信息通知',
|
|
149
|
+
kind: 'notice',
|
|
150
|
+
category: 'academic',
|
|
151
|
+
parser: 'list',
|
|
152
|
+
url: 'https://www.teach.ustc.edu.cn/category/notice/notice-info',
|
|
153
|
+
origin: 'https://www.teach.ustc.edu.cn/',
|
|
154
|
+
hosts: Object.freeze(['www.teach.ustc.edu.cn', 'teach.ustc.edu.cn'])
|
|
155
|
+
}),
|
|
156
|
+
'stuhome-notice': Object.freeze({
|
|
157
|
+
id: 'stuhome-notice',
|
|
158
|
+
label: '学工部最新通知',
|
|
159
|
+
kind: 'notice',
|
|
160
|
+
category: 'student',
|
|
161
|
+
parser: 'list',
|
|
162
|
+
url: 'https://stuhome.ustc.edu.cn/2316/list.htm',
|
|
163
|
+
origin: 'https://stuhome.ustc.edu.cn/',
|
|
164
|
+
hosts: Object.freeze(['stuhome.ustc.edu.cn'])
|
|
165
|
+
}),
|
|
166
|
+
'youth-news': Object.freeze({
|
|
167
|
+
id: 'youth-news',
|
|
168
|
+
label: '校团委校园要闻',
|
|
169
|
+
kind: 'news',
|
|
170
|
+
category: 'activity',
|
|
171
|
+
parser: 'list',
|
|
172
|
+
url: 'https://young.ustc.edu.cn/15062/list.htm',
|
|
173
|
+
origin: 'https://young.ustc.edu.cn/',
|
|
174
|
+
hosts: Object.freeze(['young.ustc.edu.cn'])
|
|
175
|
+
}),
|
|
176
|
+
ustcnet: Object.freeze({
|
|
177
|
+
id: 'ustcnet',
|
|
178
|
+
label: '网络信息中心公告',
|
|
179
|
+
kind: 'notice',
|
|
180
|
+
category: 'service',
|
|
181
|
+
parser: 'list',
|
|
182
|
+
url: 'https://ustcnet.ustc.edu.cn/33415/list.htm',
|
|
183
|
+
origin: 'https://ustcnet.ustc.edu.cn/',
|
|
184
|
+
hosts: Object.freeze(['ustcnet.ustc.edu.cn'])
|
|
185
|
+
}),
|
|
186
|
+
bwc: Object.freeze({
|
|
187
|
+
id: 'bwc',
|
|
188
|
+
label: '保卫与校园管理处公告',
|
|
189
|
+
kind: 'notice',
|
|
190
|
+
category: 'service',
|
|
191
|
+
parser: 'list',
|
|
192
|
+
url: 'https://bwc.ustc.edu.cn/5668/list.htm',
|
|
193
|
+
origin: 'https://bwc.ustc.edu.cn/',
|
|
194
|
+
hosts: Object.freeze(['bwc.ustc.edu.cn'])
|
|
195
|
+
}),
|
|
196
|
+
hospital: Object.freeze({
|
|
197
|
+
id: 'hospital',
|
|
198
|
+
label: '校医院信息公告',
|
|
199
|
+
kind: 'notice',
|
|
200
|
+
category: 'service',
|
|
201
|
+
parser: 'list',
|
|
202
|
+
url: 'https://hospital.ustc.edu.cn/xxgg/list.htm',
|
|
203
|
+
origin: 'https://hospital.ustc.edu.cn/',
|
|
204
|
+
hosts: Object.freeze(['hospital.ustc.edu.cn'])
|
|
205
|
+
}),
|
|
206
|
+
finance: Object.freeze({
|
|
207
|
+
id: 'finance',
|
|
208
|
+
label: '财务处通知公告',
|
|
209
|
+
kind: 'notice',
|
|
210
|
+
category: 'service',
|
|
211
|
+
parser: 'list',
|
|
212
|
+
url: 'https://finance.ustc.edu.cn/tzgg/list.htm',
|
|
213
|
+
origin: 'https://finance.ustc.edu.cn/',
|
|
214
|
+
hosts: Object.freeze(['finance.ustc.edu.cn'])
|
|
215
|
+
}),
|
|
216
|
+
oic: Object.freeze({
|
|
217
|
+
id: 'oic',
|
|
218
|
+
label: '国际合作与交流部通知',
|
|
219
|
+
kind: 'notice',
|
|
220
|
+
category: 'exchange',
|
|
221
|
+
parser: 'list',
|
|
222
|
+
url: 'https://oic.ustc.edu.cn/news-category/information/',
|
|
223
|
+
origin: 'https://oic.ustc.edu.cn/',
|
|
224
|
+
hosts: Object.freeze(['oic.ustc.edu.cn'])
|
|
225
|
+
}),
|
|
226
|
+
'lug-news': Object.freeze({
|
|
227
|
+
id: 'lug-news',
|
|
228
|
+
label: 'USTC LUG 新闻与预告',
|
|
229
|
+
kind: 'news',
|
|
230
|
+
category: 'tech',
|
|
231
|
+
parser: 'list',
|
|
232
|
+
url: 'https://lug.ustc.edu.cn/news/',
|
|
233
|
+
origin: 'https://lug.ustc.edu.cn/',
|
|
234
|
+
hosts: Object.freeze(['lug.ustc.edu.cn'])
|
|
235
|
+
}),
|
|
236
|
+
sgy: Object.freeze({
|
|
237
|
+
id: 'sgy',
|
|
238
|
+
label: '少年班学院通知公告',
|
|
239
|
+
kind: 'notice',
|
|
240
|
+
category: 'college',
|
|
241
|
+
collegeTags: Object.freeze(['少院', '少年班']),
|
|
242
|
+
parser: 'sgy',
|
|
243
|
+
url: 'https://sgy.ustc.edu.cn/37821/list.htm',
|
|
244
|
+
origin: 'https://sgy.ustc.edu.cn/',
|
|
245
|
+
hosts: Object.freeze(['sgy.ustc.edu.cn'])
|
|
246
|
+
}),
|
|
247
|
+
saids: Object.freeze({
|
|
248
|
+
id: 'saids',
|
|
249
|
+
label: '人工智能与数据科学学院公告',
|
|
250
|
+
kind: 'notice',
|
|
251
|
+
category: 'college',
|
|
252
|
+
collegeTags: Object.freeze(['人工智能', '数据科学', 'AI', '机器学习', '深度学习']),
|
|
253
|
+
parser: 'list',
|
|
254
|
+
url: 'https://saids.ustc.edu.cn/15435/list.htm',
|
|
255
|
+
origin: 'https://saids.ustc.edu.cn/',
|
|
256
|
+
hosts: Object.freeze(['saids.ustc.edu.cn'])
|
|
257
|
+
}),
|
|
258
|
+
cybersec: Object.freeze({
|
|
259
|
+
id: 'cybersec',
|
|
260
|
+
label: '网络空间安全学院公告',
|
|
261
|
+
kind: 'notice',
|
|
262
|
+
category: 'college',
|
|
263
|
+
collegeTags: Object.freeze(['网安', '网络安全', '信息安全', '密码']),
|
|
264
|
+
parser: 'list',
|
|
265
|
+
url: 'https://cybersec.ustc.edu.cn/tzgg_23826/list.htm',
|
|
266
|
+
origin: 'https://cybersec.ustc.edu.cn/',
|
|
267
|
+
hosts: Object.freeze(['cybersec.ustc.edu.cn'])
|
|
268
|
+
}),
|
|
269
|
+
'cs-dynamic': Object.freeze({
|
|
270
|
+
id: 'cs-dynamic',
|
|
271
|
+
label: '计算机学院动态公告',
|
|
272
|
+
kind: 'notice',
|
|
273
|
+
category: 'college',
|
|
274
|
+
collegeTags: Object.freeze(['计算机', '软件', '系统', '算法', '编译', '操作系统']),
|
|
275
|
+
parser: 'list',
|
|
276
|
+
url: 'https://cs.ustc.edu.cn/20159/list.htm',
|
|
277
|
+
origin: 'https://cs.ustc.edu.cn/',
|
|
278
|
+
hosts: Object.freeze(['cs.ustc.edu.cn'])
|
|
279
|
+
}),
|
|
280
|
+
sist: Object.freeze({
|
|
281
|
+
id: 'sist',
|
|
282
|
+
label: '信息科学技术学院通知公告',
|
|
283
|
+
kind: 'notice',
|
|
284
|
+
category: 'college',
|
|
285
|
+
collegeTags: Object.freeze(['信息', '电子', '通信', '信号', '自动化', '电路', '微电子']),
|
|
286
|
+
parser: 'list',
|
|
287
|
+
url: 'https://sist.ustc.edu.cn/5142/list.htm',
|
|
288
|
+
origin: 'https://sist.ustc.edu.cn/',
|
|
289
|
+
hosts: Object.freeze(['sist.ustc.edu.cn'])
|
|
99
290
|
})
|
|
100
291
|
});
|
|
101
292
|
|
|
293
|
+
const TEACH_SELECTORS = Object.freeze({
|
|
294
|
+
rows: 'ul.article-list > li',
|
|
295
|
+
link: 'span.post a[href]',
|
|
296
|
+
title: 'span.post a',
|
|
297
|
+
date: 'span.date'
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const STUHOME_SELECTORS = Object.freeze({
|
|
301
|
+
rows: 'ul.news_list > li',
|
|
302
|
+
link: 'span.news_title a[href]',
|
|
303
|
+
title: 'span.news_title a',
|
|
304
|
+
date: 'span.news_meta'
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const YOUTH_SELECTORS = Object.freeze({
|
|
308
|
+
rows: 'ul.text-ul > li',
|
|
309
|
+
link: 'a[href][title]',
|
|
310
|
+
title: 'a[href][title]',
|
|
311
|
+
date: 'i'
|
|
312
|
+
});
|
|
313
|
+
|
|
102
314
|
/** Explicit DOM selectors for the shared list parser. */
|
|
103
315
|
const SOURCE_SELECTORS = Object.freeze({
|
|
104
|
-
teach:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}),
|
|
116
|
-
stuhome: Object.freeze({
|
|
117
|
-
rows: 'ul.news_list > li',
|
|
118
|
-
link: 'span.news_title a[href]',
|
|
119
|
-
title: 'span.news_title a',
|
|
120
|
-
date: 'span.news_meta'
|
|
121
|
-
}),
|
|
122
|
-
youth: Object.freeze({
|
|
123
|
-
rows: 'ul.text-ul > li',
|
|
124
|
-
link: 'a[href][title]',
|
|
125
|
-
title: 'a[href][title]',
|
|
126
|
-
date: 'i'
|
|
127
|
-
}),
|
|
316
|
+
teach: TEACH_SELECTORS,
|
|
317
|
+
'teach-exam': TEACH_SELECTORS,
|
|
318
|
+
'teach-exchange': TEACH_SELECTORS,
|
|
319
|
+
'teach-info': TEACH_SELECTORS,
|
|
320
|
+
stuhome: STUHOME_SELECTORS,
|
|
321
|
+
'stuhome-notice': STUHOME_SELECTORS,
|
|
322
|
+
ustcnet: STUHOME_SELECTORS,
|
|
323
|
+
finance: STUHOME_SELECTORS,
|
|
324
|
+
'cs-dynamic': STUHOME_SELECTORS,
|
|
325
|
+
youth: YOUTH_SELECTORS,
|
|
326
|
+
'youth-news': YOUTH_SELECTORS,
|
|
128
327
|
library: Object.freeze({
|
|
129
328
|
rows: 'ul.lists > li',
|
|
130
329
|
link: 'a.item[href]',
|
|
@@ -136,6 +335,50 @@ const SOURCE_SELECTORS = Object.freeze({
|
|
|
136
335
|
link: 'a.item[href]',
|
|
137
336
|
title: 'p',
|
|
138
337
|
date: 'span.date'
|
|
338
|
+
}),
|
|
339
|
+
bwc: Object.freeze({
|
|
340
|
+
rows: 'div.jzlb',
|
|
341
|
+
link: 'a[href]',
|
|
342
|
+
title: 'a[href]',
|
|
343
|
+
date: 'div.sj, span, .time'
|
|
344
|
+
}),
|
|
345
|
+
hospital: Object.freeze({
|
|
346
|
+
rows: 'ul.list > li',
|
|
347
|
+
link: 'a[href]',
|
|
348
|
+
title: 'a[href]',
|
|
349
|
+
date: 'span, .time, .date'
|
|
350
|
+
}),
|
|
351
|
+
oic: Object.freeze({
|
|
352
|
+
rows: 'article',
|
|
353
|
+
link: 'a[href]',
|
|
354
|
+
title: 'h2, h3, a[href]',
|
|
355
|
+
date: 'time, .date, .meta',
|
|
356
|
+
preferTitleNode: true
|
|
357
|
+
}),
|
|
358
|
+
'lug-news': Object.freeze({
|
|
359
|
+
rows: 'article.archive__item',
|
|
360
|
+
link: 'h2 a[href]',
|
|
361
|
+
title: 'h2 a',
|
|
362
|
+
date: 'time, p.page__meta'
|
|
363
|
+
}),
|
|
364
|
+
saids: Object.freeze({
|
|
365
|
+
rows: 'ul.wp_article_list > li',
|
|
366
|
+
link: 'a[href]',
|
|
367
|
+
title: 'a[href]',
|
|
368
|
+
date: 'span.Article_PublishDate, span.news_meta'
|
|
369
|
+
}),
|
|
370
|
+
cybersec: Object.freeze({
|
|
371
|
+
rows: 'li.cle',
|
|
372
|
+
link: 'a[href]',
|
|
373
|
+
title: 'div.text',
|
|
374
|
+
date: 'div.time',
|
|
375
|
+
preferTitleNode: true
|
|
376
|
+
}),
|
|
377
|
+
sist: Object.freeze({
|
|
378
|
+
rows: 'div.card',
|
|
379
|
+
link: 'h5 a[href]',
|
|
380
|
+
title: 'h5 a[href]',
|
|
381
|
+
date: '.card-footer, .text-muted, small, span'
|
|
139
382
|
})
|
|
140
383
|
});
|
|
141
384
|
|
|
@@ -406,7 +649,7 @@ function loadCache(read) {
|
|
|
406
649
|
return cache;
|
|
407
650
|
}
|
|
408
651
|
|
|
409
|
-
function parseNewsHtml(html) {
|
|
652
|
+
function parseNewsHtml(html, source = FEED_SOURCES.news) {
|
|
410
653
|
const $ = load(String(html ?? ''));
|
|
411
654
|
let rows = $('ul.info-list').first().children('li').toArray();
|
|
412
655
|
if (rows.length === 0) rows = $('ul.info-list li').toArray();
|
|
@@ -423,18 +666,18 @@ function parseNewsHtml(html) {
|
|
|
423
666
|
if (!title) continue;
|
|
424
667
|
|
|
425
668
|
const href = String(link.attr('href') ?? '').trim();
|
|
426
|
-
const url = href.startsWith('#') ? null : sourceItemUrl(href,
|
|
669
|
+
const url = href.startsWith('#') ? null : sourceItemUrl(href, source);
|
|
427
670
|
const rawDate = element.find('.date').first().text();
|
|
428
671
|
const dateInfo = datePartsFromText(rawDate);
|
|
429
672
|
const date = dateInfo?.date ?? (sanitizeText(rawDate, 40) || null);
|
|
430
673
|
|
|
431
|
-
const id = makeItemId(
|
|
674
|
+
const id = makeItemId(source.id, url, `${date ?? ''}|${title}`);
|
|
432
675
|
if (seen.has(id)) continue;
|
|
433
676
|
seen.add(id);
|
|
434
677
|
|
|
435
678
|
items.push({
|
|
436
679
|
id,
|
|
437
|
-
source:
|
|
680
|
+
source: source.id,
|
|
438
681
|
title,
|
|
439
682
|
url,
|
|
440
683
|
date,
|
|
@@ -545,14 +788,78 @@ function parseNoticeList(html, source, nowMs) {
|
|
|
545
788
|
if (link.length === 0) continue;
|
|
546
789
|
|
|
547
790
|
const titleNode = selectors.title ? element.find(selectors.title).first() : link;
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
);
|
|
791
|
+
const primaryTitle = selectors.preferTitleNode
|
|
792
|
+
? (titleNode.attr('title') || titleNode.text() || link.attr('title') || link.text())
|
|
793
|
+
: (link.attr('title') || titleNode.text() || link.text());
|
|
794
|
+
const title = sanitizeText(primaryTitle, 500);
|
|
552
795
|
if (!title) continue;
|
|
553
796
|
|
|
554
|
-
|
|
555
|
-
const
|
|
797
|
+
let dateInfo = null;
|
|
798
|
+
for (const dateEl of element.find(selectors.date).toArray()) {
|
|
799
|
+
const dateRaw = sanitizeText($(dateEl).text(), 80);
|
|
800
|
+
dateInfo = datePartsFromText(dateRaw) ?? monthDayDate(dateRaw, nowMs);
|
|
801
|
+
if (dateInfo) break;
|
|
802
|
+
}
|
|
803
|
+
if (!dateInfo) {
|
|
804
|
+
const fallbackRaw = sanitizeText(element.text(), 240);
|
|
805
|
+
dateInfo = datePartsFromText(fallbackRaw);
|
|
806
|
+
}
|
|
807
|
+
if (!dateInfo) continue;
|
|
808
|
+
|
|
809
|
+
const href = String(link.attr('href') ?? '').trim();
|
|
810
|
+
const url = href && !href.startsWith('#') ? sourceItemUrl(href, source) : null;
|
|
811
|
+
|
|
812
|
+
const id = makeItemId(source.id, url, `${dateInfo.date}|${title}`);
|
|
813
|
+
if (seen.has(id)) continue;
|
|
814
|
+
seen.add(id);
|
|
815
|
+
|
|
816
|
+
items.push({
|
|
817
|
+
id,
|
|
818
|
+
source: source.id,
|
|
819
|
+
title,
|
|
820
|
+
url,
|
|
821
|
+
date: dateInfo.date,
|
|
822
|
+
time: null,
|
|
823
|
+
location: null,
|
|
824
|
+
start: null,
|
|
825
|
+
end: null,
|
|
826
|
+
secondClassroom: false,
|
|
827
|
+
reason: '',
|
|
828
|
+
past: false
|
|
829
|
+
});
|
|
830
|
+
if (items.length >= MAX_ITEMS_PER_SOURCE) break;
|
|
831
|
+
}
|
|
832
|
+
return items;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
function parseSgyNoticeHtml(html, source) {
|
|
836
|
+
const $ = load(String(html ?? ''));
|
|
837
|
+
const rows = $('ul.notice_list > li').toArray();
|
|
838
|
+
const items = [];
|
|
839
|
+
const seen = new Set();
|
|
840
|
+
|
|
841
|
+
for (const row of rows) {
|
|
842
|
+
const element = $(row);
|
|
843
|
+
const link = element.find('a[href]').first();
|
|
844
|
+
if (link.length === 0) continue;
|
|
845
|
+
|
|
846
|
+
const titleNode = element.find('h2.ellipsis3, h2, .notice_list_font').first();
|
|
847
|
+
const title = sanitizeText(link.attr('title') || titleNode.text() || link.text(), 500);
|
|
848
|
+
if (!title) continue;
|
|
849
|
+
|
|
850
|
+
const dateParts = element
|
|
851
|
+
.find('div.notice_list_date p')
|
|
852
|
+
.toArray()
|
|
853
|
+
.map((node) => sanitizeText($(node).text(), 30))
|
|
854
|
+
.filter(Boolean);
|
|
855
|
+
let dateInfo = null;
|
|
856
|
+
if (dateParts.length >= 2) {
|
|
857
|
+
const combined = `${dateParts[1]}/${dateParts[0]}`;
|
|
858
|
+
dateInfo = datePartsFromText(combined);
|
|
859
|
+
}
|
|
860
|
+
if (!dateInfo) {
|
|
861
|
+
dateInfo = datePartsFromText(sanitizeText(element.text(), 120));
|
|
862
|
+
}
|
|
556
863
|
if (!dateInfo) continue;
|
|
557
864
|
|
|
558
865
|
const href = String(link.attr('href') ?? '').trim();
|
|
@@ -736,11 +1043,13 @@ async function parseLibraryLectures(html, source, nowMs, context) {
|
|
|
736
1043
|
async function parseSourceHtml(html, source, nowMs, context) {
|
|
737
1044
|
switch (source.parser) {
|
|
738
1045
|
case 'news':
|
|
739
|
-
return parseNewsHtml(html);
|
|
1046
|
+
return parseNewsHtml(html, source);
|
|
740
1047
|
case 'lug':
|
|
741
1048
|
return parseLugHtml(html);
|
|
742
1049
|
case 'ustc-notice':
|
|
743
1050
|
return parseUstcNotices(html, source, nowMs);
|
|
1051
|
+
case 'sgy':
|
|
1052
|
+
return parseSgyNoticeHtml(html, source);
|
|
744
1053
|
case 'list':
|
|
745
1054
|
return parseNoticeList(html, source, nowMs);
|
|
746
1055
|
case 'library-lecture':
|
|
@@ -750,17 +1059,25 @@ async function parseSourceHtml(html, source, nowMs, context) {
|
|
|
750
1059
|
}
|
|
751
1060
|
}
|
|
752
1061
|
|
|
753
|
-
function normalizeSourceFilter(source) {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
.
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
1062
|
+
function normalizeSourceFilter(source, category) {
|
|
1063
|
+
let ids;
|
|
1064
|
+
if (source == null || source === '' || source === 'all') {
|
|
1065
|
+
ids = [...SOURCE_IDS];
|
|
1066
|
+
} else {
|
|
1067
|
+
const values = (Array.isArray(source) ? source : [source])
|
|
1068
|
+
.flatMap((value) => String(value).split(','))
|
|
1069
|
+
.map((value) => value.trim().toLowerCase())
|
|
1070
|
+
.filter(Boolean);
|
|
1071
|
+
ids = SOURCE_IDS.filter((id) => values.includes(id));
|
|
762
1072
|
}
|
|
763
|
-
|
|
1073
|
+
if (category != null && category !== '' && category !== 'all') {
|
|
1074
|
+
const cats = (Array.isArray(category) ? category : [category])
|
|
1075
|
+
.flatMap((v) => String(v).split(','))
|
|
1076
|
+
.map((v) => v.trim().toLowerCase())
|
|
1077
|
+
.filter(Boolean);
|
|
1078
|
+
ids = ids.filter((id) => cats.includes(FEED_SOURCES[id].category));
|
|
1079
|
+
}
|
|
1080
|
+
return ids;
|
|
764
1081
|
}
|
|
765
1082
|
|
|
766
1083
|
function normalizeInterests(interests) {
|
|
@@ -855,12 +1172,42 @@ function itemDateEpoch(item) {
|
|
|
855
1172
|
return item.start ?? dayEpoch(item.date);
|
|
856
1173
|
}
|
|
857
1174
|
|
|
858
|
-
|
|
859
|
-
|
|
1175
|
+
const ACTIVITY_CUE_RE = /(?:讲座|学术报告|报告会|论坛|沙龙|宣讲|宣介会|培训|工作坊|研讨会|大赛|竞赛|挑战杯|比武|比赛|运动会|音乐会|晚会|演出|放映会|观影|桌游|小聚|招新|招募|夏令营|寒期学校|暑期学校|打卡|马拉松|体验课|开放日|征集)/;
|
|
1176
|
+
const POST_SUMMARY_RE = /(?:圆满举办|顺利召开|取得佳绩|获奖名单|总结|回顾|初评结果|拟推荐|名单公示|公示$)/;
|
|
1177
|
+
const REG_CUE_RE = /(?:报名|申报|预约|招募|征集|参赛|抢票)/;
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* Separate actionable activities (events, second-classroom activities, lectures,
|
|
1181
|
+
* competitions, club meetups) from general notices and campus news.
|
|
1182
|
+
*/
|
|
1183
|
+
export function classifyItemIntent(item, sourceMeta = null) {
|
|
1184
|
+
const title = typeof item?.title === 'string' ? item.title : '';
|
|
1185
|
+
let intent;
|
|
1186
|
+
if (item?.intent === 'activity' || item?.intent === 'notice') {
|
|
1187
|
+
intent = item.intent;
|
|
1188
|
+
} else if (sourceMeta?.kind === 'event' || item?.source === 'youth-enrolling') {
|
|
1189
|
+
intent = 'activity';
|
|
1190
|
+
} else if (ACTIVITY_CUE_RE.test(title) && !POST_SUMMARY_RE.test(title)) {
|
|
1191
|
+
intent = 'activity';
|
|
1192
|
+
} else {
|
|
1193
|
+
intent = 'notice';
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
const requiresRegistration = item?.requiresRegistration === true
|
|
1197
|
+
|| item?.source === 'youth-enrolling'
|
|
1198
|
+
|| (intent === 'activity' && REG_CUE_RE.test(title));
|
|
1199
|
+
|
|
1200
|
+
return { intent, requiresRegistration };
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
function itemKindOf(item) {
|
|
1204
|
+
if (item?.source && FEED_SOURCES[item.source]) return FEED_SOURCES[item.source].kind;
|
|
1205
|
+
if (item?.intent === 'activity' || item?.start != null) return 'event';
|
|
1206
|
+
return 'news';
|
|
860
1207
|
}
|
|
861
1208
|
|
|
862
1209
|
function computePast(item, nowMs) {
|
|
863
|
-
if (
|
|
1210
|
+
if (itemKindOf(item) !== 'event') return false;
|
|
864
1211
|
if (item.end != null) return item.end < nowMs;
|
|
865
1212
|
if (item.start != null) return item.start < nowMs;
|
|
866
1213
|
const day = dayEpoch(item.date);
|
|
@@ -869,7 +1216,7 @@ function computePast(item, nowMs) {
|
|
|
869
1216
|
}
|
|
870
1217
|
|
|
871
1218
|
function chronologicalRank(item) {
|
|
872
|
-
if (
|
|
1219
|
+
if (itemKindOf(item) !== 'event') {
|
|
873
1220
|
return item.date && dayEpoch(item.date) != null ? 2 : 4;
|
|
874
1221
|
}
|
|
875
1222
|
if (item.start != null) return item.past ? 3 : 0;
|
|
@@ -902,7 +1249,7 @@ function buildReason(item, interests, agenda, coverage, nowMs) {
|
|
|
902
1249
|
const reasons = [];
|
|
903
1250
|
if (hits.length > 0) reasons.push(`兴趣匹配:${hits.slice(0, 3).join('、')}`);
|
|
904
1251
|
|
|
905
|
-
const kind =
|
|
1252
|
+
const kind = itemKindOf(item);
|
|
906
1253
|
if (kind === 'notice') {
|
|
907
1254
|
reasons.push('学校通知');
|
|
908
1255
|
} else if (kind === 'news') {
|
|
@@ -927,61 +1274,35 @@ function buildReason(item, interests, agenda, coverage, nowMs) {
|
|
|
927
1274
|
return reasons.join(';');
|
|
928
1275
|
}
|
|
929
1276
|
|
|
930
|
-
function scoreItem(item, interests, agenda, nowMs) {
|
|
931
|
-
const haystack = `${item.title} ${item.location ?? ''}`.toLowerCase();
|
|
932
|
-
let score = 0;
|
|
933
|
-
for (const term of interests) {
|
|
934
|
-
if (haystack.includes(term.toLowerCase())) score += 30;
|
|
935
|
-
}
|
|
936
1277
|
|
|
937
|
-
|
|
938
|
-
if (item.past) {
|
|
939
|
-
score -= 100;
|
|
940
|
-
} else if (item.start != null) {
|
|
941
|
-
score += 20;
|
|
942
|
-
if (item.start - nowMs <= 7 * 24 * 60 * 60 * 1000) score += 10;
|
|
943
|
-
if (overlapsAgenda(item, agenda)) score -= 50;
|
|
944
|
-
} else {
|
|
945
|
-
score -= 5;
|
|
946
|
-
}
|
|
947
|
-
} else {
|
|
948
|
-
score += 5;
|
|
949
|
-
}
|
|
950
|
-
return score;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
function sortItems(items, sort, interests, agenda, nowMs) {
|
|
954
|
-
if (sort === 'recommend') {
|
|
955
|
-
const withScore = items.map((item) => ({
|
|
956
|
-
item,
|
|
957
|
-
score: scoreItem(item, interests, agenda, nowMs)
|
|
958
|
-
}));
|
|
959
|
-
withScore.sort((a, b) => {
|
|
960
|
-
if (b.score !== a.score) return b.score - a.score;
|
|
961
|
-
return compareChronological(a.item, b.item);
|
|
962
|
-
});
|
|
963
|
-
return withScore.map((entry) => entry.item);
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
return [...items].sort(compareChronological);
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
function publicItem(item, interests, agenda, nowMs, coverage) {
|
|
1278
|
+
function publicItem(item, interests, agenda, nowMs, coverage, sourceMeta = null) {
|
|
970
1279
|
const past = computePast(item, nowMs);
|
|
971
|
-
|
|
1280
|
+
const meta = sourceMeta ?? FEED_SOURCES[item.source] ?? null;
|
|
1281
|
+
const { intent, requiresRegistration } = classifyItemIntent(item, meta);
|
|
1282
|
+
const projected = {
|
|
972
1283
|
id: item.id,
|
|
973
1284
|
source: item.source,
|
|
1285
|
+
category: item.category ?? meta?.category ?? 'campus',
|
|
1286
|
+
intent,
|
|
1287
|
+
requiresRegistration,
|
|
974
1288
|
title: item.title,
|
|
975
1289
|
url: item.url,
|
|
976
|
-
date: item.date,
|
|
977
|
-
time: item.time,
|
|
978
|
-
location: item.location,
|
|
979
|
-
start: item.start,
|
|
980
|
-
end: item.end,
|
|
1290
|
+
date: item.date ?? null,
|
|
1291
|
+
time: item.time ?? null,
|
|
1292
|
+
location: item.location ?? null,
|
|
1293
|
+
start: item.start ?? null,
|
|
1294
|
+
end: item.end ?? null,
|
|
981
1295
|
secondClassroom: item.secondClassroom === true,
|
|
982
1296
|
reason: buildReason({ ...item, past }, interests, agenda, coverage, nowMs),
|
|
983
1297
|
past
|
|
984
1298
|
};
|
|
1299
|
+
if (item.organizer) projected.organizer = item.organizer;
|
|
1300
|
+
if (item.enrollmentRatio) projected.enrollmentRatio = item.enrollmentRatio;
|
|
1301
|
+
if (item.remainingSlots !== undefined && item.remainingSlots !== null) projected.remainingSlots = item.remainingSlots;
|
|
1302
|
+
if (item.hours !== undefined && item.hours !== null) projected.hours = item.hours;
|
|
1303
|
+
if (item.youthItemId) projected.youthItemId = item.youthItemId;
|
|
1304
|
+
if (item.registered !== undefined && item.registered !== null) projected.registered = item.registered;
|
|
1305
|
+
return projected;
|
|
985
1306
|
}
|
|
986
1307
|
|
|
987
1308
|
function memoryStore() {
|
|
@@ -992,13 +1313,15 @@ function memoryStore() {
|
|
|
992
1313
|
};
|
|
993
1314
|
}
|
|
994
1315
|
|
|
1316
|
+
const REFRESH_CONCURRENCY = 6;
|
|
1317
|
+
|
|
1318
|
+
|
|
995
1319
|
/**
|
|
996
1320
|
* createFeed({read, write, fetch, now})
|
|
997
1321
|
*
|
|
998
1322
|
* `read`/`write` are synchronous key/value storage supplied by the host,
|
|
999
|
-
* `fetch` and `now` are injectable for tests.
|
|
1000
|
-
*
|
|
1001
|
-
* background (call `refresh({force:true})` when the caller wants to await it).
|
|
1323
|
+
* `fetch` and `now` are injectable for tests. `query` is strictly local;
|
|
1324
|
+
* callers use `refresh` when they want to check the network.
|
|
1002
1325
|
*/
|
|
1003
1326
|
export function createFeed(options = {}) {
|
|
1004
1327
|
const fallback = memoryStore();
|
|
@@ -1008,12 +1331,15 @@ export function createFeed(options = {}) {
|
|
|
1008
1331
|
const now = typeof options.now === 'function' ? options.now : Date.now;
|
|
1009
1332
|
|
|
1010
1333
|
const cache = loadCache(read);
|
|
1334
|
+
let revision = 0;
|
|
1335
|
+
let fallbackRecommender = null;
|
|
1011
1336
|
let refreshing = null;
|
|
1012
1337
|
let lastAttempt = 0;
|
|
1013
1338
|
let closed = false;
|
|
1014
1339
|
let controller = null;
|
|
1015
1340
|
|
|
1016
1341
|
function writeCache() {
|
|
1342
|
+
revision++;
|
|
1017
1343
|
try {
|
|
1018
1344
|
write(CACHE_KEY, cache);
|
|
1019
1345
|
} catch {
|
|
@@ -1022,13 +1348,17 @@ export function createFeed(options = {}) {
|
|
|
1022
1348
|
}
|
|
1023
1349
|
}
|
|
1024
1350
|
|
|
1025
|
-
function statuses(ids) {
|
|
1026
|
-
return
|
|
1027
|
-
id
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1351
|
+
function statuses(ids, extraSources = []) {
|
|
1352
|
+
return [
|
|
1353
|
+
...ids.map((id) => ({
|
|
1354
|
+
id,
|
|
1355
|
+
label: FEED_SOURCES[id].label,
|
|
1356
|
+
category: FEED_SOURCES[id].category,
|
|
1357
|
+
fetchedAt: cache.sources[id].fetchedAt ?? null,
|
|
1358
|
+
error: cache.sources[id].error ?? null
|
|
1359
|
+
})),
|
|
1360
|
+
...extraSources
|
|
1361
|
+
];
|
|
1032
1362
|
}
|
|
1033
1363
|
|
|
1034
1364
|
function isStale(id) {
|
|
@@ -1053,24 +1383,22 @@ export function createFeed(options = {}) {
|
|
|
1053
1383
|
lastAttempt = refreshNow;
|
|
1054
1384
|
const signal = controller.signal;
|
|
1055
1385
|
|
|
1056
|
-
const results = await
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
})
|
|
1073
|
-
);
|
|
1386
|
+
const results = await mapLimited(SOURCE_IDS, REFRESH_CONCURRENCY, async (id) => {
|
|
1387
|
+
const source = FEED_SOURCES[id];
|
|
1388
|
+
const html = await fetchText(source.url, {
|
|
1389
|
+
fetch: fetchImpl,
|
|
1390
|
+
allowHosts: source.hosts,
|
|
1391
|
+
signal
|
|
1392
|
+
});
|
|
1393
|
+
const items = await parseSourceHtml(html, source, refreshNow, {
|
|
1394
|
+
fetch: fetchImpl,
|
|
1395
|
+
signal
|
|
1396
|
+
});
|
|
1397
|
+
if (items.length === 0) {
|
|
1398
|
+
throw new Error('页面中没有解析到条目');
|
|
1399
|
+
}
|
|
1400
|
+
return { id, items };
|
|
1401
|
+
});
|
|
1074
1402
|
|
|
1075
1403
|
if (closed) {
|
|
1076
1404
|
return { sources: statuses(SOURCE_IDS), fetchedAt: latestFetchedAt(SOURCE_IDS) };
|
|
@@ -1145,19 +1473,31 @@ export function createFeed(options = {}) {
|
|
|
1145
1473
|
return refreshing;
|
|
1146
1474
|
}
|
|
1147
1475
|
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1476
|
+
|
|
1477
|
+
function getItemById(id) {
|
|
1478
|
+
for (const srcId of SOURCE_IDS) {
|
|
1479
|
+
const found = cache.sources[srcId].items.find((entry) => entry.id === id);
|
|
1480
|
+
if (found) return found;
|
|
1481
|
+
}
|
|
1482
|
+
return null;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
function filterTokens(raw) {
|
|
1486
|
+
if (raw == null || raw === '' || raw === 'all') return null;
|
|
1487
|
+
return (Array.isArray(raw) ? raw : [raw])
|
|
1488
|
+
.flatMap((v) => String(v).split(','))
|
|
1489
|
+
.map((v) => v.trim().toLowerCase())
|
|
1490
|
+
.filter(Boolean);
|
|
1155
1491
|
}
|
|
1156
1492
|
|
|
1157
1493
|
function query(queryOptions = {}) {
|
|
1158
|
-
const selectedIds = normalizeSourceFilter(queryOptions?.source);
|
|
1159
|
-
maybeAutoRefresh(selectedIds);
|
|
1494
|
+
const selectedIds = normalizeSourceFilter(queryOptions?.source, queryOptions?.category);
|
|
1160
1495
|
|
|
1496
|
+
const sourceTokens = filterTokens(queryOptions?.source);
|
|
1497
|
+
const categoryTokens = filterTokens(queryOptions?.category);
|
|
1498
|
+
const intentFilter = queryOptions?.intent === 'activity' || queryOptions?.intent === 'notice'
|
|
1499
|
+
? queryOptions.intent
|
|
1500
|
+
: null;
|
|
1161
1501
|
const keyword = sanitizeText(String(queryOptions?.keyword ?? ''), 120).toLowerCase();
|
|
1162
1502
|
const interests = normalizeInterests(queryOptions?.interests);
|
|
1163
1503
|
const agenda = normalizeAgenda(queryOptions?.agenda);
|
|
@@ -1168,24 +1508,72 @@ export function createFeed(options = {}) {
|
|
|
1168
1508
|
: 'time';
|
|
1169
1509
|
const nowMs = now();
|
|
1170
1510
|
|
|
1511
|
+
const extraSourceMap = new Map();
|
|
1512
|
+
const matchedExtraSources = [];
|
|
1513
|
+
for (const src of Array.isArray(queryOptions?.extraSources) ? queryOptions.extraSources : []) {
|
|
1514
|
+
if (!src || typeof src !== 'object' || !src.id) continue;
|
|
1515
|
+
extraSourceMap.set(src.id, src);
|
|
1516
|
+
const srcOk = !sourceTokens || sourceTokens.includes(String(src.id).toLowerCase());
|
|
1517
|
+
const catOk = !categoryTokens || categoryTokens.includes(String(src.category ?? 'campus').toLowerCase());
|
|
1518
|
+
if (srcOk && catOk) matchedExtraSources.push(src);
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1171
1521
|
let items = [];
|
|
1172
1522
|
for (const id of selectedIds) {
|
|
1173
1523
|
items.push(...cache.sources[id].items);
|
|
1174
1524
|
}
|
|
1525
|
+
for (const extra of Array.isArray(queryOptions?.extraItems) ? queryOptions.extraItems : []) {
|
|
1526
|
+
if (!extra || typeof extra !== 'object' || !extra.id || !extra.title) continue;
|
|
1527
|
+
const sid = String(extra.source ?? '').toLowerCase();
|
|
1528
|
+
const cat = String(extra.category ?? extraSourceMap.get(extra.source)?.category ?? 'activity').toLowerCase();
|
|
1529
|
+
if (sourceTokens && !sourceTokens.includes(sid)) continue;
|
|
1530
|
+
if (categoryTokens && !categoryTokens.includes(cat)) continue;
|
|
1531
|
+
items.push(extra);
|
|
1532
|
+
}
|
|
1533
|
+
const seenIds = new Set();
|
|
1534
|
+
items = items.filter(item => !seenIds.has(item.id) && seenIds.add(item.id));
|
|
1175
1535
|
|
|
1176
1536
|
if (keyword) {
|
|
1177
1537
|
items = items.filter((item) => {
|
|
1178
|
-
const haystack = `${item.title} ${item.location ?? ''} ${item.date ?? ''}`.toLowerCase();
|
|
1538
|
+
const haystack = `${item.title} ${item.location ?? ''} ${item.organizer ?? ''} ${item.date ?? ''}`.toLowerCase();
|
|
1179
1539
|
return haystack.includes(keyword);
|
|
1180
1540
|
});
|
|
1181
1541
|
}
|
|
1182
1542
|
|
|
1183
|
-
|
|
1184
|
-
|
|
1543
|
+
let projected = items.map((item) => publicItem(item, interests, agenda, nowMs, coverage, extraSourceMap.get(item.source) ?? null));
|
|
1544
|
+
if (intentFilter) {
|
|
1545
|
+
projected = projected.filter((item) => item.intent === intentFilter);
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
let sorted;
|
|
1549
|
+
if (sort === 'recommend') {
|
|
1550
|
+
if (!queryOptions?.recommender && !fallbackRecommender) {
|
|
1551
|
+
fallbackRecommender = createRecommender({ now });
|
|
1552
|
+
}
|
|
1553
|
+
const recommender = queryOptions?.recommender ?? fallbackRecommender;
|
|
1554
|
+
const explicitSourceFilter = Boolean(queryOptions?.source && queryOptions.source !== 'all');
|
|
1555
|
+
const explicitKeywordFilter = Boolean(keyword);
|
|
1556
|
+
sorted = recommender.rank(projected, {
|
|
1557
|
+
nowMs,
|
|
1558
|
+
interests,
|
|
1559
|
+
userContext: queryOptions?.userContext,
|
|
1560
|
+
explicitSourceFilter,
|
|
1561
|
+
explicitKeywordFilter,
|
|
1562
|
+
dedupe: queryOptions?.dedupe !== false,
|
|
1563
|
+
getSourceMeta: (id) => FEED_SOURCES[id] ?? extraSourceMap.get(id) ?? null,
|
|
1564
|
+
agendaInfo: {
|
|
1565
|
+
hasAgenda: agenda.length > 0,
|
|
1566
|
+
overlaps: (item) => overlapsAgenda(item, agenda),
|
|
1567
|
+
covered: (item) => coverageCovers(occupiedInterval(item.start, item.end), coverage)
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
} else {
|
|
1571
|
+
sorted = projected.sort(compareChronological);
|
|
1572
|
+
}
|
|
1185
1573
|
|
|
1186
1574
|
return {
|
|
1187
1575
|
items: sorted,
|
|
1188
|
-
sources: statuses(selectedIds)
|
|
1576
|
+
sources: statuses(selectedIds, matchedExtraSources)
|
|
1189
1577
|
};
|
|
1190
1578
|
}
|
|
1191
1579
|
|
|
@@ -1200,5 +1588,5 @@ export function createFeed(options = {}) {
|
|
|
1200
1588
|
refreshing = null;
|
|
1201
1589
|
}
|
|
1202
1590
|
|
|
1203
|
-
return { query, refresh, close };
|
|
1591
|
+
return { query, refresh, close, getItemById, revision: () => revision };
|
|
1204
1592
|
}
|