rsshub
Version:
Make RSS Great Again!
65 lines (63 loc) • 2.66 kB
JavaScript
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 { t as timezone } from "./timezone-BBvDwS_3.mjs";
import { load } from "cheerio";
//#region lib/routes/gov/beijing/bjedu/gh.ts
const route = {
path: "/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: "/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 currentUrl = `${baseUrl}/ghsite/${urlPath}/index.html`;
const { data: response, url: link = currentUrl } = await got_default(currentUrl);
const $ = load(response);
const list = $(".content li a").toArray().map((item) => {
const $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(), "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 } = await got_default(item.link);
const $ = load(response);
item.title = item.title.endsWith("...") ? $(".con-h h1").text().trim() : item.title;
item.pubDate = timezone(parseDate($(".con-h span").eq(0).text(), "YYYY-MM-DD HH:mm:ss"), 8);
item.author = $(".con-h span").eq(1).text().trim();
item.description = $(".content_font").html();
return item;
})));
return {
title: $("head title").text(),
link,
item: items
};
}
//#endregion
export { route };