rsshub
Version:
Make RSS Great Again!
104 lines (103 loc) • 3.64 kB
JavaScript
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs";
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { Agent, buildConnector } from "undici";
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/szmuseum/namespace.ts
const namespace = {
name: "Suzhou Museum",
url: "www.szmuseum.com",
zh: { name: "苏州博物馆" }
};
//#endregion
//#region lib/routes/szmuseum/temporary.tsx
const connect = buildConnector({});
const dispatcher = new Agent({ connect(opts, cb) {
connect(opts, (err, socket) => {
if (err || !socket) {
cb(err, null);
return;
}
const read = socket.read.bind(socket);
socket.read = (...args) => {
const chunk = read(...args);
if (Buffer.isBuffer(chunk)) {
const index = chunk.indexOf("\r\nCache Control:");
if (index !== -1) chunk.write("-", index + 7);
}
return chunk;
};
cb(null, socket);
});
} });
const route = {
path: "/temporary",
categories: ["travel"],
example: "/szmuseum/temporary",
name: "Special Exhibition",
maintainers: ["magazian"],
radar: [{
source: ["www.szmuseum.com/Exhibition/Temporary"],
target: "/temporary"
}],
handler: async () => {
const baseUrl = "https://www.szmuseum.com";
const apiUrl = `${baseUrl}/Exhibition/Temporary`;
const museumName = namespace.zh?.name || namespace.name;
const $ = load(await rofetch(apiUrl, {
dispatcher,
parseResponse: (txt) => txt
}));
const list = $(".extemwrap ul li.clearfix").toArray().map((item) => {
const $item = $(item);
const a = $item.find("h1 a");
const title = a.text();
const linkStr = new URL(a.attr("href") || "", baseUrl);
linkStr.search = "";
const link = linkStr.href;
const imgUrl = $item.find(".aleftimg img").attr("src");
const fullDuration = $item.find(".activity_r_detail p:nth-child(1) span:nth-child(2)").text();
const location = $item.find(".activity_r_detail p:nth-child(2) span:nth-child(2)").text();
let startDate;
let endDate;
if (fullDuration) {
const times = fullDuration.split("-");
const startStr = times[0].replaceAll(/(.*?)/g, "").trim().replaceAll(/[年月/.]/g, "-").replace("日", "");
let endStr = times[1].replaceAll(/(.*?)/g, "").trim().replaceAll(/[年月/.]/g, "-").replace("日", "");
if (startStr && endStr.split("-").length === 2) endStr = `${startStr.split("-", 1)[0]}-${endStr}`;
startDate = dayjs(startStr).format("YYYY-MM-DD");
endDate = dayjs(endStr).format("YYYY-MM-DD");
}
const pubDate = startDate ? parseDate(startDate) : void 0;
return {
title,
link,
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] }) })
] })),
pubDate,
_extra: {
museumName,
location,
startDate,
endDate
}
};
});
return {
title: `${museumName} - 临时展览`,
link: apiUrl,
language: "zh-CN",
item: list
};
}
};
//#endregion
export { route };