UNPKG

rsshub

Version:
65 lines (64 loc) 2.32 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; import { load } from "cheerio"; //#region lib/routes/cug/gcxy.ts const route = { path: "/gcxy/:type?", categories: ["university"], example: "/cug/gcxy/xyxw", parameters: { type: "分类,见下表,默认为所有" }, name: "工程学院", maintainers: ["Doradx"], description: `| 学院新闻 | 通知公告 | 党建新闻 | 学术动态 | 本科生培养 | 研究生教育 | | -------- | -------- | -------- | -------- | ---------- | ---------- | | xyxw | tzgg | djxw | xsdt | bkspy | yjsjy |`, handler }; async function handler(ctx) { const host = "https://gcxy.cug.edu.cn"; const typeUrl = { xyxw: "/index/xyxw.htm", tzgg: "/index/tzgg.htm", djxw: "/index/djxw.htm", xsdt: "/kxyj/xsdt.htm", bkspy: "/index/bkspy.htm", yjsjy: "/index/yjsjy.htm" }; const type = ctx.req.param("type"); if (type && !Object.hasOwn(typeUrl, type)) throw new Error("Invalid type"); const selected = type ? [typeUrl[type]] : Object.values(typeUrl); const getItems = async (url) => { const $ = load(await rofetch(host + url)); return { name: $("a.selected").text(), items: await Promise.all($("ul.col-news-list li.list_item").toArray().map((item) => { const $item = $(item); const a = $item.find("a.news-title"); const linkUrl = new URL(a.attr("href"), host + url); const link = linkUrl.href; return cache_default.tryGet(link, async () => { const entry = { title: a.attr("title"), link, pubDate: timezone(parseDate($item.find("span.news-date").text()), 8) }; if (linkUrl.hostname !== "gcxy.cug.edu.cn") return entry; entry.description = load(await rofetch(link))(".v_news_content").html(); return entry; }); })) }; }; const outList = await Promise.all(selected.map((url) => getItems(url))); const name = type ? outList[0].name : "所有"; return { title: `[${name}]CUG-工程学院`, link: host + (type ? typeUrl[type] : ""), description: "中国地质大学(武汉)工程学院-" + name, item: outList.flatMap((o) => o.items) }; } //#endregion export { route };