UNPKG

rsshub

Version:
99 lines (98 loc) 3.65 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as namespace } from "./namespace-Cq1oArok.mjs"; import { jsx, jsxs } from "hono/jsx/jsx-runtime"; import { load } from "cheerio"; import { renderToString } from "hono/jsx/dom/server"; //#region lib/routes/grandcanalmuseum/linzhantezhan.tsx const formatExhibitionDate = (dateStr) => { const [y, m, d] = dateStr.replaceAll(/[年月.]/g, "-").replace("日", "").split("-", 3); if (!y || !m || !d) return; return `${y}-${m.padStart(2, "0")}-${d.padStart(2, "0")}`; }; const parseExhibitionDuration = (fullDuration) => { if (!fullDuration) return { startDate: void 0, endDate: void 0 }; const parts = fullDuration.split(/[—-]/); if (parts.length < 2) return { startDate: void 0, endDate: void 0 }; const startRaw = parts[0].trim(); let endRaw = parts[1].trim(); const startDate = formatExhibitionDate(startRaw); if (startDate && !/\d{4}/.test(endRaw)) endRaw = `${startDate.slice(0, 4)}${endRaw}`; return { startDate, endDate: formatExhibitionDate(endRaw) }; }; const route = { path: "/linzhantezhan", categories: ["travel"], example: "/grandcanalmuseum/linzhantezhan", radar: [{ source: ["www.grandcanalmuseum.cn/linzhantezhan.html"], target: "/linzhantezhan" }], name: "临展特展", maintainers: ["magazian"], handler: async () => { const museumName = namespace.zh?.name || namespace.name; const baseUrl = "https://www.grandcanalmuseum.cn"; const listUrl = `${baseUrl}/linzhantezhan.html`; const $ = load(await rofetch(listUrl)); const rawItems = $(".list_zhanlan .list > ul > li > a").toArray().map((el) => { const $a = $(el); const href = $a.attr("href"); const link = new URL(href, baseUrl).href; return { title: $a.find(".title").text(), link, imgUrl: $a.find(".img img").attr("src") }; }); const items = await Promise.all(rawItems.map((item) => cache_default.tryGet(item.link, async () => { const $d = load(await rofetch(item.link)); const location = $d(".article .lanmu span").toArray().map((el) => $d(el).text().trim()).find((text) => text.startsWith("地点:"))?.replace("地点:", ""); let fullDuration = ""; $d(".zhengwen p").each((_, el) => { const text = $d(el).text().trim(); if (text.includes("展览时间:")) fullDuration = text.split("展览时间:", 2)[1]; }); const { startDate, endDate } = parseExhibitionDuration(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 || "未定/常设"] }), fullDuration && /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsxs("small", { children: ["原始展期:", fullDuration] }) }) ] })); return { title: item.title, link: item.link, pubDate, description, _extra: { museumName, location, startDate, endDate } }; }))); return { title: `${museumName} - 临展特展`, link: listUrl, language: "zh-CN", item: items }; } }; //#endregion export { route };