UNPKG

rsshub

Version:
82 lines (81 loc) 2.46 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { t as timezone } from "./timezone-UiMFOuvL.mjs"; import { load } from "cheerio"; //#region lib/routes/zjut/cs/index.ts const rootUrl = "https://cs.zjut.edu.cn/jsp/newsclass.jsp?wcId="; const host = "cs.zjut.edu.cn"; const route = { path: "/cs/:type", categories: ["university"], example: "/zjut/cs/54", parameters: { type: "分类,见下表" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "浙江工业大学计算机科学与技术学院、软件学院", maintainers: ["zhullyb"], url: "cs.zjut.edu.cn", handler, radar: [{ source: ["cs.zjut.edu.cn/jsp/newsclass.jsp"], target: "/cs/:type" }], description: `| 新闻资讯 | 学术动态 | 通知公告 | | -------- | -------- | -------- | | 54 | 55 | 53 |` }; async function handler(ctx) { const type = Number.parseInt(ctx.req.param("type")); const response = await rofetch(rootUrl + type); const $ = load(response); const list = $("dl.news").toArray().map((item) => { const cheerioItem = $(item); const a = cheerioItem.find("a"); try { const title = a.text(); let link = a.attr("href"); if (!link) link = ""; else if (!link.startsWith("http")) link = "https://" + host + "/jsp/" + link; const pubDate = timezone(parseDate(cheerioItem.find(".datetime").text().slice(1, -1)), 8); return { title, link, pubDate }; } catch { return { title: "", link: "", pubDate: Date.now() }; } }).filter((item) => item.title && item.link); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const newItem = { ...item, description: "" }; if (host === new URL(item.link).hostname) { if (new URL(item.link).pathname.startsWith("/upload")) newItem.description = item.link; else { const response = await rofetch(item.link); newItem.description = load(response)("div.news1content").html() ?? ""; } } else newItem.description = item.link; return newItem; }))); return { title: $("li#classname").text() + " - 浙江工业大学计算机科学与技术学院、软件学院", link: rootUrl + type, item: items }; } //#endregion export { route };