// Writes one placeholder thumbnail per top-level product category into // public/images/categories/{id}.svg. They are meant to be replaced with real // artwork one file at a time — the carousel reads the same paths either way. // Run: node scripts/gen-category-placeholders.mjs import { mkdir, writeFile } from "node:fs/promises"; const DOMAIN = process.env.NEXT_PUBLIC_SITE_DOMAIN || "moalem.shop"; const OUT = new URL("../public/images/categories/", import.meta.url); const res = await fetch( `https://api.meshkee.com/api/v1/tenants/${DOMAIN}/categories?entityType=product` ); const { items } = await res.json(); const roots = items.filter((c) => c.parentId === null).map((c) => c.id); const level2 = items.filter((c) => c.parentId && roots.includes(c.parentId)); await mkdir(OUT, { recursive: true }); const escape = (s) => s.replace(/&/g, "&").replace(//g, ">"); for (const cat of level2) { const label = escape(cat.nameFa || cat.name); const svg = ` ${label.slice(0, 9)} ${cat.id} `; await writeFile(new URL(`${cat.id}.svg`, OUT), svg, "utf8"); } console.log(`wrote ${level2.length} placeholders to public/images/categories/`);