From 69f7d21c68f0d403325fa03e75b1170cc17c6771 Mon Sep 17 00:00:00 2001 From: linsenwang <88711203+linsenwang@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:29:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=9B=BE=E4=B9=A6?= =?UTF-8?q?=E9=A6=86=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A=20(#18128)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add 厦门大学经济学院科研动态 * Apply suggestions from code review Thanks for the feedback! The change has been applied. Co-authored-by: Tony * add 图书馆通知公告 * Update lib/routes/tsinghua/lib/tzgg.ts Co-authored-by: Tony --------- --- lib/routes/tsinghua/lib/tzgg.ts | 73 +++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 lib/routes/tsinghua/lib/tzgg.ts diff --git a/lib/routes/tsinghua/lib/tzgg.ts b/lib/routes/tsinghua/lib/tzgg.ts new file mode 100644 index 000000000..73ff5975f --- /dev/null +++ b/lib/routes/tsinghua/lib/tzgg.ts @@ -0,0 +1,73 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import cache from '@/utils/cache'; + +export const route: Route = { + path: '/lib/tzgg/:category', + categories: ['university'], + example: '/tsinghua/lib/tzgg/qtkx', + parameters: { category: '分类,可在对应分类页 URL 中找到' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['lib.tsinghua.edu.cn/tzgg/:category'], + }, + ], + name: '图书馆通知公告', + maintainers: ['linsenwang'], + handler, +}; + +async function handler(ctx) { + const { category } = ctx.req.param(); + const host = `https://lib.tsinghua.edu.cn/tzgg/${category}.htm`; + const response = await ofetch(host); + const $ = load(response); + + const feedTitle = $('.tags .on').text(); + + const list = $('ul.notice-list li') + .toArray() + .map((item) => { + item = $(item); + const title = item.find('a').first().text(); + const time = item.find('.notice-date').first().text(); + const a = item.find('a').first().attr('href'); + + const fullUrl = new URL(a, host).href; + + return { + title, + link: fullUrl, + pubDate: time, + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = load(response); + + item.description = $('.v_news_content').first().html(); + + return item; + }) + ) + ); + + return { + allowEmpty: true, + title: '图书馆通知公告 - ' + feedTitle, + link: host, + item: items, + }; +}