UNPKG

rsshub

Version:
70 lines (67 loc) 2.56 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/pku/hr.ts const route = { path: "/hr/:category?", categories: ["university"], example: "/pku/hr", parameters: { category: "分类,见下方说明,默认为首页最新公告" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["hr.pku.edu.cn/"] }], name: "人事处", maintainers: ["nczitzk"], handler, url: "hr.pku.edu.cn/", description: `::: tip 分类字段处填写的是对应北京大学人事处分类页网址中介于 **\`http://hr.pku.edu.cn/\`** 和 **/index.htm** 中间的一段,并将其中的 \`/\` 修改为 \`-\`。 如 [北京大学人事处 - 人才招聘 - 教师 - 教学科研人员](https://hr.pku.edu.cn/rczp/js/jxkyry/index.htm) 的网址为 \`https://hr.pku.edu.cn/rczp/js/jxkyry/index.htm\` 其中介于 **\`http://hr.pku.edu.cn/\`** 和 **\`/index.ht\`** 中间的一段为 \`rczp/js/jxkyry\`。随后,并将其中的 \`/\` 修改为 \`-\`,可以得到 \`rczp-js-jxkyry\`。所以最终我们的路由为 [\`/pku/hr/rczp-js-jxkyry\`](https://rsshub.app/pku/hr/rczp-js-jxkyry) :::` }; async function handler(ctx) { const category = ctx.req.param("category")?.replaceAll("-", "/") ?? "zxgg"; const rootUrl = "https://hr.pku.edu.cn/"; const currentUrl = `${rootUrl}/${category}/index.htm`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); const list = $(".item-list li a").toArray().map((item) => { item = $(item); return { title: item.text().replace(/\d+、/, ""), link: `${rootUrl}/${category}/${item.attr("href")}` }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); content(".title").remove(); item.description = content(".article").html(); item.pubDate = parseDate(content("#date").text()); return item; }))); return { title: `${$("h2").text()} - ${$("title").text()}`, link: currentUrl, item: items }; } //#endregion export { route };