27 lines
1002 B
TypeScript
27 lines
1002 B
TypeScript
import { fetchAPI } from "./api-client";
|
|
import type {
|
|
CaseStudyPageDetail,
|
|
CaseStudyPageSummary,
|
|
WagtailListResponse,
|
|
} from "@/types/wagtail";
|
|
|
|
/** 获取客户案例列表(按发布时间倒序)。 */
|
|
export async function getCaseStudyList(): Promise<CaseStudyPageSummary[]> {
|
|
const res = await fetchAPI<WagtailListResponse<CaseStudyPageSummary>>(
|
|
"/api/v2/pages/?type=cases.CaseStudyPage&fields=client_name,industry,published_at,summary,cover_image&order=-published_at",
|
|
{ tags: ["case-study-list"] },
|
|
);
|
|
return res.items;
|
|
}
|
|
|
|
/** 根据 slug 获取客户案例详情。 */
|
|
export async function getCaseStudyBySlug(
|
|
slug: string,
|
|
): Promise<CaseStudyPageDetail | null> {
|
|
const res = await fetchAPI<WagtailListResponse<CaseStudyPageDetail>>(
|
|
`/api/v2/pages/?type=cases.CaseStudyPage&slug=${encodeURIComponent(slug)}&fields=body,client_name,industry,published_at,summary,cover_image&limit=1`,
|
|
{ tags: [`case-study:${slug}`] },
|
|
);
|
|
return res.items[0] ?? null;
|
|
}
|