diff --git a/src/modules/posts/api/get/fetchPostById.ts b/src/modules/posts/api/get/fetchPostById.ts index dd373ad..c9781a4 100644 --- a/src/modules/posts/api/get/fetchPostById.ts +++ b/src/modules/posts/api/get/fetchPostById.ts @@ -4,13 +4,25 @@ import { parseContent } from "@/shared/api/parseContent"; import { App, WPv2 } from "@/shared/types/app"; export const fetchPostById = async (id: number): Promise => { - const post = await wp.posts().id(id).get() as WPv2.Post; + 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; diff --git a/src/modules/posts/api/get/fetchPosts.ts b/src/modules/posts/api/get/fetchPosts.ts index a624c8c..4367862 100644 --- a/src/modules/posts/api/get/fetchPosts.ts +++ b/src/modules/posts/api/get/fetchPosts.ts @@ -58,6 +58,6 @@ export const fetchPosts = async (): Promise => { result.other.push(newWpPostPage); } } - console.log('fetchPosts result', result); + return result; }; diff --git a/vite.config.ts b/vite.config.ts index 3e9bd1e..48cf719 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,7 +3,7 @@ import react from "@vitejs/plugin-react"; import path from "path"; export default defineConfig({ - base: '/wp-content/reactpress/apps/skb/dist/', + // base: '/wp-content/reactpress/apps/skb/dist/', plugins: [react()], resolve: { alias: {