rsshub
Version:
Make RSS Great Again!
64 lines (62 loc) • 2.02 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./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/cac/index.ts
const route = {
path: "/cac/*",
name: "Unknown",
maintainers: [],
handler
};
async function handler(ctx) {
const path = ctx.params[0];
const host = "http://www.cac.gov.cn";
const homepage = `${host}/index.htm`;
const completeUrl = (await cache_default.tryGet("gov:cac:pathList", async () => {
const { data: homepageResponse } = await got_default(homepage);
const $ = load(homepageResponse);
return $("a").toArray().map((item) => {
const href = $(item).attr("href");
if (href && /(?:http:)?\/\/www\.cac\.gov\.cn(.*?)\/(A.*?\.htm)/.test(href)) {
const matchArray = href.match(/(?:http:)?\/\/www\.cac\.gov\.cn(.*?)\/(A.*?\.htm)/);
if (matchArray && matchArray.length > 2) {
const path$1 = matchArray[1];
return {
path: path$1,
completeUrl: `${host}${path$1}/${matchArray[2]}`
};
}
}
return null;
}).filter(Boolean);
}, config.cache.routeExpire, false)).find((item) => item && item.path === path).completeUrl;
const { data: channelResponse } = await got_default(completeUrl);
const $1 = load(channelResponse);
const items = $1("div#loadingInfoPage li").toArray().map((item) => {
const c = $1(item);
const a = c.find("a");
const articleHref = a.attr("href");
const title = a.text();
return {
link: articleHref,
pubDate: timezone(parseDate(c.find(".times").text())),
title,
description: title
};
});
return {
title: $1("head title").text(),
link: completeUrl,
item: items
};
}
//#endregion
export { route };