/** * Generates dist/client/sitemap.xml after `vite build`. * * Static routes are listed explicitly; journal essay slugs are parsed from * src/data/catalog.ts so they stay in sync with the source of truth. * Dynamic product/collection pages are intentionally excluded for now — * they duplicate shop.mozimo.in content and churn constantly. * * Origin: SITE_ORIGIN env (default https://mozimo.in). */ import { readFileSync, writeFileSync, mkdirSync } from "node:fs"; import { join, dirname } from "node:path"; import { fileURLToPath } from "node:url"; const root = join(dirname(fileURLToPath(import.meta.url)), ".."); const origin = (process.env.SITE_ORIGIN ?? "https://mozimo.in").replace( /\/+$/, "", ); const STATIC_ROUTES = [ { path: "/", priority: 1.0, changefreq: "weekly" }, { path: "/chocolate", priority: 0.9, changefreq: "weekly" }, { path: "/gifting", priority: 0.9, changefreq: "weekly" }, { path: "/experiences", priority: 0.7, changefreq: "monthly" }, { path: "/bespoke", priority: 0.8, changefreq: "monthly" }, { path: "/contact", priority: 0.5, changefreq: "yearly" }, { path: "/our-world", priority: 0.6, changefreq: "monthly" }, { path: "/journal", priority: 0.6, changefreq: "monthly" }, { path: "/privacy", priority: 0.2, changefreq: "yearly" }, ]; // journal essay slugs live in src/data/catalog.ts (the essays block) const catalogSrc = readFileSync(join(root, "src/data/catalog.ts"), "utf8"); const slugs = [...catalogSrc.matchAll(/^\s{4}slug:\s*"([^"]+)"/gm)].map( (m) => m[1], ); const today = new Date().toISOString().slice(0, 10); const urls = [ ...STATIC_ROUTES, ...slugs.map((slug) => ({ path: `/journal/${slug}`, priority: 0.5, changefreq: "yearly", })), ]; const xml = [ '', '', ...urls.map(({ path, priority, changefreq }) => [ " ", ` ${origin}${path === "/" ? "/" : path}`, ` ${today}`, changefreq ? ` ${changefreq}` : null, priority !== undefined ? ` ${priority}` : null, " ", ] .filter(Boolean) .join("\n"), ), "", "", ].join("\n"); const outDir = join(root, "dist/client"); mkdirSync(outDir, { recursive: true }); writeFileSync(join(outDir, "sitemap.xml"), xml, "utf8"); console.log( `[sitemap] ${urls.length} URLs → dist/client/sitemap.xml (origin ${origin})`, );