UNPKG

rsshub

Version:
140 lines (139 loc) 4.39 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { jsx, jsxs } from "hono/jsx/jsx-runtime"; import { renderToString } from "hono/jsx/dom/server"; //#region lib/routes/njmuseum/namespace.ts const namespace = { name: "Nanjing Museum", url: "www.njmuseum.com/zh", zh: { name: "南京博物院" } }; //#endregion //#region lib/routes/njmuseum/exhibitionindex.tsx const extractDates = (durationStr) => { let startDate; let endDate; if (!durationStr) return { startDate, endDate }; const parts = durationStr.split(/-+/).map((p) => p.trim()); const startStr = parts[0]; const endStr = parts[1]; let startYear; let startMonth; const startMatch = startStr.match(/(\d{4})[年.](\d{1,2})(?:[月.](\d{1,2}))?/); if (startMatch) { startYear = startMatch[1]; startMonth = startMatch[2].padStart(2, "0"); const startDay = startMatch[3] ? startMatch[3].padStart(2, "0") : "01"; startDate = `${startYear}-${startMonth}-${startDay}`; } if (endStr && startDate) { const endMatch = endStr.match(/(?:(\d{4})[年.])?(\d{1,2})(?:[月.](\d{1,2}))?/); if (endMatch) { const matchYear = endMatch[1]; const matchMonth = endMatch[2]; const matchDay = endMatch[3]; endDate = `${matchYear || startYear}-${matchMonth ? matchMonth.padStart(2, "0") : startMonth}-${matchDay ? matchDay.padStart(2, "0") : "01"}`; } } return { startDate, endDate }; }; const TYPE_MAP = { review: { modular: "exIndexReview", code: "properties", value: "5" }, abroad: { modular: "exIndexGoAbroad", code: "properties", value: "7" }, virtual: { modular: "exIndexVirtual", code: "properties", value: "11" }, forecast: { modular: "exIndexForecast", code: "properties", value: "1" }, default: { modular: "exIndex", code: "", value: "0", pageSize: 6, pageNum: 1, isList: true } }; const route = { path: "/exhibitionIndex/:type?", categories: ["travel"], example: "/njmuseum/exhibitionIndex/review", parameters: { type: "Exhibition type, supported values: review (展览回顾) | abroad (赴外展览) | virtual (虚拟展厅) | forecast (展览预告). Default: Current Exhibitions (正在展出)." }, name: "Exhibitions", maintainers: ["magazian"], radar: [{ source: ["www.njmuseum.com/zh/exhibitionIndex"], target: "/exhibitionIndex" }], handler: async (ctx) => { const typeParam = ctx.req.param("type") || "default"; const currentType = TYPE_MAP[typeParam]; const baseUrl = "https://www.njmuseum.com"; const resourceUrl = "https://manage.njmuseum.org.cn"; const apiUrl = `${baseUrl}/api/exhibition/list`; const museumName = namespace.zh?.name || namespace.name; const fetchExhibits = async (config) => { const data = (await got_default.post(apiUrl, { form: config })).data?.data; return { list: data.list, title: data.title }; }; const { list: rawItems, title: titleTag } = await fetchExhibits(currentType); const items = rawItems?.map((item) => { const title = item.title; const itemLink = `${baseUrl}/zh/${item.link}?id=${item.id}`; const imgPath = item.imgSrc?.[0]; const imgUrl = `${resourceUrl}${imgPath}`; const location = item.position; const fullDuration = item.timedesc; const { startDate, endDate } = extractDates(fullDuration); return { title, link: itemLink, pubDate: startDate ? parseDate(startDate) : void 0, description: renderToString(/* @__PURE__ */ jsxs("div", { children: [ /* @__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 ?? "未定/常设"] }), /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsxs("small", { children: ["原始展期:", fullDuration] }) }) ] })), _extra: { museumName, location, startDate, endDate } }; }); return { title: `${museumName} - 展览 - ${titleTag}`, link: `${baseUrl}/zh/exhibitionIndex`, language: "zh-CN", item: items }; } }; //#endregion export { route };