UNPKG

rsshub

Version:
71 lines (68 loc) 2.83 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 { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/beijing/bjedu/gh.ts const route = { path: "/beijing/bjedu/gh/:urlPath?", categories: ["government"], example: "/gov/beijing/bjedu/gh", parameters: { urlPath: "路径,默认为 `zxtzgg`" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["gh.bjedu.gov.cn/ghsite/:urlPath/index.html", "gh.bjedu.gov.cn/ghsite/:urlPath"], target: "/beijing/bjedu/gh/:urlPath" }], name: "通用", maintainers: ["TonyRL"], handler, description: `::: tip 路径处填写对应页面 URL 中 \`https://gh.bjedu.cn/ghsite/\` 和 \`/index.html\` 之间的字段。下面是一个例子。 若订阅 [通知公告](https://gh.bjedu.cn/ghsite/zxtzgg/index.html) 则将对应页面 URL \`https://gh.bjedu.cn/ghsite/zxtzgg/index.html\` 中 \`https://gh.bjedu.cn/ghsite/\` 和 \`/index.html\` 之间的字段 \`zxtzgg\` 作为路径填入。此时路由为 [\`/gov/beijing/bjedu/gh/zxtzgg\`](https://rsshub.app/gov/beijing/bjedu/gh/zxtzgg) :::` }; async function handler(ctx) { const baseUrl = "https://gh.bjedu.cn"; const { urlPath = "zxtzgg" } = ctx.req.param(); const { data: response, url: link } = await got_default(`${baseUrl}/ghsite/${urlPath}/index.html`); const $ = load(response); const list = $(".content li a").toArray().map((item) => { item = $(item); return { title: item.text().trim(), link: item.attr("href").startsWith("http") ? item.attr("href").replace(/^http:/, "https:") : new URL(item.attr("href"), link).href, pubDate: item.prev().length ? timezone(parseDate(item.prev().text().trim(), "YYYY-MM-DD"), 8) : null }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { if (!item.link.endsWith(".html")) return item; const { data: response$1 } = await got_default(item.link); const $$1 = load(response$1); item.title = item.title.endsWith("...") ? $$1(".con-h h1").text().trim() : item.title; item.pubDate = timezone(parseDate($$1(".con-h span").eq(0).text().trim(), "YYYY-MM-DD HH:mm:ss"), 8); item.author = $$1(".con-h span").eq(1).text().trim(); item.description = $$1(".content_font").html(); return item; }))); return { title: $("head title").text(), link, item: items }; } //#endregion export { route };