rsshub
Version:
Make RSS Great Again!
84 lines (82 loc) • 2.77 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs";
import { load } from "cheerio";
//#region lib/routes/uestc/gr.ts
const baseUrl = "https://gr.uestc.edu.cn/";
const detailUrl = "https://gr.uestc.edu.cn/";
const dateTimeRegex = /(\d{4}-\d{2}-\d{2} \d{2}:\d{2})/;
const typeUrlMap = {
important: "tongzhi/",
teaching: "tongzhi/119",
degree: "tongzhi/129",
student: "tongzhi/122",
practice: "tongzhi/123"
};
const typeNameMap = {
important: "重要公告",
teaching: "教学管理",
degree: "学位管理",
student: "学生管理",
practice: "就业实践"
};
const route = {
path: "/gr/:type?",
categories: ["university"],
example: "/uestc/gr/student",
parameters: { type: "默认为 `important`" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["gr.uestc.edu.cn/"] }],
name: "研究生院",
maintainers: ["huyyi", "mobyw"],
handler,
url: "gr.uestc.edu.cn/",
description: `\
| 重要公告 | 教学管理 | 学位管理 | 学生管理 | 就业实践 |
| --------- | -------- | -------- | -------- | -------- |
| important | teaching | degree | student | practice |`
};
async function handler(ctx) {
const type = ctx.req.param("type") || "important";
if (type in typeUrlMap === false) throw new invalid_parameter_default("type not supported");
const typeName = typeNameMap[type];
const $ = load(await ofetch_default(baseUrl + typeUrlMap[type]));
const items = $("div.title").toArray().map(async (entry) => {
const element = $(entry);
const newsTitle = element.find("a").text() ?? "";
const newsLink = detailUrl + element.find("a").attr("href");
return await cache_default.tryGet(newsLink, async () => {
const content = load(await ofetch_default(newsLink));
const basicInfo = content("div.topic_detail_header").find("div.info").text();
const match = dateTimeRegex.exec(basicInfo);
return {
title: newsTitle,
link: newsLink,
pubDate: match ? timezone(parseDate(match[1]), 8) : null,
description: content("div.content").html()
};
});
});
const out = await Promise.all(items);
return {
title: `研究生院通知(${typeName})`,
link: baseUrl,
description: `电子科技大学研究生院通知(${typeName})`,
item: out
};
}
//#endregion
export { route };