rsshub
Version:
Make RSS Great Again!
71 lines (68 loc) • 2.81 kB
JavaScript
import "./dist-Bog6z_OM.mjs";
import "./config-MQ-7ebJ_.mjs";
import "./logger-C4avouvV.mjs";
import "./ofetch-DKl_Ma9g.mjs";
import { t as parseDate } from "./parse-date-r5WDWHno.mjs";
import "./is-worker-DESPicPc.mjs";
import { t as cache_default } from "./cache-SV6W5EPy.mjs";
import "./helpers-Bo4JQYdN.mjs";
import { t as got_default } from "./got-CO-ndVl2.mjs";
import { t as timezone } from "./timezone-CA9Huotp.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 } = 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().trim(), "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 };