From ea506ffe0aa7c3ee7357993af516152ef3017cee Mon Sep 17 00:00:00 2001 From: hyeongrok7874 Date: Tue, 1 Aug 2023 21:13:54 +0900 Subject: [PATCH 1/5] Add notFound() when useGetPostDetail is error --- apps/client/src/components/PostPage/AssembledPost/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/client/src/components/PostPage/AssembledPost/index.tsx b/apps/client/src/components/PostPage/AssembledPost/index.tsx index f749e2a65..d44b19ec0 100644 --- a/apps/client/src/components/PostPage/AssembledPost/index.tsx +++ b/apps/client/src/components/PostPage/AssembledPost/index.tsx @@ -2,6 +2,8 @@ 'use client'; +import { notFound } from 'next/navigation'; + import { css } from '@emotion/react'; import { PostContent, PostDetailHead, ReturnToList } from 'client/components'; @@ -17,7 +19,9 @@ interface AssembledPostProps { } const AssembledPost: React.FC = ({ postSeq }) => { - const { data } = useGetPostDetail(postSeq); + const { data, isError } = useGetPostDetail(postSeq); + + if (isError) notFound(); return ( From a1dbe326ff1113fa8875e15308b4cdc0abd1c760 Mon Sep 17 00:00:00 2001 From: hyeongrok7874 Date: Tue, 1 Aug 2023 21:23:29 +0900 Subject: [PATCH 2/5] Update stop-color -> stopColor --- apps/client/src/assets/svg/NotFoundTitle.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/client/src/assets/svg/NotFoundTitle.tsx b/apps/client/src/assets/svg/NotFoundTitle.tsx index b54663bf1..2926b0ea2 100644 --- a/apps/client/src/assets/svg/NotFoundTitle.tsx +++ b/apps/client/src/assets/svg/NotFoundTitle.tsx @@ -27,7 +27,7 @@ const NotFoundTitle = () => ( y2='328.025' gradientUnits='userSpaceOnUse' > - + @@ -40,7 +40,7 @@ const NotFoundTitle = () => ( y2='328.025' gradientUnits='userSpaceOnUse' > - + From 75c7d857194089354d7694aba426e15ead39fb99 Mon Sep 17 00:00:00 2001 From: hyeongrok7874 Date: Tue, 1 Aug 2023 21:24:19 +0900 Subject: [PATCH 3/5] Update notFound() call --- apps/client/src/app/post/[postSeq]/page.tsx | 4 ++++ apps/client/src/components/PostPage/AssembledPost/index.tsx | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/client/src/app/post/[postSeq]/page.tsx b/apps/client/src/app/post/[postSeq]/page.tsx index a0d1973d2..a31220bb7 100644 --- a/apps/client/src/app/post/[postSeq]/page.tsx +++ b/apps/client/src/app/post/[postSeq]/page.tsx @@ -1,3 +1,5 @@ +import { notFound } from 'next/navigation'; + import { Footer, Header, AssembledPost } from 'client/components'; import { postUrl } from 'api/client'; @@ -29,6 +31,8 @@ export const generateMetadata = async ({ `${process.env.BASE_URL}/api/client${postUrl.postDetail(postSeq)}` ).then((res) => res.json()); + if (!(await post).postTitle) return notFound(); + return { title: { absolute: (await post).postTitle }, description: (await post).postContent, diff --git a/apps/client/src/components/PostPage/AssembledPost/index.tsx b/apps/client/src/components/PostPage/AssembledPost/index.tsx index d44b19ec0..f749e2a65 100644 --- a/apps/client/src/components/PostPage/AssembledPost/index.tsx +++ b/apps/client/src/components/PostPage/AssembledPost/index.tsx @@ -2,8 +2,6 @@ 'use client'; -import { notFound } from 'next/navigation'; - import { css } from '@emotion/react'; import { PostContent, PostDetailHead, ReturnToList } from 'client/components'; @@ -19,9 +17,7 @@ interface AssembledPostProps { } const AssembledPost: React.FC = ({ postSeq }) => { - const { data, isError } = useGetPostDetail(postSeq); - - if (isError) notFound(); + const { data } = useGetPostDetail(postSeq); return ( From bae5e8e079a01400b02ec04b2690f30a25586fec Mon Sep 17 00:00:00 2001 From: hyeongrok7874 Date: Tue, 1 Aug 2023 22:46:41 +0900 Subject: [PATCH 4/5] Add descriptionFormatting --- apps/client/src/app/post/[postSeq]/page.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/client/src/app/post/[postSeq]/page.tsx b/apps/client/src/app/post/[postSeq]/page.tsx index a31220bb7..10cf10348 100644 --- a/apps/client/src/app/post/[postSeq]/page.tsx +++ b/apps/client/src/app/post/[postSeq]/page.tsx @@ -27,19 +27,22 @@ export const generateMetadata = async ({ }: PostPageProps): Promise => { const postSeq = Number(params.postSeq); - const post: Promise = await fetch( + const post: PostDetailType = await fetch( `${process.env.BASE_URL}/api/client${postUrl.postDetail(postSeq)}` ).then((res) => res.json()); - if (!(await post).postTitle) return notFound(); + if (!post.postTitle) return notFound(); return { - title: { absolute: (await post).postTitle }, - description: (await post).postContent, + title: { absolute: post.postTitle }, + description: descriptionFormatting(post.postContent), openGraph: { - title: (await post).postTitle, - description: (await post).postContent, + title: post.postTitle, + description: descriptionFormatting(post.postContent), url: `https://official.hellogsm.kr/post/${postSeq}`, }, }; }; + +const descriptionFormatting = (description: string) => + description.replace(/\n/g, ' ').replace(/\s+/g, ' ').slice(0, 120); From dcb32be030f540fb425906b619957160b9043888 Mon Sep 17 00:00:00 2001 From: hyeongrok7874 Date: Tue, 1 Aug 2023 23:17:37 +0900 Subject: [PATCH 5/5] Add try catch --- apps/client/src/app/post/[postSeq]/page.tsx | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/client/src/app/post/[postSeq]/page.tsx b/apps/client/src/app/post/[postSeq]/page.tsx index 10cf10348..f1975446f 100644 --- a/apps/client/src/app/post/[postSeq]/page.tsx +++ b/apps/client/src/app/post/[postSeq]/page.tsx @@ -25,23 +25,25 @@ export default function PostPage({ params: { postSeq } }: PostPageProps) { export const generateMetadata = async ({ params, }: PostPageProps): Promise => { - const postSeq = Number(params.postSeq); + try { + const postSeq = Number(params.postSeq); - const post: PostDetailType = await fetch( - `${process.env.BASE_URL}/api/client${postUrl.postDetail(postSeq)}` - ).then((res) => res.json()); + const post: PostDetailType = await fetch( + `${process.env.BASE_URL}/api/client${postUrl.postDetail(postSeq)}` + ).then((res) => res.json()); - if (!post.postTitle) return notFound(); - - return { - title: { absolute: post.postTitle }, - description: descriptionFormatting(post.postContent), - openGraph: { - title: post.postTitle, + return { + title: { absolute: post.postTitle }, description: descriptionFormatting(post.postContent), - url: `https://official.hellogsm.kr/post/${postSeq}`, - }, - }; + openGraph: { + title: post.postTitle, + description: descriptionFormatting(post.postContent), + url: `https://official.hellogsm.kr/post/${postSeq}`, + }, + }; + } catch (e) { + return notFound(); + } }; const descriptionFormatting = (description: string) =>