Sentry.io integration. Vince integration. Region-scoped consent (denied-by-default in EU/EEA/UK/CH, granted elsewhere, DPDP-friendly notice)
75 lines
2.5 KiB
JavaScript
75 lines
2.5 KiB
JavaScript
/**
|
|
* 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 = [
|
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
...urls.map(({ path, priority, changefreq }) =>
|
|
[
|
|
" <url>",
|
|
` <loc>${origin}${path === "/" ? "/" : path}</loc>`,
|
|
` <lastmod>${today}</lastmod>`,
|
|
changefreq ? ` <changefreq>${changefreq}</changefreq>` : null,
|
|
priority !== undefined ? ` <priority>${priority}</priority>` : null,
|
|
" </url>",
|
|
]
|
|
.filter(Boolean)
|
|
.join("\n"),
|
|
),
|
|
"</urlset>",
|
|
"",
|
|
].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})`,
|
|
);
|