rsshub
Version:
Make RSS Great Again!
52 lines (50 loc) • 1.66 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 { r as getSubPath } from "./common-utils-Cz5bFBus.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/cnnic/index.ts
const route = {
path: "/cnnic/*",
name: "Unknown",
maintainers: [],
handler
};
async function handler(ctx) {
const path = getSubPath(ctx).replaceAll(/^\/cnnic/g, "");
const currentUrl = `http://www.cnnic.net.cn${path === "/" ? "/gywm/xwzx/rdxw/20172017_7086/" : `${path}/`}`;
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
let items = $(".link a").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 12).toArray().map((item) => {
item = $(item);
return {
title: item.text(),
link: new URL(item.attr("href"), currentUrl).href
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const content = load((await got_default({
method: "get",
url: item.link
})).data);
item.description = content(".TRS_Editor").html();
item.pubDate = timezone(parseDate(content(".info .text span").first().text(), "YYYY年MM月DD日 HH:mm"), 8);
return item;
})));
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };