- 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)。
25 lines
942 B
TypeScript
25 lines
942 B
TypeScript
import { fetchAPI } from "./api-client";
|
||
import type { ContactPageDetail, HomePageDetail, WagtailListResponse } from "@/types/wagtail";
|
||
|
||
/**
|
||
* 获取首页内容(取页面树中第一条 home.HomePage)。
|
||
*/
|
||
export async function getHomePage(): Promise<HomePageDetail | null> {
|
||
const res = await fetchAPI<WagtailListResponse<HomePageDetail>>(
|
||
"/api/v2/pages/?type=home.HomePage&fields=body,seo_title_override,seo_description_override&limit=1",
|
||
{ tags: ["home-page"] },
|
||
);
|
||
return res.items[0] ?? null;
|
||
}
|
||
|
||
/**
|
||
* 获取联系我们页面(apps.core.ContactPage,slug=contact)。
|
||
*/
|
||
export async function getContactPage(): Promise<ContactPageDetail | null> {
|
||
const res = await fetchAPI<WagtailListResponse<ContactPageDetail>>(
|
||
"/api/v2/pages/?type=core.ContactPage&fields=body,seo_title_override,seo_description_override&slug=contact&limit=1",
|
||
{ tags: ["contact-page"] },
|
||
);
|
||
return res.items[0] ?? null;
|
||
}
|