rsshub
Version:
Make RSS Great Again!
78 lines (76 loc) • 2.89 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { URL } from "node:url";
import { load } from "cheerio";
//#region lib/routes/gov/nea/ghs.ts
const route = {
path: "/nea/sjzz/ghs",
categories: ["government"],
example: "/gov/nea/sjzz/ghs",
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["nea.gov.cn/sjzz/ghs/"],
target: "/nea/sjzz/ghs"
}],
name: "发展规划司",
maintainers: ["nczitzk", "pseudoyu"],
handler,
url: "www.nea.gov.cn/sjzz/ghs/"
};
async function handler(ctx) {
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 35;
const rootUrl = "https://www.nea.gov.cn";
const targetUrl = new URL("sjzz/ghs/", rootUrl).href;
const dataSourceId = load(await ofetch_default(targetUrl))("ul#showData0").attr("data")?.split(/:/).pop();
if (!dataSourceId) throw new Error("Data source ID not found");
const jsonUrl = new URL(`ds_${dataSourceId}.json`, targetUrl).href;
const list = (await ofetch_default(jsonUrl)).datasource.slice(0, limit).map((item) => {
const itemLink = new URL(item.publishUrl, rootUrl).href;
const titleText = load(item.showTitle).text();
return {
title: titleText,
link: itemLink,
pubDate: item.publishTime ? timezone(parseDate(item.publishTime), 8) : void 0,
description: item.summary?.trim() || titleText,
author: [...new Set([
item.sourceText,
item.author,
item.editor,
item.responsibleEditor
].filter(Boolean))].map((author) => ({ name: author })),
category: item.keywords.split(/,/)
};
});
return {
item: (await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
try {
const content = load(await ofetch_default(item.link));
item.title = content("meta[name=\"ArticleTitle\"]").prop("content") || item.title;
item.description = content("td.detail").html() || content("div.article-content").html() || item.description;
item.category = [...new Set([...item.category ?? [], ...content("meta[name=\"keywords\"]").attr("conetnt")?.split(/,/) ?? []])];
const detailPubDate = content("meta[name=\"PubDate\"]").prop("content");
item.pubDate = detailPubDate ? timezone(parseDate(detailPubDate), 8) : item.pubDate;
} catch {}
return item;
})))).filter(Boolean),
title: "国家能源局 - 发展规划司工作进展",
link: targetUrl,
description: "国家能源局 - 发展规划司工作进展"
};
}
//#endregion
export { route };