UNPKG

rsshub

Version:
70 lines (67 loc) 2.12 kB
import "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { load } from "cheerio"; //#region lib/routes/obsidian/utils.ts const regex = /([^/]+)\.md$/; const getTitle = (path) => { const match = path.match(regex); return match ? match[1] : ""; }; //#endregion //#region lib/routes/obsidian/publish.ts const route = { path: "/publish/:id", categories: ["blog"], example: "/obsidian/publish/marshallontheroad", parameters: { id: "网站 id,由Publish持有者自定义" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["publish.obsidian.md/"] }], name: "Publish", maintainers: ["Xy2002"], handler, url: "publish.obsidian.md/" }; async function handler(ctx) { return { title: "Obsidian Publish", language: "en-us", item: await fetchPage(ctx.req.param("id")), link: "https://publish.obsidian.md/" }; } async function fetchPage(id) { const baseUrl = `https://publish.obsidian.md/${id}`; const preloadCacheUrl = load(await ofetch_default(baseUrl))("script:contains(\"preloadCache\")").text().match(/preloadCache\s*=\s*f\("([^"]+)"\);/)?.[1] || ""; let preloadCacheResponse; try { preloadCacheResponse = await ofetch_default(preloadCacheUrl, { headers: { "User-Agent": config.trueUA, Referer: "https://publish.obsidian.md/", Origin: "https://publish.obsidian.m/" } }); } catch { preloadCacheResponse = {}; } return Object.entries(preloadCacheResponse).map(([postKey, post]) => { if (!post) return null; return { title: post.frontmatter?.title || getTitle(postKey), link: `${baseUrl}/${postKey.replaceAll(" ", "+").split(".md")[0]}`, pubDate: post.frontmatter?.["date created"] ? parseDate(post.frontmatter["date created"]) : void 0, ...post.frontmatter }; }).filter(Boolean); } //#endregion export { route };