rsshub
Version:
Make RSS Great Again!
120 lines (119 loc) • 4.18 kB
JavaScript
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 namespace } from "./namespace-y0YEP6Cr.mjs";
import { jsx, jsxs } from "hono/jsx/jsx-runtime";
import { load } from "cheerio";
import { renderToString } from "hono/jsx/dom/server";
//#region lib/routes/sxhm/temporary.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].padStart(2, "0");
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]?.padStart(2, "0");
const matchDay = endMatch[3].padStart(2, "0");
endDate = `${matchYear || startYear}-${matchMonth || startMonth}-${matchDay}`;
}
}
return {
startDate,
endDate
};
};
const route = {
path: "/temporary",
categories: ["travel"],
example: "/sxhm/temporary",
parameters: {},
name: "Special Exhibition",
maintainers: ["magazian"],
radar: [{
source: ["www.sxhm.com/Temporary.html"],
target: "/temporary"
}],
handler: async () => {
const baseUrl = "https://www.sxhm.com";
const apiUrl = `${baseUrl}/Temporary.html`;
const museumName = namespace.zh?.name || namespace.name;
const $ = load((await got_default({
method: "get",
url: apiUrl
})).data);
const items = await Promise.all($(".temporary_exhibition2 .list .item").toArray().map(async (el) => {
const $item = $(el);
const $a = $item.find(".text .t1");
const link = new URL($a.attr("href"), baseUrl).href;
const imgUrlRaw = $item.find(".pic img.i").attr("src") || "";
const imgUrl = new URL(imgUrlRaw, baseUrl).href;
let title = $a.text();
const $pEls = $item.find(".text .t2 .p");
let fullDuration = $pEls.eq(0).text().replaceAll("时间:", "").trim();
const location = $pEls.eq(1).text().replaceAll("地点:", "").trim();
if (title.endsWith("...") || fullDuration.endsWith("...")) {
const $detail = load(await cache_default.tryGet(link, async () => {
return (await got_default({
method: "get",
url: link
})).data;
}));
const detailTitle = $detail(".universal2 .title, .universal3 .tbox .title").text();
if (detailTitle) title = detailTitle;
const detailDuration = $detail(".universal2 .txt_box .infor .item .t").eq(0).text().trim();
if (detailDuration) fullDuration = detailDuration;
}
const titleMatch = title.match(/“(.+?)”/);
if (titleMatch) title = titleMatch[1];
const { startDate, endDate } = extractDates(fullDuration);
const pubDate = startDate ? parseDate(startDate) : void 0;
const 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] }) })
] }));
return {
title,
link,
pubDate,
description,
_extra: {
museumName,
title,
location,
startDate,
endDate,
itemLink: link
}
};
}));
return {
title: `${museumName} - 临时展览`,
link: apiUrl,
language: "zh-CN",
item: items
};
}
};
//#endregion
export { route };