RTL Meshkee storefront with home/about/contact/products/blog, API auth/contact/blog wiring, and SEO sitemap-config. Co-authored-by: Cursor <cursoragent@cursor.com>
90 lines
2.3 KiB
JavaScript
90 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Scans src/app for public static routes and writes
|
|
* src/generated/sitemap-config.json for Meshkee sync.
|
|
*/
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const appDir = path.join(__dirname, "../src/app");
|
|
const outDir = path.join(__dirname, "../src/generated");
|
|
const outFile = path.join(outDir, "sitemap-config.json");
|
|
|
|
const EXCLUDE_PREFIXES = [
|
|
"/meshkee",
|
|
"/api",
|
|
"/auth",
|
|
"/login",
|
|
"/checkout",
|
|
"/cart",
|
|
"/account",
|
|
"/admin",
|
|
"/customer",
|
|
];
|
|
|
|
function walk(dir, base = "") {
|
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
const routes = [];
|
|
|
|
for (const entry of entries) {
|
|
if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
|
|
const full = path.join(dir, entry.name);
|
|
|
|
if (entry.isDirectory()) {
|
|
if (entry.name.startsWith("[") && entry.name.endsWith("]")) continue;
|
|
const segment = entry.name.startsWith("(") ? "" : `/${entry.name}`;
|
|
routes.push(...walk(full, `${base}${segment}`));
|
|
continue;
|
|
}
|
|
|
|
if (entry.name === "page.tsx" || entry.name === "page.ts" || entry.name === "page.jsx") {
|
|
const routePath = base || "/";
|
|
if (EXCLUDE_PREFIXES.some((p) => routePath === p || routePath.startsWith(`${p}/`))) {
|
|
continue;
|
|
}
|
|
routes.push(routePath);
|
|
}
|
|
}
|
|
|
|
return routes;
|
|
}
|
|
|
|
function priorityFor(route) {
|
|
if (route === "/") return 1.0;
|
|
if (route === "/products") return 0.8;
|
|
if (route === "/blog") return 0.7;
|
|
if (route === "/about-us") return 0.6;
|
|
if (route === "/contact-us") return 0.5;
|
|
return 0.5;
|
|
}
|
|
|
|
function changefreqFor(route) {
|
|
if (route === "/" || route === "/blog") return "daily";
|
|
return undefined;
|
|
}
|
|
|
|
const routes = [...new Set(walk(appDir))].sort((a, b) => {
|
|
if (a === "/") return -1;
|
|
if (b === "/") return 1;
|
|
return a.localeCompare(b);
|
|
});
|
|
|
|
const staticPages = routes.map((routePath) => {
|
|
const page = {
|
|
path: routePath,
|
|
priority: priorityFor(routePath),
|
|
};
|
|
const cf = changefreqFor(routePath);
|
|
if (cf) page.changefreq = cf;
|
|
return page;
|
|
});
|
|
|
|
const config = {
|
|
baseUrl: "https://www.plift.ir",
|
|
staticPages,
|
|
};
|
|
|
|
fs.mkdirSync(outDir, { recursive: true });
|
|
fs.writeFileSync(outFile, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
console.log(`Wrote ${outFile} (${staticPages.length} static pages)`);
|