rsshub
Version:
Make RSS Great Again!
84 lines (83 loc) • 3.06 kB
JavaScript
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs";
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as namespace } from "./namespace-DIhnJrV5.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/tjbwg/exhibition.tsx
const formatDate = (dateString) => {
if (!dateString) return;
return dayjs(dateString, "YYYY年M月D日").format("YYYY-MM-DD");
};
const parseExhibitionDuration = (duration) => {
if (!duration) return {
startDate: void 0,
endDate: void 0
};
const parts = duration.replaceAll(/【.*?】/g, "").replaceAll(/\s+/g, "").split("-");
const startDateRaw = parts[0];
let endDateRaw = parts[1];
if (endDateRaw && !endDateRaw.includes("年")) {
const yearMatch = startDateRaw.match(/^\d{4}年/);
if (yearMatch) endDateRaw = yearMatch[0] + endDateRaw;
}
return {
startDate: formatDate(startDateRaw),
endDate: formatDate(endDateRaw)
};
};
const route = {
path: "/exhibition",
categories: ["travel"],
example: "/tjbwg/exhibition",
radar: [{
source: ["www.tjbwg.cn/cn/ExhibitionList.aspx"],
target: "/exhibition"
}],
name: "Temporary Exhibition",
maintainers: ["magazian"],
handler: async () => {
const baseUrl = "https://www.tjbwg.cn";
const listUrl = `${baseUrl}/cn/ExhibitionList.aspx?TypeId=10939`;
const museumName = namespace.zh?.name ?? namespace.name;
const $ = load(await rofetch(listUrl));
const items = $(".exhList2 ul li").toArray().map((item) => {
const a = $(item).find("a");
const href = a.attr("href") ?? "";
const link = new URL(href, `${baseUrl}/cn/`).href;
const title = a.find(".text h3").text();
const imgUrl = a.find(".img img").attr("src") ?? "";
const location = a.find("p").first().text().trim().replace(/^地点:/, "");
const fullDuration = a.find("p").last().text().trim().replace(/^展期:/, "");
const { startDate, endDate } = parseExhibitionDuration(fullDuration);
return {
title,
link,
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 || "未定/常设"] }),
fullDuration && /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsxs("small", { children: ["原始展期:", fullDuration] }) })
] })),
_extra: {
museumName,
location,
startDate,
endDate
}
};
});
return {
title: `${museumName} - 临时展览`,
link: listUrl,
language: "zh-CN",
item: items
};
}
};
//#endregion
export { route };