64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
export type Product = {
|
|
slug: string;
|
|
name: string;
|
|
category: string;
|
|
shortLabel: string;
|
|
summary: string;
|
|
state: "placeholder";
|
|
accent: "orange" | "blue";
|
|
};
|
|
|
|
export const products: Product[] = [
|
|
{
|
|
slug: "product-placeholder-a",
|
|
name: "产品资料待补充 A",
|
|
category: "无线音频",
|
|
shortLabel: "开发占位产品",
|
|
summary: "真实产品图片、型号与规格待确认。此卡片仅用于验证产品中心与详情模板。",
|
|
state: "placeholder",
|
|
accent: "orange",
|
|
},
|
|
{
|
|
slug: "product-placeholder-b",
|
|
name: "产品资料待补充 B",
|
|
category: "蓝牙配件",
|
|
shortLabel: "开发占位产品",
|
|
summary: "真实产品内容尚未入库。发布前将由结构化 CMS 内容替换。",
|
|
state: "placeholder",
|
|
accent: "blue",
|
|
},
|
|
];
|
|
|
|
export const navigation = [
|
|
{ label: "主页", href: "/" },
|
|
{ label: "产品", href: "/products" },
|
|
{ label: "技术", href: "/#technology" },
|
|
{ label: "AI Lab", href: "/tts" },
|
|
{ label: "关于我们", href: "/about" },
|
|
];
|
|
|
|
type CmsProduct = {
|
|
id: string;
|
|
name: string;
|
|
slug: string;
|
|
category?: string;
|
|
summary?: string;
|
|
};
|
|
|
|
export async function getProducts(): Promise<Product[]> {
|
|
const endpoint = process.env.CMS_PUBLIC_API_URL;
|
|
if (!endpoint) return products;
|
|
const response = await fetch(`${endpoint.replace(/\/$/, "")}/api/products?where[status][equals]=published&sort=sortOrder&limit=100`, { cache: "no-store" });
|
|
if (!response.ok) throw new Error(`CMS products request failed: ${response.status}`);
|
|
const body = (await response.json()) as { docs?: CmsProduct[] };
|
|
return (body.docs ?? []).map((item) => ({
|
|
slug: item.slug,
|
|
name: item.name,
|
|
category: item.category ?? "产品",
|
|
shortLabel: "CMS 已发布",
|
|
summary: item.summary ?? "",
|
|
state: "placeholder",
|
|
accent: "blue",
|
|
}));
|
|
}
|