Files
wagtailcms-frontend/services/page.service.ts
T

31 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { fetchAPI } from "./api-client";
import type { ColumnPageDetail, ContactPageDetail, HomePageDetail, WagtailListResponse } from "@/types/wagtail";
export async function getColumnPage(type: string, slug: string): Promise<ColumnPageDetail | null> {
const query = new URLSearchParams({ type, slug, fields: "intro", limit: "1" });
const res = await fetchAPI<WagtailListResponse<ColumnPageDetail>>(`/api/v2/pages/?${query}`);
return res.items[0] ?? null;
}
/**
* 获取首页内容(取页面树中第一条 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;
}