-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Create PostDetailPage common component to eliminate code du…
…plication
- Loading branch information
Showing
5 changed files
with
34 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
frontend/apps/service-site/src/features/posts/components/PostDetailPage/PostDetailPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Lang } from '@/features/i18n' | ||
import { MDXContent } from '@packages/mdx-components' | ||
import { format, parseISO } from 'date-fns' | ||
import { notFound } from 'next/navigation' | ||
import type { FC } from 'react' | ||
import { findPostByLangAndSlug } from '../../utils' | ||
|
||
type Props = { | ||
lang: Lang | ||
slug: string | ||
} | ||
|
||
export const PostDetailPage: FC<Props> = ({ lang, slug }) => { | ||
const post = findPostByLangAndSlug({ lang, slug }) | ||
if (!post) notFound() | ||
|
||
return ( | ||
<article> | ||
<div> | ||
<time dateTime={post.date}> | ||
{format(parseISO(post.date), 'LLLL d, yyyy')} | ||
</time> | ||
<h1>{post.title}</h1> | ||
</div> | ||
<MDXContent code={post.body.code} /> | ||
</article> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/apps/service-site/src/features/posts/components/PostDetailPage/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './PostDetailPage' |
1 change: 1 addition & 0 deletions
1
frontend/apps/service-site/src/features/posts/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './PostDetailPage' | ||
export * from './PostListPage' |