File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 11import { notFound } from "next/navigation" ;
22
33import PostHero from "@/components/blocks/post-hero" ;
4+ import RecentArticles from "@/components/blocks/recent-articles" ;
45
56import PortableTextRenderer from "@/components/portable-text-renderer" ;
67import {
@@ -47,6 +48,7 @@ export default async function PostPage(props: {
4748 < PostHero { ...post } />
4849 { post . body && < PortableTextRenderer value = { post . body } /> }
4950 </ article >
51+ < RecentArticles currentSlug = { params . slug } />
5052 </ div >
5153 </ section >
5254 ) ;
Original file line number Diff line number Diff line change 1+ import Link from "next/link" ;
2+ import PostCard from "@/components/ui/post-card" ;
3+ import { fetchSanityPosts } from "@/sanity/lib/fetch" ;
4+
5+ export default async function RecentArticles ( {
6+ currentSlug,
7+ title = "Recent articles" ,
8+ } : {
9+ currentSlug : string ;
10+ title ?: string ;
11+ } ) {
12+ const posts = await fetchSanityPosts ( ) ;
13+ const recent = posts
14+ . filter ( ( p ) => p ?. slug ?. current && p . slug . current !== currentSlug )
15+ . slice ( 0 , 3 ) ;
16+
17+ if ( ! recent . length ) return null ;
18+
19+ return (
20+ < div className = "mt-16 border-t pt-10" >
21+ < h2 className = "text-2xl font-semibold mb-6" > { title } </ h2 >
22+ < div className = "grid grid-cols-1 lg:grid-cols-3 gap-6" >
23+ { recent . map ( ( post ) => (
24+ < Link
25+ key = { post ?. slug ?. current }
26+ className = "flex w-full rounded-3xl ring-offset-background focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
27+ href = { `/blog/${ post ?. slug ?. current } ` }
28+ >
29+ < PostCard
30+ title = { post ?. title ?? "" }
31+ excerpt = { post ?. excerpt ?? "" }
32+ image = { post ?. image ?? null }
33+ />
34+ </ Link >
35+ ) ) }
36+ </ div >
37+ </ div >
38+ ) ;
39+ }
You can’t perform that action at this time.
0 commit comments