feat: scaffold headless frontend integration per design doc
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user