// posts/api/get.ts import { wp } from "@/shared/api/wp-client"; import { parseContent } from "@/shared/api/parseContent"; import { App, WPv2 } from "@/shared/types/app"; export const fetchPostById = async (id: number): Promise => { const [post, categories] = await Promise.all([ wp.posts().id(id).get() as Promise, wp.categories().get() as Promise, ]); const categoryMap = new Map( categories.map((c) => [c.id, c.name]) ); const postCategories = post.categories.map( (id) => categoryMap.get(id) || "" ); const result: App.WpPostPage = { id: post.id, title: post.title.rendered, content: parseContent(post.content.rendered), tag: post.tags[0], categories: postCategories, }; return result; };