From 1309c5083eb60913580d1bb1ae84b0bd3b8aeaa3 Mon Sep 17 00:00:00 2001 From: chris zheng Date: Thu, 17 Oct 2024 01:07:51 +0800 Subject: [PATCH] feat(route): add route for graduacted school of CJLU (China Jiliang University) (#17149) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(namespace): add namespace for CJLU * feat(route): Add route for graduate school of CJLU 为中国计量大学研究生院添加路由 支持将`教师通知`和`研究生通知`页面转化为 RSS 订阅源 * doc: modify discription of some params 修改参数描述 * fix(radar rule): modify radar rule 修改 radar 规则,以正确提供订阅源 * fix: add exception handling 增加异常处理 * chore: optimize conditional logic 优化判断逻辑 * Update lib/routes/cjlu/yjsy/index.ts Co-authored-by: Tony * fix(radar rule): list all source choices 在 radar 规则中列出全部的类型 修改行尾符为 LF * fix(example): correct example of the route 订正路由的案例 --------- --- lib/routes/cjlu/namespace.ts | 10 ++++ lib/routes/cjlu/yjsy/index.ts | 107 ++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 lib/routes/cjlu/namespace.ts create mode 100644 lib/routes/cjlu/yjsy/index.ts diff --git a/lib/routes/cjlu/namespace.ts b/lib/routes/cjlu/namespace.ts new file mode 100644 index 000000000..f1763025c --- /dev/null +++ b/lib/routes/cjlu/namespace.ts @@ -0,0 +1,10 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'China Jiliang University', + url: 'www.cjlu.edu.cn', + + zh: { + name: '中国计量大学', + }, +}; diff --git a/lib/routes/cjlu/yjsy/index.ts b/lib/routes/cjlu/yjsy/index.ts new file mode 100644 index 000000000..1785e2dc3 --- /dev/null +++ b/lib/routes/cjlu/yjsy/index.ts @@ -0,0 +1,107 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import cache from '@/utils/cache'; +import timezone from '@/utils/timezone'; + +const host = 'https://yjsy.cjlu.edu.cn/'; + +const titleMap = new Map([ + ['yjstz', '中量大研究生院 —— 研究生通知'], + ['jstz', '中量大研究生院 —— 教师通知'], +]); + +export const route: Route = { + path: '/yjsy/:cate', + categories: ['university'], + example: '/cjlu/yjsy/yjstz', + parameters: { + cate: '订阅的类型,支持 yjstz(研究生通知)和 jstz(教师通知)', + }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + title: '研究生通知', + source: ['yjsy.cjlu.edu.cn/index/yjstz/:suffix', 'yjsy.cjlu.edu.cn/index/yjstz.htm'], + target: '/yjsy/yjstz', + }, + { + title: '教师通知', + source: ['yjsy.cjlu.edu.cn/index/jstz/:suffix', 'yjsy.cjlu.edu.cn/index/jstz.htm'], + target: '/yjsy/jstz', + }, + ], + name: '研究生院', + maintainers: ['chrisis58'], + handler, + description: `| 研究生通知 | 教师通知 | + | -------- | -------- | + | yjstz | jstz |`, +}; + +async function handler(ctx) { + const cate = ctx.req.param('cate'); + + const response = await ofetch(`${cate}.htm`, { + baseURL: `${host}/index/`, + responseType: 'text', + }); + + const $ = load(response); + + const list = $('div.grid685.right div.body ul') + .find('li') + .toArray() + .map((element) => { + const item = $(element); + + const a = item.find('a').first(); + + const timeStr = item.find('span').first().text().trim(); + const href = a.attr('href') ?? ''; + const route = href.startsWith('../') ? href.replace(/^\.\.\//, '') : href; + + return { + title: a.attr('title') ?? titleMap.get(cate), + pubDate: timezone(parseDate(timeStr, 'YYYY/MM/DD'), +8), + link: `${host}${route}`, + description: '', + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + if (!item.link || item.link === host) { + return item; + } + + const res = await ofetch(item.link, { + responseType: 'text', + }); + const $ = load(res); + + const content = $('#vsb_content').html() ?? ''; + const attachments = $('form[name="_newscontent_fromname"] div ul').html() ?? ''; + + item.description = `${content}
${attachments}`; + return item; + }) + ) + ); + + return { + title: titleMap.get(cate), + link: `https://yjsy.cjlu.edu.cn/index/${cate}.htm`, + item: items, + }; +}