rsshub
Version:
Make RSS Great Again!
64 lines (62 loc) • 2.01 kB
JavaScript
import "./dist-Bog6z_OM.mjs";
import { t as config } from "./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/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 = matchArray[1];
return {
path,
completeUrl: `${host}${path}/${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 };