@@ -3,6 +3,7 @@ import { ChevronRight } from "react-feather";
33import { Card } from "../Card" ;
44import Link from "next/link" ;
55import { usePosts } from "../../graphql/allPostsQuery" ;
6+ import { getAllBlogsMetadata , BlogMetadata } from "../../../lib/blogs" ;
67
78interface Post {
89 title : string ;
@@ -14,13 +15,38 @@ interface Post {
1415 excerpt ?: string ;
1516}
1617
18+ // Convert BlogMetadata to Post format for consistency
19+ function convertBlogToPost ( blog : BlogMetadata ) : Post {
20+ return {
21+ title : blog . title ,
22+ date : blog . date ,
23+ tags : blog . tags || [ ] ,
24+ featured_image : "" , // MDX posts don't have featured images
25+ excerpt : `Recent blog post in category: ${ blog . category } ` ,
26+ slug : `/blog/${ blog . slug } ` ,
27+ } ;
28+ }
29+
1730export const RecentPosts = ( ) => {
18- const posts : Post [ ] = usePosts ( 3 ) ;
31+ const jsonPosts : Post [ ] = usePosts ( 3 ) ;
32+
33+ // Get MDX blog posts
34+ const mdxBlogs = getAllBlogsMetadata ( ) ;
35+ const mdxPosts = mdxBlogs . map ( convertBlogToPost ) ;
36+
37+ // Combine and sort all posts by date
38+ const allPosts = [ ...mdxPosts , ...jsonPosts ] . sort (
39+ ( a , b ) => new Date ( b . date ) . getTime ( ) - new Date ( a . date ) . getTime ( )
40+ ) ;
41+
42+ // Take the 3 most recent posts
43+ const recentPosts = allPosts . slice ( 0 , 3 ) ;
44+
1945 return (
2046 < div className = "mt-12 mb-8" >
2147 < h2 className = "text-2xl font-bold mb-6 text-foreground" > Recent Posts:</ h2 >
2248 < div className = "flex flex-col gap-6" >
23- { posts . map ( ( res : Post ) => {
49+ { recentPosts . map ( ( res : Post ) => {
2450 return < Card { ...res } key = { res . title } /> ;
2551 } ) }
2652 </ div >
0 commit comments