UNPKG

rsshub

Version:
73 lines (72 loc) 2.26 kB
import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { t as got_default } from "./got-DUpa1V3-.mjs"; import { t as timezone } from "./timezone-UiMFOuvL.mjs"; import { t as InvalidParameterError } from "./invalid-parameter-CGxhjomn.mjs"; import { load } from "cheerio"; //#region lib/routes/ustc/gs.ts const map = /* @__PURE__ */ new Map([["tzgg", { title: "中国科学技术大学研究生院 - 通知公告", id: "9" }], ["xwdt", { title: "中国科学技术大学研究生院 - 新闻动态", id: "10" }]]); const host = "https://gradschool.ustc.edu.cn"; const route = { path: "/gs/:type?", categories: ["university"], example: "/ustc/gs/tzgg", parameters: { type: "分类,见下表,默认为通知公告" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["gradschool.ustc.edu.cn/"], target: "/gs" }], name: "研究生院", maintainers: ["jasongzy"], handler, url: "gradschool.ustc.edu.cn/", description: `| 通知公告 | 新闻动态 | | -------- | -------- | | tzgg | xwdt |` }; async function handler(ctx) { const type = ctx.req.param("type") ?? "tzgg"; const info = map.get(type); if (!info) throw new InvalidParameterError("invalid type"); const id = info.id; const response = await got_default(`${host}/column/${id}`); const $ = load(response.data); let items = $("div.r-box > ul").find("li").toArray().map((item) => { const $item = $(item); const title = $item.find("a").text(); const link = $item.find("a").attr("href").startsWith("/article") ? host + $item.find("a").attr("href") : $item.find("a").attr("href"); return { title, pubDate: timezone(parseDate($item.find("time").text(), "YYYY-MM-DD"), 8), link }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { try { const response = await got_default(item.link); item.description = load(response.data)("article.article").html(); } catch {} return item; }))); return { title: info.title, link: `${host}/column/${id}`, item: items }; } //#endregion export { route };