From 43ca44dc715f4c472f257f51bdae0828f7ca0dc9 Mon Sep 17 00:00:00 2001 From: ifraimka1 Date: Wed, 23 Apr 2025 19:41:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=B8=D0=B9,=20=D1=83?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=BB=20base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/posts/api/get/fetchPostById.ts | 14 +++++++++++++- src/modules/posts/api/get/fetchPosts.ts | 2 +- vite.config.ts | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) 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: {