UNPKG

rsshub

Version:
78 lines (77 loc) 3.16 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { t as namespace } from "./namespace-BIfgRAES.mjs"; import dayjs from "dayjs"; import { jsx, jsxs } from "hono/jsx/jsx-runtime"; import { load } from "cheerio"; import { renderToString } from "hono/jsx/dom/server"; //#region lib/routes/gdmuseum/exhibition.tsx const formatExhibitionDate = (d) => { if (!d) return; return dayjs(d.replaceAll(/[年月/.]/g, "-").replaceAll("日", "")).format("YYYY-MM-DD"); }; const parseExhibitionDuration = (duration) => { const allDates = duration?.match(/\d{4}[./年-]\d{1,2}[./月-]\d{1,2}日?/g) || []; return { startDate: formatExhibitionDate(allDates[0]), endDate: formatExhibitionDate(allDates[1]) }; }; const route = { path: "/exhibition/:type?", categories: ["travel"], example: "/gdmuseum/exhibition/temp", parameters: { type: "Exhibition type, supported values: temp(临时展览), default: All exhibitions." }, name: "Current Exhibitions", maintainers: ["magazian"], radar: [{ source: ["www.gdmuseum.org.cn/col9/list"], target: "/exhibition" }], handler: async (ctx) => { const typeParam = ctx.req.param("type") || "all"; const museumName = namespace.zh?.name || namespace.name; const baseUrl = "https://www.gdmuseum.org.cn"; const url = `${baseUrl}/col9/list`; const $ = load((await got_default(url)).data); const list = $(".ULLIST li a[href^=\"/cn/col\"]").toArray().map((el) => { const $item = $(el); const title = $item.find(".divtt.qui-dot").text(); if (typeParam === "temp") { if (title.includes("常设展览")) return null; } else if (typeParam !== "all") return null; const rawLink = $item.attr("href"); const itemLink = rawLink ? new URL(rawLink, baseUrl).href : ""; const imgUrl = $item.find("img").attr("src"); const [fullDuration = "", location = ""] = $item.find(".quitxt.qui-dot").text().split("|").map((p) => p.trim()); const { startDate, endDate } = parseExhibitionDuration(fullDuration); return { title, link: itemLink, pubDate: startDate ? parseDate(startDate) : void 0, description: renderToString(/* @__PURE__ */ jsxs("div", { children: [ imgUrl && /* @__PURE__ */ jsx("img", { src: imgUrl }), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx("b", { children: "地点:" }), location || "参考详情"] }), /* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx("b", { children: "开展:" }), startDate || "未定/常设"] }), /* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx("b", { children: "闭展:" }), endDate || "未定/常设"] }), fullDuration && /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsxs("small", { children: ["原始展期:", fullDuration] }) }) ] })), _extra: { museumName, location, startDate, endDate } }; }).filter((i) => i !== null); return { title: `${museumName} - 正在热展${typeParam === "temp" ? " - 临时展览" : ""}`, link: url, language: "zh-CN", item: list }; } }; //#endregion export { route };