Skip to content

Commit 5d7458f

Browse files
committed
Loading optimizations
1 parent 204ed0e commit 5d7458f

File tree

2 files changed

+55
-22
lines changed

2 files changed

+55
-22
lines changed

src/app/components/blog.tsx

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import React, { useState } from 'react';
44
import ReactMarkdown from 'react-markdown';
55
import Modal from './Modal';
66
import rehypeRaw from 'rehype-raw';
7-
import { Post } from '../components/posts';
7+
import { Post } from './posts';
88
import 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

1212
interface BlogListProps {
1313
posts: Post[];
1414
}
1515

1616
const 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>

src/app/leaders/page.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import { leaders, officers, teamleads } from '../components/officersData';
77
import Footer from '../components/footer';
88

99

10+
const blurDataURL = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAv/xAAhEAACAQMDBQAAAAAAAAAAAAABAgMABAUGIWGRkqGx0f/EABUBAQEAAAAAAAAAAAAAAAAAAAMF/8QAGhEAAgIDAAAAAAAAAAAAAAAAAAECEgMRkf/aAAwDAQACEQMRAD8AltJagyeH0AthI5xdrLcNM91BF5pX2HaH9bcfaSXWGaRmknyEhck+C3Hx2lhE6mZAFr2n7CRaIDFwJULk5LlhQDg/f5Vfo";
11+
1012
const LeaderPage: React.FC = () => {
1113
const handleClick = (link) => {
1214
if (link) {
1315
window.open(link, '_blank');
1416
}
1517
};
18+
1619
return (
1720
<>
1821
<Navbar scrollSet={false} />
@@ -37,6 +40,10 @@ const LeaderPage: React.FC = () => {
3740
alt={member.name}
3841
className="object-contain rounded-full"
3942
placeholder='blur'
43+
blurDataURL={blurDataURL}
44+
priority={index < 4}
45+
loading={index < 4 ? "eager" : "lazy"}
46+
sizes="(max-width: 640px) 50vw, (max-width: 768px) 25vw, (max-width: 1024px) 25vw, 200px"
4047
fill
4148
/>
4249
</div>
@@ -71,6 +78,10 @@ const LeaderPage: React.FC = () => {
7178
alt={member.name}
7279
className="object-cover rounded-full"
7380
placeholder='blur'
81+
blurDataURL={blurDataURL}
82+
priority={index < 4}
83+
loading={index < 4 ? "eager" : "lazy"}
84+
sizes="(max-width: 640px) 50vw, (max-width: 768px) 25vw, (max-width: 1024px) 25vw, 200px"
7485
fill
7586
/>
7687
</div>
@@ -104,6 +115,10 @@ const LeaderPage: React.FC = () => {
104115
alt={member.name}
105116
className="object-cover rounded-full"
106117
placeholder='blur'
118+
blurDataURL={blurDataURL}
119+
priority={index < 6}
120+
loading={index < 6 ? "eager" : "lazy"}
121+
sizes="(max-width: 640px) 64px, (max-width: 768px) 96px, 96px"
107122
fill
108123
/>
109124
</div>

0 commit comments

Comments
 (0)