diff --git a/app/admin/write/page.tsx b/app/admin/write/page.tsx index 2e2cff6..270d456 100644 --- a/app/admin/write/page.tsx +++ b/app/admin/write/page.tsx @@ -9,7 +9,7 @@ export const generateMetadata = async (): Promise => { const BlogWritePage = () => { return ( -
+
); diff --git a/app/api/posts/[slug]/route.ts b/app/api/posts/[slug]/route.ts index 83ad40e..aa42ee3 100644 --- a/app/api/posts/[slug]/route.ts +++ b/app/api/posts/[slug]/route.ts @@ -47,9 +47,17 @@ export async function PUT( const body = await req.json(); const post = await Post.findOne({ slug: params.slug }); + let thumbnailOfPost = getThumbnailInMarkdown(body.content); + if (!thumbnailOfPost) { + const seriesThumbnail = await Series.findById(body.seriesId).select('thumbnailImage'); + thumbnailOfPost = + seriesThumbnail?.thumbnailImage || + '/images/placeholder/thumbnail_example2.webp'; + } + const updatedPost = await Post.findOneAndUpdate( { slug: params.slug }, - { ...body, thumbnailImage: getThumbnailInMarkdown(body.content) }, + { ...body, thumbnailImage: thumbnailOfPost }, { new: true, runValidators: true, diff --git a/app/entities/post/write/BlogForm.tsx b/app/entities/post/write/BlogForm.tsx index cdeffda..0f5d0da 100644 --- a/app/entities/post/write/BlogForm.tsx +++ b/app/entities/post/write/BlogForm.tsx @@ -240,7 +240,7 @@ const BlogForm = () => { }; return ( -
+

글 {slug ? '수정' : '작성'}

@@ -294,7 +294,11 @@ const BlogForm = () => { setFormData({ content: value })} - extraCommands={[calloutCommand, commands.divider, ...commands.getExtraCommands()]} + extraCommands={[ + calloutCommand, + commands.divider, + ...commands.getExtraCommands(), + ]} height={500} minHeight={500} visibleDragbar={false} @@ -304,8 +308,13 @@ const BlogForm = () => { 'data-color-mode': theme, }, components: { - callout: ({ emoji, children }: { emoji?: string; children?: React.ReactNode }) => - {children}, + callout: ({ + emoji, + children, + }: { + emoji?: string; + children?: React.ReactNode; + }) => {children}, } as any, rehypeRewrite: (node, index?, parent?) => { asideToCallout(node); diff --git a/app/hooks/post/usePost.ts b/app/hooks/post/usePost.ts index 03317b1..07fccc5 100644 --- a/app/hooks/post/usePost.ts +++ b/app/hooks/post/usePost.ts @@ -80,7 +80,10 @@ const usePost = (slug = '') => { try { const data = await getAllSeriesData(); setSeriesList(data); - setFormData((prev) => ({ ...prev, seriesId: data[0]._id })); + // 편집 모드(slug 존재)에서는 getPostDetail이 seriesId를 설정하므로 덮어쓰지 않음 + if (!slug) { + setFormData((prev) => ({ ...prev, seriesId: data[0]._id })); + } setUIState((prev) => ({ ...prev, seriesLoading: false })); } catch (e) { console.error('시리즈 조회 중 오류 발생', e);