UNPKG

rsshub

Version:
58 lines (57 loc) 2.35 kB
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs"; import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; //#region lib/routes/immich/cursed-knowledge.ts const route = { path: "/cursed-knowledge", categories: ["blog"], example: "/immich/cursed-knowledge", radar: [{ source: ["immich.app/cursed-knowledge", "immich.app"], target: "/cursed-knowledge" }], name: "Cursed Knowledge", maintainers: ["TonyRL"], handler }; const ghType = { pr: "pull", issue: "issues", discussion: "discussions" }; const parseGithubLink = (arg) => { const number = arg.match(/(?:number: )?([\d_]+)/)?.[1].replaceAll("_", ""); const type = arg.match(/type: '(\w+)'/)?.[1] ?? "pr"; return `https://github.com/immich-app/immich/${ghType[type]}/${number}`; }; const matchString = (entry, key) => { const m = entry.match(new RegExp(`${key}:\\s*(?:'((?:[^'\\\\]|\\\\.)*)'|"((?:[^"\\\\]|\\\\.)*)")`)); return (m?.[1] ?? m?.[2])?.replaceAll(/\\(.)/g, "$1"); }; async function handler() { const baseUrl = "https://immich.app"; const link = `${baseUrl}/cursed-knowledge/`; const [source, feed] = await Promise.all([rofetch("https://raw.githubusercontent.com/immich-app/static-pages/main/apps/root.immich.app/src/routes/cursed-knowledge/+page.svelte"), rofetch(`${baseUrl}/blog/feed.json`, { responseType: "json" })]); const items = source.slice(source.indexOf("const items")).split(/\n {4}(?:withBlog\()?\{\n/).slice(1).map((entry) => { const blogId = entry.match(/id: '([^']+)'/)?.[1]; const blogPost = blogId && feed.items.find((post) => post.id.endsWith(blogId)); const gh = entry.match(/link: asGithubLink\(([^)]*)\)/); const date = entry.match(/new Date\((\d+), (\d+), (\d+)\)/); const title = matchString(entry, "title"); return { title, description: matchString(entry, "description"), link: (gh ? parseGithubLink(gh[1]) : void 0) ?? entry.match(/href: '([^']+)'/)?.[1] ?? blogPost?.url, guid: `${link}#${title}`, pubDate: date ? parseDate(`${date[1]}-${Number(date[2]) + 1}-${date[3]}`, "YYYY-M-D") : blogPost ? parseDate(blogPost.date_published) : void 0 }; }); return { title: "Cursed Knowledge | Immich", description: "Cursed knowledge we have learned as a result of building Immich that we wish we never knew.", image: `${baseUrl}/favicon.ico`, link, item: items }; } //#endregion export { route };