rsshub
Version:
Make RSS Great Again!
93 lines (92 loc) • 3.34 kB
JavaScript
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs";
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as cache_default } from "./cache-BkqOokyU.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/chinasilkmuseum/namespace.ts
const namespace = {
name: "China National Silk Museum",
url: "www.chinasilkmuseum.com",
zh: { name: "中国丝绸博物馆" }
};
//#endregion
//#region lib/routes/chinasilkmuseum/zz.tsx
const fmtExhibitionDate = (raw) => {
if (!raw) return;
const d = dayjs(raw.trim(), "YYYY年M月D日");
return d.isValid() ? d.format("YYYY-MM-DD") : void 0;
};
const parseExhibitionDuration = (fullDuration) => {
const [startRaw, endRaw] = fullDuration.split(" - ", 2);
return {
startDate: fmtExhibitionDate(startRaw),
endDate: fmtExhibitionDate(endRaw)
};
};
const route = {
path: "/zz",
categories: ["travel"],
example: "/chinasilkmuseum/zz",
name: "Exhibition",
maintainers: ["magazian"],
radar: [{
source: ["www.chinasilkmuseum.com/zz/list_17.aspx"],
target: "/zz"
}],
handler: async () => {
const baseUrl = "https://www.chinasilkmuseum.com";
const listUrl = `${baseUrl}/zz/list_17.aspx`;
const museumName = namespace.zh?.name ?? namespace.name;
const $ = load(await rofetch(listUrl));
const items = $("div.about_body div.show_info ul.ul li").toArray().map((el) => {
const $el = $(el);
const $titleLink = $el.find("div.show_text h3.h3 a");
const title = $titleLink.text();
const rawHref = $titleLink.attr("href") ?? "";
const link = new URL(rawHref, baseUrl).href;
const rawSrc = $el.find("a > img").attr("src") ?? "";
return {
title,
link,
imgUrl: new URL(rawSrc, baseUrl).href
};
});
const list = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const $d = load(await rofetch(item.link));
const location = $d("div.detail_text p").first().text().replace("展览地点:", "").trim();
const fullDuration = $d("div.detail_text p").eq(1).text().replace("展览时间:", "").trim();
const { startDate, endDate } = parseExhibitionDuration(fullDuration);
const pubDate = startDate ? parseDate(startDate) : 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.link,
pubDate,
description,
_extra: {
museumName,
location,
startDate,
endDate
}
};
})));
return {
title: `${museumName} - 在展`,
link: listUrl,
language: "zh-CN",
item: list
};
}
};
//#endregion
export { route };