// Writes one placeholder thumbnail per product category (every level, not // just level-2) into public/images/categories/{id}.svg. They are meant to be // replaced with real artwork one file at a time — the carousel and any other // page that links a specific category id (e.g. /installments) read the same // paths either way, so every id needs a file, not just the level-2 ones the // homepage carousel shows by default. // 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(); // Root categories (parentId === null) have no icon of their own on this // site — nothing links directly to "کالای دیجیتال" itself — so only their // descendants get a placeholder. const roots = new Set(items.filter((c) => c.parentId === null).map((c) => c.id)); const withIcons = items.filter((c) => !roots.has(c.id)); await mkdir(OUT, { recursive: true }); const escape = (s) => s.replace(/&/g, "&").replace(//g, ">"); for (const cat of withIcons) { 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 ${withIcons.length} placeholders to public/images/categories/`);