50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { notFound } from "next/navigation";
|
|
import type { Metadata } from "next";
|
|
import { getProductBySlug } from "@/services/product.service";
|
|
import { getPreviewOrFallback } from "@/services/preview.service";
|
|
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
|
import type { ProductPageDetail } from "@/types/wagtail";
|
|
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
|
import PageSEO from "@/components/layout/PageSEO";
|
|
import { PageCover } from "@/components/layout/PageContent";
|
|
|
|
interface ProductDetailPageProps {
|
|
params: Promise<{ slug: string }>;
|
|
}
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: ProductDetailPageProps): Promise<Metadata> {
|
|
const { slug } = await params;
|
|
return createPageMetadata(await getPageSEO("products.ProductPage", slug).catch(() => null), "产品未找到");
|
|
}
|
|
|
|
export default async function ProductDetailPage({
|
|
params,
|
|
}: ProductDetailPageProps) {
|
|
const { slug } = await params;
|
|
const product = await getPreviewOrFallback<ProductPageDetail>(
|
|
"products.productpage",
|
|
"body,summary,cover_image",
|
|
() => getProductBySlug(slug).catch(() => null),
|
|
);
|
|
|
|
if (!product) {
|
|
notFound();
|
|
}
|
|
|
|
return (
|
|
<article className="mx-auto max-w-3xl px-6 py-24">
|
|
<PageSEO type="products.ProductPage" slug={slug} />
|
|
<h1 className="mb-4 text-4xl font-bold text-slate-900">
|
|
{product.title}
|
|
</h1>
|
|
{product.summary && (
|
|
<p className="mb-12 text-lg text-slate-600">{product.summary}</p>
|
|
)}
|
|
<PageCover image={product.cover_image} />
|
|
<BlockRenderer blocks={product.body} />
|
|
</article>
|
|
);
|
|
}
|