rsshub
Version:
Make RSS Great Again!
62 lines (60 loc) • 2.08 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 { t as renderDescription } from "./description-BVnw0xCM.mjs";
import { load } from "cheerio";
//#region lib/routes/gov/cmse/index.ts
const route = {
path: "/cmse/*",
name: "Unknown",
maintainers: [],
handler
};
async function handler(ctx) {
const path = getSubPath(ctx).replaceAll(/(^\/cmse|\/$)/g, "");
const currentUrl = `http://www.cmse.gov.cn${path === "" ? "/xwzx/zhxw/" : `${path}/`}`;
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
let items = $("#list li a").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 15).toArray().map((item) => {
item = $(item);
const pubDate = item.next().text();
const link = new URL(item.attr("href"), currentUrl).href;
return {
title: item.text(),
pubDate: parseDate(pubDate),
link: /\.html$/.test(link) ? link : `${link}#${pubDate}`
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const detailResponse = await got_default({
method: "get",
url: item.link
});
const content = load(detailResponse.data);
content(".share").remove();
const detailPubTimeMatches = detailResponse.data.match(/__\$pubtime='(.*?)';var/);
item.pubDate = detailPubTimeMatches ? timezone(parseDate(detailPubTimeMatches[1]), 8) : item.pubDate;
item.description = renderDescription({
video: content("#con_video").html(),
description: content(".TRS_Editor, #content").html()
});
return item;
})));
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };