UNPKG

rsshub

Version:
98 lines (96 loc) 2.86 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { load } from "cheerio"; //#region lib/routes/njit/jwc.ts const host = "https://jwc.njit.edu.cn"; const route = { path: "/jwc/:type?", categories: ["university"], example: "/njit/jwc/jx", parameters: { type: "默认为 `jx`" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "南京工程学院教务处", maintainers: ["zefengdaguo"], handler, description: `| 教学 | 考试 | 信息 | 实践 | | ---- | ---- | ---- | ---- | | jx | ks | xx | sj |` }; async function handler(ctx) { const type = ctx.req.param("type") ?? "jx"; const link = host + "/index/" + type + ".htm"; const $ = load((await got_default({ method: "get", url: link, https: { rejectUnauthorized: false } })).body); const urlList = $("body").find("ul li span a").map((e) => $(e).attr("href")); const titleList = $("body").find("ul li span a").toArray().map((e) => $(e).attr("title")); const dateList = $("body").find("span.date").toArray().map((e) => $(e).text()); const out = await Promise.all(urlList.map((itemUrl, index) => { itemUrl = new URL(itemUrl, host).href; if (itemUrl.includes(".htm")) return cache_default.tryGet(itemUrl, async () => { const response = await got_default({ method: "get", url: itemUrl, https: { rejectUnauthorized: false } }); if (response.redirectUrls.length !== 0) return { title: titleList[index], link: itemUrl, description: "该通知无法直接预览, 请点击原文链接↑查看", pubDate: parseDate(dateList[index]) }; const $$1 = load(response.body); return { title: $$1("title").text(), link: itemUrl, description: $$1(".v_news_content").html().replaceAll("src=\"/", `src="${new URL(".", host).href}`).replaceAll("href=\"/", `href="${new URL(".", host).href}`).trim(), pubDate: $$1(".author p").eq(1).text().replace("时间:", "") }; }); else return { title: titleList[index], link: itemUrl, description: "该通知为文件,请点击原文链接↑下载", pubDate: parseDate(dateList[index]) }; })); let info; switch (type) { case "ks": info = "考试"; break; case "xx": info = "信息"; break; case "sj": info = "实践"; break; case "jx": default: info = "教学"; break; } return { title: "南京工程学院教务处 -- " + info, link, item: out }; } //#endregion export { route };