From 4200769d1affab0e3981d5ef2e3d5ebcfa7c7f3c Mon Sep 17 00:00:00 2001 From: studyinglover <68844494+StudyingLover@users.noreply.github.com> Date: Thu, 26 Mar 2026 18:02:55 +0800 Subject: [PATCH] feat(route/xupt): add XUPT JYC notifications route (#21451) --- lib/routes/xupt/jyc.ts | 69 ++++++++++++++++++++++++++++++++++++ lib/routes/xupt/namespace.ts | 10 ++++++ 2 files changed, 79 insertions(+) create mode 100644 lib/routes/xupt/jyc.ts create mode 100644 lib/routes/xupt/namespace.ts diff --git a/lib/routes/xupt/jyc.ts b/lib/routes/xupt/jyc.ts new file mode 100644 index 000000000..5e1e640cc --- /dev/null +++ b/lib/routes/xupt/jyc.ts @@ -0,0 +1,69 @@ +import { load } from 'cheerio'; + +import type { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; + +export const route: Route = { + path: '/jyc/:type?', + categories: ['university'], + example: '/xupt/jyc', + parameters: { type: '分类,默认为 tzgg(通知公告)' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['jyc.xupt.edu.cn/index/tzgg.htm'], + target: '/jyc/tzgg', + }, + ], + name: '教务处通知公告', + maintainers: ['StudyingLover'], + handler, + description: `| 分类 | 参数 | +| ---- | ---- | +| 通知公告 | tzgg |`, +}; + +async function handler(ctx) { + const type = ctx.req.param('type') || 'tzgg'; + const typeDict = { + tzgg: ['通知公告', 'https://jyc.xupt.edu.cn/index/tzgg.htm'], + }; + + const [typeName, url] = typeDict[type as keyof typeof typeDict] || typeDict.tzgg; + + const response = await ofetch(url); + const $ = load(response); + + const list = $('.ej_list li') + .toArray() + .map((item) => { + const $item = $(item); + const $link = $item.find('a').first(); + + // 处理相对链接,转换为绝对链接 + const linkHref = $link.attr('href') || ''; + const absoluteLink = new URL(linkHref, 'https://jyc.xupt.edu.cn').href; + + // 日期格式:18/03 - 只有月日,无年份 + // 根据规范,网站不提供完整日期时不添加 pubDate + + return { + title: $link.text().trim(), + link: absoluteLink, + }; + }) + .filter((item) => item.title && item.link); + + return { + title: `西安邮电大学教务处 - ${typeName}`, + link: url, + item: list, + }; +} diff --git a/lib/routes/xupt/namespace.ts b/lib/routes/xupt/namespace.ts new file mode 100644 index 000000000..a8c81ba77 --- /dev/null +++ b/lib/routes/xupt/namespace.ts @@ -0,0 +1,10 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '西安邮电大学', + url: 'xupt.edu.cn', + description: '西安邮电大学教务处通知公告', + zh: { + name: '西安邮电大学', + }, +};