Skip to content

Commit 117752b

Browse files
feat(route/tsinghua): 图书馆通知公告 (#22927)
* feat(tsinghua): 图书馆通知公告 * fix(tsinghua): address review comments * style(tsinghua): sort imports
1 parent ff4256a commit 117752b

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

lib/routes/tsinghua/lib/notice.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { load } from 'cheerio';
2+
3+
import type { DataItem, Route } from '@/types';
4+
import cache from '@/utils/cache';
5+
import ofetch from '@/utils/ofetch';
6+
import { parseDate } from '@/utils/parse-date';
7+
8+
export const route: Route = {
9+
path: '/lib/notice',
10+
categories: ['university'],
11+
example: '/tsinghua/lib/notice',
12+
parameters: {},
13+
features: {
14+
requireConfig: false,
15+
requirePuppeteer: false,
16+
antiCrawler: false,
17+
supportBT: false,
18+
supportPodcast: false,
19+
supportScihub: false,
20+
},
21+
radar: [
22+
{
23+
source: ['lib.tsinghua.edu.cn/tzgg.htm'],
24+
},
25+
],
26+
name: '图书馆通知公告',
27+
maintainers: ['Aquarius-Situla'],
28+
handler: async () => {
29+
const baseUrl = 'https://lib.tsinghua.edu.cn';
30+
const link = `${baseUrl}/tzgg.htm`;
31+
32+
const response = await ofetch(link);
33+
const $ = load(response);
34+
35+
// Extract list page items
36+
let items: DataItem[] = $('ul.notice-list li')
37+
.toArray()
38+
.filter((item) => $(item).find('.notice-list-tt a').attr('href'))
39+
.map((item) => {
40+
const $item = $(item);
41+
const a = $item.find('.notice-list-tt a');
42+
const title = a.text().trim();
43+
const href = a.attr('href') as string;
44+
const dateStr = $item.find('.notice-date').text().trim();
45+
const category = $item.find('.notice-label').text().trim();
46+
47+
return {
48+
title,
49+
link: new URL(href, link).href,
50+
pubDate: parseDate(dateStr, 'YYYY-MM-DD'),
51+
category,
52+
};
53+
});
54+
55+
// Fetch article body with cache
56+
items = (await Promise.all(
57+
items.map((item) =>
58+
cache.tryGet(item.link as string, async () => {
59+
const itemResponse = await ofetch(item.link as string);
60+
const $$ = load(itemResponse);
61+
item.description = $$('.v_news_content').html() || undefined;
62+
return item as DataItem;
63+
})
64+
)
65+
)) as DataItem[];
66+
67+
return {
68+
title: '清华大学图书馆 - 通知公告',
69+
link,
70+
description: '清华大学图书馆 - 通知公告',
71+
item: items,
72+
};
73+
},
74+
};

0 commit comments

Comments
 (0)