UNPKG

rsshub

Version:
52 lines (51 loc) 1.78 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { load } from "cheerio"; //#region lib/routes/pku/eecs.ts const eecsMap = /* @__PURE__ */ new Map([ [0, "tzgg.htm"], [1, "tzgg/xytz.htm"], [2, "tzgg/rstz.htm"], [6, "tzgg/jwtz.htm"], [8, "tzgg/xgtz.htm"], [3, "tzgg/ghtz.htm"], [4, "tzgg/yytz.htm"] ]); const route = { path: "/eecs/:type?", name: "信科公告通知", example: "/pku/eecs/0", maintainers: ["Ir1d"], handler, description: `| 全部 | 学院通知 | 人事通知 | 教务通知 | 学工通知 | 工会通知 | 院友通知 | | ---- | -------- | -------- | -------- | -------- | -------- | -------- | | 0 | 1 | 2 | 6 | 8 | 3 | 4 |` }; async function handler(ctx) { const type = Number.parseInt(ctx.req.param("type")) || 0; const listUrl = "https://eecs.pku.edu.cn/" + (eecsMap.get(type) ?? eecsMap.get(0)); const $ = load((await got_default(listUrl)).data); let items = $("ul.list-text > li > a").toArray().map((item) => { const $item = $(item); return { title: $item.find(".tit").text(), link: new URL($item.attr("href"), listUrl).href, pubDate: parseDate($item.find(".date .mon").text() + "-" + $item.find(".date .day").text()) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default(item.link)).data)(".Section1"); content.find("[style]").removeAttr("style"); item.description = content.html(); return item; }))); return { title: $("title").text(), link: listUrl, description: "北大信科 公告通知", item: items }; } //#endregion export { route };