Product pages emit crawler-readable meta, public URLs use id plus Farsi slugs, and the homepage catalog matches the dashboard slot keys. Co-authored-by: Cursor <cursoragent@cursor.com>
27 lines
818 B
TypeScript
27 lines
818 B
TypeScript
import { getCategories, type ApiCategory } from "./api";
|
|
import { parentCategories } from "./data";
|
|
import { categoryHref } from "./paths";
|
|
|
|
export type MenuCategory = {
|
|
name: string;
|
|
href: string;
|
|
children: { name: string; href: string }[];
|
|
};
|
|
|
|
function hrefForSlug(categories: ApiCategory[], slug: string) {
|
|
const match = categories.find((category) => category.slug === slug);
|
|
return match ? categoryHref(match) : `/products/${slug}`;
|
|
}
|
|
|
|
export async function getMenuCategories(): Promise<MenuCategory[]> {
|
|
const categories = await getCategories();
|
|
return parentCategories.map((parent) => ({
|
|
name: parent.name,
|
|
href: hrefForSlug(categories, parent.slug),
|
|
children: parent.children.map((child) => ({
|
|
name: child.name,
|
|
href: hrefForSlug(categories, child.slug),
|
|
})),
|
|
}));
|
|
}
|