新增 /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} />;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { fetchAPI } from "./api-client";
|
import { fetchAPI } from "./api-client";
|
||||||
import type { HomePageDetail, WagtailListResponse } from "@/types/wagtail";
|
import type { ContactPageDetail, HomePageDetail, WagtailListResponse } from "@/types/wagtail";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取首页内容(取页面树中第一条 home.HomePage)。
|
* 获取首页内容(取页面树中第一条 home.HomePage)。
|
||||||
@@ -11,3 +11,14 @@ export async function getHomePage(): Promise<HomePageDetail | null> {
|
|||||||
);
|
);
|
||||||
return res.items[0] ?? null;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const PREVIEW_PATH_RESOLVERS: Record<
|
|||||||
"products.productpage": (page) => `/products/${page.meta.slug}`,
|
"products.productpage": (page) => `/products/${page.meta.slug}`,
|
||||||
"cases.casestudypage": (page) => `/cases/${page.meta.slug}`,
|
"cases.casestudypage": (page) => `/cases/${page.meta.slug}`,
|
||||||
"solutions.solutionpage": (page) => `/solutions/${page.meta.slug}`,
|
"solutions.solutionpage": (page) => `/solutions/${page.meta.slug}`,
|
||||||
|
"core.contactpage": () => "/contact",
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 根据 content_type 解析预览内容应跳转到的前端路径,未知类型返回 null。 */
|
/** 根据 content_type 解析预览内容应跳转到的前端路径,未知类型返回 null。 */
|
||||||
|
|||||||
@@ -231,6 +231,12 @@ export interface SimpleContentPageDetail extends WagtailPageSummary {
|
|||||||
body: string; // richtext HTML
|
body: string; // richtext HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ContactPageDetail extends WagtailPageSummary {
|
||||||
|
body: StreamFieldBlock[];
|
||||||
|
seo_title_override?: string;
|
||||||
|
seo_description_override?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局 Snippet 类型(apps/core/models.py)。
|
* 全局 Snippet 类型(apps/core/models.py)。
|
||||||
* 通过 /api/v1/custom/core/... 只读接口获取,非 Wagtail Page API。
|
* 通过 /api/v1/custom/core/... 只读接口获取,非 Wagtail Page API。
|
||||||
|
|||||||
Reference in New Issue
Block a user