Skip to content

Commit

Permalink
Merge pull request #189 from themoment-team/feature/postDetailNotFound
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeongrok7874 committed Aug 1, 2023
2 parents e3c972d + dcb32be commit 6d8cb12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
39 changes: 24 additions & 15 deletions apps/client/src/app/post/[postSeq]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { notFound } from 'next/navigation';

import { Footer, Header, AssembledPost } from 'client/components';

import { postUrl } from 'api/client';
Expand All @@ -23,19 +25,26 @@ export default function PostPage({ params: { postSeq } }: PostPageProps) {
export const generateMetadata = async ({
params,
}: PostPageProps): Promise<Metadata> => {
const postSeq = Number(params.postSeq);

const post: Promise<PostDetailType> = await fetch(
`${process.env.BASE_URL}/api/client${postUrl.postDetail(postSeq)}`
).then((res) => res.json());

return {
title: { absolute: (await post).postTitle },
description: (await post).postContent,
openGraph: {
title: (await post).postTitle,
description: (await post).postContent,
url: `https://official.hellogsm.kr/post/${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());

return {
title: { absolute: post.postTitle },
description: descriptionFormatting(post.postContent),
openGraph: {
title: post.postTitle,
description: descriptionFormatting(post.postContent),
url: `https://official.hellogsm.kr/post/${postSeq}`,
},
};
} catch (e) {
return notFound();
}
};

const descriptionFormatting = (description: string) =>
description.replace(/\n/g, ' ').replace(/\s+/g, ' ').slice(0, 120);
4 changes: 2 additions & 2 deletions apps/client/src/assets/svg/NotFoundTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const NotFoundTitle = () => (
y2='328.025'
gradientUnits='userSpaceOnUse'
>
<stop stop-color='#B2E449' />
<stop stopColor='#B2E449' />
<stop offset='0.488435' stopColor='#7ACDF4' />
<stop offset='0.614583' stopColor='#5CA7D1' />
<stop offset='1' stopColor='#003365' />
Expand All @@ -40,7 +40,7 @@ const NotFoundTitle = () => (
y2='328.025'
gradientUnits='userSpaceOnUse'
>
<stop stop-color='#B2E449' />
<stop stopColor='#B2E449' />
<stop offset='0.488435' stopColor='#7ACDF4' />
<stop offset='0.614583' stopColor='#5CA7D1' />
<stop offset='1' stopColor='#003365' />
Expand Down

5 comments on commit 6d8cb12

@vercel
Copy link

@vercel vercel bot commented on 6d8cb12 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 6d8cb12 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 6d8cb12 Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 6d8cb12 Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 6d8cb12 Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.