rsshub
Version:
Make RSS Great Again!
84 lines (82 loc) • 2.82 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 { load } from "cheerio";
//#region lib/routes/gdsrx/index.ts
const route = {
path: "/:id?",
categories: ["other"],
example: "/gdsrx",
parameters: { id: "栏目 id,可在对应栏目页 URL 中找到,见下表,默认为法规文库" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "栏目",
maintainers: [],
handler,
description: `| 栏目名称 | 栏目 id |
| ----------------- | ------- |
| 法规文库 | 10 |
| 法规资讯 | 12 |
| 专家供稿 | 13 |
| 协会动态 会员动态 | 20 |
| 协会动态 | 37 |
| 协会通知公告 | 38 |
| 会员动态 | 39 |`
};
async function handler(ctx) {
const { id = "10" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 15;
const rootUrl = "http://www.gdsrx.org.cn";
const currentUrl = new URL(`portal/list/index/id/${id}.html`, rootUrl).href;
const { data: response } = await got_default(currentUrl);
const $ = load(response);
let items = $("a.xn-item, a.t-item").slice(0, limit).toArray().map((item) => {
item = $(item);
return {
title: item.find("div.xn-d, div.t-e").text(),
link: new URL(item.prop("href"), rootUrl).href,
pubDate: parseDate(item.find("div.xn-time, div.t-f").text())
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const { data: detailResponse } = await got_default(item.link);
const content = load(detailResponse);
const categories = content("a.nav-a").slice(1).toArray().map((c) => content(c).text());
item.title = categories.pop() || content("div.u-c").text();
item.description = content("div.u-f").html();
item.author = content(".author").text();
item.category = categories;
item.pubDate = parseDate(content("div.u-d").text());
return item;
})));
const author = $("title").text();
const image = $("a.h-g img").prop("src");
const icon = new URL("favicon.ico", rootUrl).href;
const subtitle = $("a.nav-a").toArray().map((c) => $(c).text()).pop();
return {
item: items,
title: `${author} - ${subtitle}`,
link: currentUrl,
description: $("meta[name=\"description\"]").prop("content"),
language: "zh",
image,
icon,
logo: icon,
subtitle,
author
};
}
//#endregion
export { route };