UNPKG

rsshub

Version:
107 lines (106 loc) 4.06 kB
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 { t as namespace } from "./namespace-T_kZtxVK.mjs"; import { jsx, jsxs } from "hono/jsx/jsx-runtime"; import { load } from "cheerio"; import { renderToString } from "hono/jsx/dom/server"; //#region lib/routes/capitalmuseum/exhibition.tsx const parseExhibitionDates = (fullDuration) => { let startDate; let endDate; if (fullDuration) { const match = fullDuration.match(/(\d{4})年(\d{1,2})月(\d{1,2})日(?:\D+(?:(\d{4})年)?(\d{1,2})月(\d{1,2})日)?/); if (match) { const startYear = match[1]; startDate = `${startYear}-${match[2].padStart(2, "0")}-${match[3].padStart(2, "0")}`; if (match[5] && match[6]) endDate = `${match[4] || startYear}-${match[5].padStart(2, "0")}-${match[6].padStart(2, "0")}`; } } return { startDate, endDate }; }; const route = { path: "/exhibition/:type?", categories: ["travel"], example: "/capitalmuseum/exhibition", parameters: { type: "Exhibition type, supported values: new(最新展览), review(展览回顾), default: All exhibitions." }, name: "Exhibitions", maintainers: ["magazian"], radar: [{ source: ["www.capitalmuseum.org.cn/exhibition"], target: "/exhibition" }], handler: async (ctx) => { const typeParam = ctx.req.param("type") || "all"; const typeMap = { new: "最新展览", review: "展览回顾" }; const apiUrl = `https://www.capitalmuseum.org.cn/exhibition`; const museumName = namespace.zh?.name || namespace.name; const nuxtDataStr = load((await got_default({ method: "get", url: apiUrl })).data)("#__NUXT_DATA__").text(); const nuxtData = JSON.parse(nuxtDataStr); const targetType = typeMap[typeParam]; const listItems = nuxtData.filter((item) => { if (typeof item === "object" && "eid" in item) { const itemType = nuxtData[item.cid]; return typeParam === "all" ? Object.values(typeMap).includes(itemType) : itemType === targetType; } return false; }).map((item) => { const eid = nuxtData[item.eid]; return { title: nuxtData[item.title], itemlink: `${apiUrl}/${eid}`, imgUrl: nuxtData[item.titileurl] }; }); const items = await Promise.all(listItems.map((item) => cache_default.tryGet(item.itemlink, async () => { const detailNuxtDataStr = load((await got_default({ method: "get", url: item.itemlink })).data)("#__NUXT_DATA__").text(); const detailNuxtData = JSON.parse(detailNuxtDataStr); const detailObj = detailNuxtData.find((obj) => typeof obj === "object" && "address" in obj); const location = detailNuxtData[detailObj.address]; const fullDuration = detailNuxtData[detailObj.open_time]; const { startDate, endDate } = parseExhibitionDates(fullDuration); const pubDate = startDate ? timezone(parseDate(startDate, "YYYY-MM-DD"), 8) : 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.itemlink, pubDate, description, _extra: { museumName, location, startDate, endDate } }; }))); return { title: `${museumName} - 展览陈列${targetType ? ` - ${targetType}` : ""}`, link: apiUrl, language: "zh-CN", item: items }; } }; //#endregion export { route };