UNPKG

rsshub

Version:
101 lines (100 loc) 3.62 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import "./types-DNj6Etbg.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { d as renderYoutube } from "./utils-BHA2zQME.mjs"; import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime"; import { renderToString } from "hono/jsx/dom/server"; import { raw } from "hono/html"; //#region lib/routes/ryo.lu/journal.tsx const route = { path: "/journal/:lang?", categories: ["blog"], view: 0, example: "/ryo.lu/journal", parameters: { lang: { description: "Language", default: "en", options: [ { value: "en", label: "English" }, { value: "zh", label: "中文" }, { value: "ja", label: "日本語" } ] } }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["ryo.lu/journal", "ryo.lu/"], target: "/journal" }], name: "Journal", maintainers: ["TonyRL"], handler, url: "ryo.lu/journal" }; const decodeJsStringLiteral = (raw) => JSON.parse("\"" + raw.replaceAll(/\\(?:x([\dA-Fa-f]{2})|(.))|"/g, (m, hex, ch) => { if (hex) return `\\u00${hex}`; if (ch === "'") return "'"; if (ch === "v" || ch === "0") return ch === "v" ? String.raw`\u000b` : String.raw`\u0000`; return m === "\"" ? String.raw`\"` : m; }) + "\""); async function handler(ctx) { const lang = ctx.req.param("lang") ?? "en"; const baseUrl = "https://ryo.lu"; const scriptPath = (await rofetch(`${baseUrl}/journal/`)).match(/\/static\/js\/main\.\w+\.js/)?.[0]; if (!scriptPath) throw new Error("Cannot find main script"); const script = await rofetch(`${baseUrl}${scriptPath}`, { responseType: "text" }); const start = script.indexOf("JSON.parse('[{"); if (start === -1) throw new Error("Cannot find journal data"); const rest = script.slice(start + 12); const literal = rest.slice(0, rest.indexOf("]')") + 1); const entries = JSON.parse(decodeJsStringLiteral(literal)); const suffix = lang === "zh" ? "Zh" : lang === "ja" ? "Ja" : ""; const items = entries.map((entry) => { const title = entry[`title${suffix}`] ?? entry.title; const text = (entry[`text${suffix}`] ?? entry.text) || ""; const description = renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [ text.split("\n").map((line, index) => /* @__PURE__ */ jsxs(Fragment, { children: [index > 0 && /* @__PURE__ */ jsx("br", {}), line] })), entry.photos?.map((photo) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("img", { src: `${baseUrl}${photo}` })] })), entry.youtube && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("br", {}), raw(renderYoutube(true, entry.youtube, void 0, void 0))] }), entry.links?.map((link) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("a", { href: link.href, children: link.title })] })), entry.href && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("a", { href: `${baseUrl}${entry.href}`, children: `${baseUrl}${entry.href}` })] }) ] })); return { title: title ?? text.split("\n", 1)[0], description, link: `${baseUrl}/journal/${entry.slug ?? entry.id}?locale=${lang}`, guid: entry.id, pubDate: parseDate(entry.dateTime) }; }); return { title: "Ryo’s Journal", link: `${baseUrl}/journal/`, description: "Journal of Ryo Lu", language: lang === "en" ? "en" : lang === "zh" ? "zh-TW" : "ja", item: items }; } //#endregion export { route };