rsshub
Version:
Make RSS Great Again!
61 lines (59 loc) • 2.37 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./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/mofcom/article.ts
const host = "http://www.mofcom.gov.cn";
const route = {
path: "/mofcom/article/:suffix{.+}",
name: "Unknown",
maintainers: [],
handler
};
async function handler(ctx) {
const url = `http://www.mofcom.gov.cn/article/${ctx.req.param("suffix")}/`;
const { data: res } = await got_default(url);
const $ = load(res);
$(".listline").remove();
const list = $(".txtList_01 li").toArray().map((item) => {
item = $(item);
const date = item.find("span").length === 0 ? item.find("a").attr("title").match(/(\d{4}年\d{1,2}月\d{1,2})/)[1] : item.find("span").text().match(/((\d{4}-\d{2}-\d{2})(\s\d{2}:\d{2}:\d{2})?)/)[1];
return {
title: item.find("a").attr("title"),
link: host + item.find("a").attr("href"),
pubDate: timezone(parseDate(date, [
"YYYY-MM-DD HH:mm:ss",
"YYYY-MM-DD",
"YYYY年M月D"
]), 8)
};
});
await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
let responses = await got_default(item.link);
const redirect = responses.data.match(/_cofing1={href:"(.*)",type/) || responses.data.match(/window\.location\.href='(.*)'/);
if (redirect) responses = await got_default(redirect[1], { headers: { Referer: item.link } });
const $$1 = load(responses.data);
const iframe = $$1(".art-con iframe").attr("src");
if ($$1(".art-con iframe").attr("src")) {
const { data: res$1 } = await got_default(iframe);
item.description = load(res$1)("tbody").html();
} else item.description = $$1(".art-con").html() || $$1(".textlive").html();
item.pubDate = $$1("meta[name=\"PubDate\"]").length ? timezone(parseDate($$1("meta[name=\"PubDate\"]").attr("content"), "YYYY-MM-DD HH:mm"), 8) : item.pubDate;
return item;
})));
return {
title: $("head > title").text(),
description: $("meta[name=description]").attr("content"),
link: url,
item: list
};
}
//#endregion
export { route };