Create Glassmond storefront with Meshkee integration
Build the RTL Next.js experience with live catalog, journal, customer interactions, and SEO-ready canonical routes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import { readdir, writeFile } from "node:fs/promises";
|
||||
import { dirname, join, relative, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const appDirectory = join(root, "app");
|
||||
const outputFile = join(root, "data", "generated-sitemap-pages.ts");
|
||||
const pageFilePattern = /^page\.(?:js|jsx|ts|tsx)$/;
|
||||
const excludedSegments = new Set([
|
||||
"admin",
|
||||
"api",
|
||||
"auth",
|
||||
"cart",
|
||||
"checkout",
|
||||
"meshkee",
|
||||
]);
|
||||
|
||||
const routeSettings = {
|
||||
"/": { changefreq: "daily", priority: 1 },
|
||||
"/products": { changefreq: "daily", priority: 0.9 },
|
||||
"/blog": { changefreq: "weekly", priority: 0.8 },
|
||||
"/features": { changefreq: "monthly", priority: 0.7 },
|
||||
"/about": { changefreq: "monthly", priority: 0.6 },
|
||||
"/contact": { changefreq: "monthly", priority: 0.5 },
|
||||
};
|
||||
|
||||
function toRoute(directory) {
|
||||
const route = relative(appDirectory, directory)
|
||||
.split("/")
|
||||
.filter((segment) => segment && !segment.startsWith("("))
|
||||
.join("/");
|
||||
return route ? `/${route}` : "/";
|
||||
}
|
||||
|
||||
function isPublicStaticRoute(route) {
|
||||
const segments = route.split("/").filter(Boolean);
|
||||
return (
|
||||
!segments.some(
|
||||
(segment) =>
|
||||
segment.startsWith("[") ||
|
||||
segment.startsWith("_") ||
|
||||
excludedSegments.has(segment),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
async function collectPages(directory) {
|
||||
const entries = await readdir(directory, { withFileTypes: true });
|
||||
const route = toRoute(directory);
|
||||
const pages = [];
|
||||
|
||||
if (
|
||||
isPublicStaticRoute(route) &&
|
||||
entries.some((entry) => entry.isFile() && pageFilePattern.test(entry.name))
|
||||
) {
|
||||
pages.push(route);
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
const childRoute = toRoute(join(directory, entry.name));
|
||||
if (!isPublicStaticRoute(childRoute)) continue;
|
||||
pages.push(...(await collectPages(join(directory, entry.name))));
|
||||
}
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
||||
const routes = [...new Set(await collectPages(appDirectory))].sort((a, b) => {
|
||||
if (a === "/") return -1;
|
||||
if (b === "/") return 1;
|
||||
return a.localeCompare(b, "en");
|
||||
});
|
||||
|
||||
const pages = routes.map((path) => ({
|
||||
path,
|
||||
...(routeSettings[path] ?? { changefreq: "monthly", priority: 0.5 }),
|
||||
}));
|
||||
|
||||
const source = `// Generated by scripts/generate-sitemap-config.mjs. Do not edit manually.
|
||||
export const generatedStaticPages = ${JSON.stringify(pages, null, 2)} as const;
|
||||
`;
|
||||
|
||||
await writeFile(outputFile, source, "utf8");
|
||||
console.log(`Generated ${pages.length} public sitemap routes in ${relative(root, outputFile)}.`);
|
||||
Reference in New Issue
Block a user