rsshub
Version:
Make RSS Great Again!
81 lines (77 loc) • 3.58 kB
JavaScript
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { t as timezone } from "./timezone-BBvDwS_3.mjs";
import { load } from "cheerio";
//#region lib/routes/gov/nifdc/index.ts
const route = {
path: "/:path{.+}?",
name: "国家药品监督管理局医疗器械标准管理中心 - 通用",
example: "/gov/nifdc/bshff/ylqxbzhgl/qxggtzh",
parameters: { path: "路径,默认为公告通告" },
radar: [{
source: ["www.nifdc.org.cn/nifdc/*path/index.html", "www.nifdc.org.cn/nifdc/*path"],
target: "/:path"
}],
maintainers: ["nczitzk"],
handler,
description: `::: tip
路径处填写对应页面 URL 中 \`https://www.nifdc.org.cn/nifdc/\` 与 \`/index.html\` 之间的字段,下面是一个例子。
若订阅 [公告通告](https://www.nifdc.org.cn/nifdc/bshff/ylqxbzhgl/qxggtzh/index.html) 则将对应页面 URL <https://www.nifdc.org.cn/nifdc/bshff/ylqxbzhgl/qxggtzh/index.html> 中 \`https://www.nifdc.org.cn/nifdc/\` 和 \`/index.html\` 之间的字段 \`bshff/ylqxbzhgl/qxggtzh\` 作为路径填入。此时路由为 [\`/gov/nifdc/bshff/ylqxbzhgl/qxggtzh\`](https://rsshub.app/gov/nifdc/bshff/ylqxbzhgl/qxggtzh)
:::`
};
async function handler(ctx) {
const { path = "bshff/ylqxbzhgl/qxggtzh" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 30;
const rootUrl = "https://www.nifdc.org.cn";
const currentUrl = new URL(`nifdc/${path}/`, rootUrl).href;
const { data: response } = await got_default(currentUrl);
const $ = load(response);
let items = $("div.list ul li").slice(0, limit).toArray().map((item) => {
const $item = $(item);
const a = $item.find("a");
const link = a.prop("href");
return {
title: a.prop("title") || a.text(),
link: link.startsWith("http") ? link : new URL(link, currentUrl).href,
pubDate: parseDate($item.find("span").text().replaceAll(/\(|\)/g, ""))
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
try {
const { data: detailResponse } = await got_default(item.link);
const content = load(detailResponse);
item.title = content(".title").text();
item.description = content("div.text").append(content("div.fujian")).html();
item.author = content("meta[name=\"ContentSource\"]").prop("content");
item.category = [.../* @__PURE__ */ new Set([
content("meta[name=\"ColumnName\"]").prop("content"),
content("meta[name=\"ColumnType\"]").prop("content"),
...content("meta[name=\"ColumnKeywords\"]").prop("content").split(/,|;/) ?? []
])].filter(Boolean);
item.pubDate = timezone(parseDate(content("meta[name=\"PubDate\"]").prop("content")), 8);
item.enclosure_url = content("a.fujianClass").first().prop("href");
if (item.enclosure_url) {
item.enclosure_url = new URL(item.enclosure_url, rootUrl).href;
item.enclosure_type = `application/${item.enclosure_url.split(/\./).pop()}`;
}
} catch {}
return item;
})));
const image = new URL($("div.logo img").prop("src"), currentUrl).href;
const icon = new URL($("link[rel=\"shortcut icon\"]").prop("href"), currentUrl).href;
return {
item: items,
title: $("title").text().replace(/----/, " - "),
link: currentUrl,
description: $("meta[name=\"ColumnDescription\"]").prop("content"),
language: "zh",
image,
icon,
logo: icon,
subtitle: $("meta[ name=\"ColumnName\"]").prop("content"),
author: $("meta[name=\"SiteName\"]").prop("content")
};
}
//#endregion
export { route };