Connect Meshkee-managed imagery and publish sitemap metadata
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
e664acb854
commit
00126e5777
@@ -0,0 +1,104 @@
|
||||
import { readdirSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
export const dynamic = "force-static";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
type StaticPage = {
|
||||
path: string;
|
||||
changefreq: "daily" | "weekly" | "monthly";
|
||||
priority: number;
|
||||
};
|
||||
|
||||
const EXCLUDED_SEGMENTS = new Set([
|
||||
"account",
|
||||
"admin",
|
||||
"api",
|
||||
"auth",
|
||||
"cart",
|
||||
"checkout",
|
||||
"login",
|
||||
"meshkee",
|
||||
"register",
|
||||
]);
|
||||
|
||||
function collectStaticPagePaths(
|
||||
directory: string,
|
||||
routeSegments: string[] = [],
|
||||
): string[] {
|
||||
const entries = readdirSync(directory, { withFileTypes: true });
|
||||
const paths: string[] = [];
|
||||
|
||||
if (entries.some((entry) => entry.isFile() && /^page\.[jt]sx?$/.test(entry.name))) {
|
||||
const path = routeSegments.length ? `/${routeSegments.join("/")}` : "/";
|
||||
paths.push(path);
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
|
||||
const isRouteGroup = entry.name.startsWith("(") && entry.name.endsWith(")");
|
||||
const isPrivateFolder = entry.name.startsWith("_");
|
||||
const isParallelRoute = entry.name.startsWith("@");
|
||||
const isDynamicRoute = entry.name.includes("[");
|
||||
|
||||
if (
|
||||
isPrivateFolder ||
|
||||
isParallelRoute ||
|
||||
isDynamicRoute ||
|
||||
EXCLUDED_SEGMENTS.has(entry.name)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
paths.push(
|
||||
...collectStaticPagePaths(
|
||||
join(directory, entry.name),
|
||||
isRouteGroup ? routeSegments : [...routeSegments, entry.name],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
function toStaticPage(path: string): StaticPage {
|
||||
if (path === "/") {
|
||||
return { path, changefreq: "daily", priority: 1 };
|
||||
}
|
||||
|
||||
if (path === "/about-us") {
|
||||
return { path, changefreq: "monthly", priority: 0.6 };
|
||||
}
|
||||
|
||||
if (path === "/contact-us") {
|
||||
return { path, changefreq: "monthly", priority: 0.5 };
|
||||
}
|
||||
|
||||
return { path, changefreq: "weekly", priority: 0.5 };
|
||||
}
|
||||
|
||||
export function GET() {
|
||||
const baseUrl = (
|
||||
process.env.NEXT_PUBLIC_SITE_URL ||
|
||||
process.env.SITE_URL ||
|
||||
"https://samanandish.com"
|
||||
).replace(/\/$/, "");
|
||||
|
||||
const staticPages = collectStaticPagePaths(join(process.cwd(), "app"))
|
||||
.sort((first, second) => {
|
||||
if (first === "/") return -1;
|
||||
if (second === "/") return 1;
|
||||
return first.localeCompare(second);
|
||||
})
|
||||
.map(toStaticPage);
|
||||
|
||||
return Response.json(
|
||||
{ baseUrl, staticPages },
|
||||
{
|
||||
headers: {
|
||||
"Cache-Control": "public, max-age=300, stale-while-revalidate=3600",
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
const slots = [
|
||||
{
|
||||
key: "slider",
|
||||
label: "اسلایدر صفحه اصلی",
|
||||
kind: "list",
|
||||
pageKey: "home",
|
||||
aspectRatio: "17:5",
|
||||
itemCount: null,
|
||||
recommendedWidth: 1920,
|
||||
},
|
||||
{
|
||||
key: "three-categories",
|
||||
label: "سه دستهبندی صفحه اصلی",
|
||||
kind: "list",
|
||||
pageKey: "home",
|
||||
aspectRatio: "3:2",
|
||||
itemCount: 3,
|
||||
recommendedWidth: 900,
|
||||
},
|
||||
{
|
||||
key: "about-us-images",
|
||||
label: "تصاویر درباره ما در صفحه اصلی",
|
||||
kind: "list",
|
||||
pageKey: "home",
|
||||
aspectRatio: "1:1",
|
||||
itemCount: 2,
|
||||
recommendedWidth: 900,
|
||||
},
|
||||
] as const;
|
||||
|
||||
export function GET() {
|
||||
return Response.json(
|
||||
{ slots },
|
||||
{
|
||||
headers: {
|
||||
"Cache-Control": "public, max-age=300, stale-while-revalidate=3600",
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user