feat: scaffold headless frontend integration per design doc

This commit is contained in:
2026-08-06 15:51:59 +08:00
parent b0919bf8b5
commit 7e30631c68
28 changed files with 708 additions and 126 deletions
+28
View File
@@ -0,0 +1,28 @@
import { fetchAPI } from "./api-client";
import type {
BlogPageDetail,
BlogPageSummary,
WagtailListResponse,
} from "@/types/wagtail";
/**
* 获取博客列表(按发布时间倒序)。
*/
export async function getBlogList(): Promise<BlogPageSummary[]> {
const res = await fetchAPI<WagtailListResponse<BlogPageSummary>>(
"/api/v2/pages/?type=blog.BlogPage&fields=intro,published_at&order=-published_at",
{ tags: ["blog-list"] },
);
return res.items;
}
/**
* 根据 slug 获取博客详情。
*/
export async function getBlogBySlug(slug: string): Promise<BlogPageDetail | null> {
const res = await fetchAPI<WagtailListResponse<BlogPageDetail>>(
`/api/v2/pages/?type=blog.BlogPage&slug=${encodeURIComponent(slug)}&fields=body,intro,published_at&limit=1`,
{ tags: [`blog:${slug}`] },
);
return res.items[0] ?? null;
}