新增 /contact 联系我们页面
- types/wagtail.ts 新增 ContactPageDetail(与 HomePageDetail 同构)。 - services/page.service.ts 新增 getContactPage()。 - services/preview.service.ts 的 PREVIEW_PATH_RESOLVERS 新增 core.contactpage -> /contact。 - 新建 app/contact/page.tsx(generateMetadata + getPreviewOrFallback + BlockRenderer,与首页同构,未配置内容时展示友好提示而非 404)。
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getContactPage } from "@/services/page.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { ContactPageDetail } from "@/types/wagtail";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const page = await getContactPage().catch(() => null);
|
||||
return {
|
||||
title: page?.seo_title_override || page?.title || "联系我们",
|
||||
description: page?.seo_description_override,
|
||||
};
|
||||
}
|
||||
|
||||
export default async function ContactPage() {
|
||||
const contactPage = await getPreviewOrFallback<ContactPageDetail>(
|
||||
"core.contactpage",
|
||||
"body,seo_title_override,seo_description_override",
|
||||
() =>
|
||||
getContactPage().catch((err) => {
|
||||
console.error("getContactPage failed:", err);
|
||||
return null;
|
||||
}),
|
||||
);
|
||||
|
||||
if (!contactPage) {
|
||||
return (
|
||||
<div className="mx-auto max-w-3xl px-6 py-32 text-center">
|
||||
<h1 className="mb-4 text-3xl font-semibold text-slate-900">
|
||||
联系我们
|
||||
</h1>
|
||||
<p className="text-slate-600">
|
||||
页面内容尚未配置,请稍后再试,或通过其他渠道联系我们。
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <BlockRenderer blocks={contactPage.body} />;
|
||||
}
|
||||
Reference in New Issue
Block a user