Something went wrong. Try again.
🌿 Collaborative wiki on ATProto forked from juprodh.me/lichen.wiki
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142import { createHash } from "node:crypto";import { readFileSync } from "node:fs";import { join } from "node:path";
const PUBLIC_DIR = join(import.meta.dir, "..", "..", "public");const hashCache = new Map<string, string>();
function computeHash(localPath: string): string | null { try { const buf = readFileSync(join(PUBLIC_DIR, localPath)); return createHash("sha256").update(buf).digest("hex").slice(0, 10); } catch { // Missing asset (e.g. in tests before build) — silently skip versioning. return null; }}
export const VIZ_SCRIPTS = [ "https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js", "/public/viz/dist.js",];
export const EDITOR_SCRIPTS = ["/public/editor/dist.js"];
export const KATEX_STYLESHEETS = ["/public/katex.css"];
// Appends a content hash (?v=…) so a deploy busts CDN/browser caches automatically.export function assetUrl(path: string): string { if (/^https?:\/\//.test(path)) return path; if (path.includes("?")) return path; if (!path.startsWith("/public/")) return path;
const localPath = path.slice("/public/".length); if (localPath.includes("..")) return path; // never let a path escape the public dir let hash = hashCache.get(localPath); if (hash === undefined) { hash = computeHash(localPath) ?? ""; hashCache.set(localPath, hash); } return hash ? `${path}?v=${hash}` : path;}