UNPKG

rsshub

Version:
92 lines (91 loc) 3.43 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { jsx, jsxs } from "hono/jsx/jsx-runtime"; import { load } from "cheerio"; import { renderToString } from "hono/jsx/dom/server"; //#region lib/routes/minhangmuseum/namespace.ts const namespace = { name: "Minhang Museum", url: "minhangmuseum.shmh.gov.cn", zh: { name: "上海市闵行区博物馆" } }; //#endregion //#region lib/routes/minhangmuseum/interim.tsx const parseExhibitionDuration = (duration) => { const [startDate, endDate] = duration?.match(/\d{4}年\d{1,2}月\d{1,2}日/g)?.map((d) => d.replace(/(\d{4})年(\d{1,2})月(\d{1,2})日/, (_, y, m, d) => `${y}-${m.padStart(2, "0")}-${d.padStart(2, "0")}`)) ?? []; return { startDate, endDate }; }; const route = { path: "/interim", categories: ["travel"], example: "/minhangmuseum/interim", name: "临时展览", maintainers: ["magazian"], radar: [{ source: ["minhangmuseum.shmh.gov.cn/weixin/interim/list.htm"], target: "/interim" }], handler: async () => { const baseUrl = "https://minhangmuseum.shmh.gov.cn"; const listUrl = `${baseUrl}/weixin/interim/list.htm`; const museumName = namespace.zh?.name || namespace.name; const response = await rofetch(listUrl); const $ = load(response); const listItems = $("#courseContent li, .ex-ul li").toArray().map((el) => { const $el = $(el); const href = $el.find("a").attr("href"); if (!href) return null; const itemLink = new URL(href, baseUrl).href; return { title: $el.find(".ex-li-title").text(), itemLink, fullDuration: $el.find(".apply-time").text(), imgUrl: $el.find(".ex-li-img img").attr("src") }; }).filter((item) => item !== null); const items = await Promise.all(listItems.map((item) => cache_default.tryGet(item.itemLink, async () => { const detailResponse = await rofetch(item.itemLink); const $detail = load(detailResponse); let location; $detail(".activity-detail-time ul li").each((_, el) => { const label = $detail(el).find(".detail-time-lf").text(); const val = $detail(el).find(".detail-time-rig").text(); if (label.includes("地点") && val) location = val; }); const { startDate, endDate } = parseExhibitionDuration(item.fullDuration); const pubDate = startDate ? parseDate(startDate) : void 0; const description = renderToString(/* @__PURE__ */ jsxs("div", { children: [ /* @__PURE__ */ jsx("img", { src: item.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 || "未定/常设"] }), /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsxs("small", { children: ["原始展期:", item.fullDuration] }) }) ] })); return { title: item.title, link: item.itemLink, pubDate, description, _extra: { museumName, location, startDate, endDate } }; }))); return { title: `${museumName} - 临时展览`, link: listUrl, language: "zh-CN", item: items }; } }; //#endregion export { route };