@@ -4,23 +4,23 @@ import React, { useState } from 'react';
44import ReactMarkdown from 'react-markdown' ;
55import Modal from './Modal' ;
66import rehypeRaw from 'rehype-raw' ;
7- import { Post } from '../components /posts' ;
7+ import { Post } from './posts' ;
88import Navbar from './Navbar' ;
9- import Footer from '../components /footer' ;
10- import Image from 'next/image' ; // Added import for next/image
9+ import Footer from './footer' ;
10+ import Image from 'next/image' ;
1111
1212interface BlogListProps {
1313 posts : Post [ ] ;
1414}
1515
1616const BlogList : React . FC < BlogListProps > = ( { posts } ) => {
17-
1817 const [ selectedPost , setSelectedPost ] = useState < Post | null > ( null ) ;
1918 const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
2019
2120 if ( ! posts . length ) {
2221 return < div > No posts found. Please check your _posts folder.</ div > ;
2322 }
23+
2424 const openModal = ( post : Post ) => {
2525 setSelectedPost ( post ) ;
2626 setIsModalOpen ( true ) ;
@@ -40,30 +40,33 @@ const BlogList: React.FC<BlogListProps> = ({ posts }) => {
4040 Blog Posts
4141 </ h1 >
4242 < div className = "grid grid-cols-1 md:grid-cols-3 gap-4 md:gap-6 w-full" >
43- { posts . map ( ( post ) => (
43+ { posts . map ( ( post , index ) => (
4444 < div
4545 key = { post . slug }
4646 onClick = { ( ) => openModal ( post ) }
4747 className = "border border-gray-200 rounded-lg p-4 md:p-6 cursor-pointer
4848 bg-[#e6e4d8] hover:bg-[#d4d2c6] transition-colors duration-200 inline-flex"
4949 >
50- < div className = "flex-col flex" >
51- < div className = "text-sm md:text-base text-gray-600 mb-3" >
52- { post . date }
50+ < div className = "flex-col flex" >
51+ < div className = "text-sm md:text-base text-gray-600 mb-3" >
52+ { post . date }
53+ </ div >
54+ < div className = "text-lg md:text-xl font-bold pr-2" >
55+ { post . title }
56+ </ div >
5357 </ div >
54- < div className = "text-lg md:text-xl font-bold pr-2" >
55- { post . title }
56- </ div >
57- </ div >
58- { post . image && (
59- < Image
60- src = { post . image }
61- alt = ""
62- className = "w-[40%] ml-auto object-cover"
63- width = { 200 }
64- height = { 200 }
65- />
66- ) }
58+ { post . image && (
59+ < Image
60+ src = { post . image }
61+ alt = { post . title }
62+ className = "w-[40%] ml-auto object-cover rounded"
63+ priority = { index < 6 }
64+ loading = { index < 6 ? "eager" : "lazy" }
65+ sizes = "(max-width: 768px) 40vw, (max-width: 1024px) 25vw, 200px"
66+ width = { 200 }
67+ height = { 200 }
68+ />
69+ ) }
6770 </ div >
6871 ) ) }
6972 </ div >
@@ -78,7 +81,22 @@ const BlogList: React.FC<BlogListProps> = ({ posts }) => {
7881 { selectedPost . date }
7982 </ p >
8083 < div className = "prose max-w-none" >
81- < ReactMarkdown rehypePlugins = { [ rehypeRaw ] } >
84+ < ReactMarkdown
85+ rehypePlugins = { [ rehypeRaw ] }
86+ components = { {
87+ img : ( { src, alt, ...props } : any ) => (
88+ < Image
89+ src = { src || '' }
90+ alt = { alt || '' }
91+ className = "rounded-lg max-w-full h-auto"
92+ width = { 600 }
93+ height = { 400 }
94+ loading = "lazy"
95+ { ...props }
96+ />
97+ ) ,
98+ } }
99+ >
82100 { selectedPost . content }
83101 </ ReactMarkdown >
84102 </ div >
0 commit comments