1
- import { MarkdownRenderer } from '@/components/shared/markdown-renderer' ;
2
- import { getAllPosts , getPostBySlug } from '@/lib/notion' ;
3
- import { format } from 'date-fns' ;
4
- import { Link } from 'next-view-transitions' ;
1
+ import { PostContent } from '@/components/post/content' ;
2
+ import { PostHeader } from '@/components/post/header' ;
3
+ import { ContentSkeleton , HeaderSkeleton , RelatedPostsSkeleton } from '@/components/post/loading' ;
4
+ import { RelatedPosts } from '@/components/post/related' ;
5
+ import { config } from '@/config' ;
6
+ import { getPostBySlug } from '@/lib/notion' ;
5
7
import { notFound } from 'next/navigation' ;
8
+ import { Suspense } from 'react' ;
6
9
7
10
export async function generateMetadata ( { params } : { params : Promise < { slug : string } > } ) {
8
11
const { slug } = await params ;
@@ -20,67 +23,30 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
20
23
export default async function PostPage ( { params } : { params : Promise < { slug : string } > } ) {
21
24
const { slug } = await params ;
22
25
26
+ // Get just the post ID for related posts
23
27
const post = await getPostBySlug ( slug ) ;
24
28
25
29
if ( ! post ) return notFound ( ) ;
26
30
27
- const allPosts = await getAllPosts ( ) ;
28
- const relatedPosts = allPosts . filter ( ( p ) => p . id !== post . id ) . slice ( 0 , 2 ) ;
29
-
30
31
return (
31
- < >
32
- < header className = 'mb-10' >
33
- < h1 className = 'mb-2 font-medium text-3xl text-foreground' > { post . title } </ h1 >
34
- < div className = 'flex items-center gap-4 text-muted-foreground text-sm' >
35
- < time dateTime = { post . date } > { post . date ? format ( new Date ( post . date ) , 'MMMM d, yyyy' ) : '' } </ time >
36
- { post . tag && post . tag . length > 0 && (
37
- < div className = 'flex gap-1.5' >
38
- { post . tag . map ( ( tag ) => (
39
- < span key = { tag } className = 'rounded-md bg-secondary px-2 py-0.5 text-secondary-foreground text-xs' >
40
- { tag }
41
- </ span >
42
- ) ) }
43
- </ div >
44
- ) }
45
- </ div >
46
- </ header >
32
+ < div className = 'space-y-6' >
33
+ < Suspense fallback = { < HeaderSkeleton /> } >
34
+ < PostHeader slug = { slug } />
35
+ </ Suspense >
36
+
37
+ < Suspense fallback = { < ContentSkeleton /> } >
38
+ < PostContent slug = { slug } />
39
+ </ Suspense >
40
+
41
+ < div className = 'border-tertiary border-b' />
47
42
48
- < article className = 'mb-10' >
49
- < MarkdownRenderer content = { post . content || '' } className = 'prose prose-neutral dark:prose-invert max-w-none' />
50
- </ article >
43
+ < Suspense fallback = { < RelatedPostsSkeleton /> } >
44
+ < RelatedPosts currentPostId = { post . id } />
45
+ </ Suspense >
51
46
52
- < footer className = 'mb-3 border-tertiary border-t pt-6 md:mb-10' >
53
- < div className = 'flex items-center justify-between' >
54
- < Link href = '/' className = 'text-foreground text-sm hover:underline' >
55
- Back to home
56
- </ Link >
57
- </ div >
58
- </ footer >
47
+ < div className = 'border-tertiary border-b' />
59
48
60
- { relatedPosts . length > 0 && (
61
- < section className = 'flex w-full items-center justify-between' >
62
- { relatedPosts . map ( ( relatedPost , index ) => (
63
- < Link key = { relatedPost . id } href = { `/${ relatedPost . slug } ` } className = 'group block' >
64
- < article >
65
- < p className = 'mb-1 text-muted-foreground text-sm' > { index === 0 ? 'Previous' : 'Next' } </ p >
66
- < h3 className = 'font-medium text-base text-foreground transition-colors group-hover:text-muted-foreground' > { relatedPost . title } </ h3 >
67
- < div className = 'mt-1.5 flex items-center gap-2' >
68
- < p className = 'text-muted-foreground text-xs' > { relatedPost . date ? format ( new Date ( relatedPost . date ) , 'MMM d, yyyy' ) : '' } </ p >
69
- { relatedPost . tag && relatedPost . tag . length > 0 && (
70
- < div className = 'flex gap-1' >
71
- { relatedPost . tag . slice ( 0 , 1 ) . map ( ( tag ) => (
72
- < span key = { tag } className = 'rounded-sm bg-secondary px-1.5 py-0.5 text-secondary-foreground text-xs' >
73
- { tag }
74
- </ span >
75
- ) ) }
76
- </ div >
77
- ) }
78
- </ div >
79
- </ article >
80
- </ Link >
81
- ) ) }
82
- </ section >
83
- ) }
84
- </ >
49
+ { config . post . footer }
50
+ </ div >
85
51
) ;
86
52
}
0 commit comments