Skip to content

Commit 5dd32da

Browse files
committed
image in blogpost.
1 parent ff7f5f6 commit 5dd32da

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

public/posts/warning-post.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ And when I'm not gaming, I'm probably lost in a good book, binging a captivating
1111
This space is entirely my own, a place where my ideas, opinions, and sometimes questionable tastes run wild.
1212
I share whatever I want, whenever I want, without apology. So, if you're looking for polished, perfectly curated content,
1313
you might find some of that, but mostly, you'll find genuine, unadulterated me. Dive in, explore, and enjoy the ride!
14-
15-
![The Stranger](images/logs/albert-camus-the-stranger.jpg)

src/pages/BlogPostPage.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { customTheme } from '../utils/customTheme';
1212
import PostMetadata from '../components/PostMetadata';
1313
import CodeModal from '../components/CodeModal';
1414
import { useToast } from '../hooks/useToast';
15+
import ImageModal from '../components/ImageModal';
1516
import remarkGfm from 'remark-gfm';
1617
import rehypeRaw from 'rehype-raw';
1718

@@ -129,6 +130,7 @@ const BlogPostPage = () => {
129130
const [isModalOpen, setIsModalToOpen] = useState(false);
130131
const [modalContent, setModalContent] = useState('');
131132
const [modalLanguage, setModalLanguage] = useState('jsx'); // Default to jsx
133+
const [modalImageSrc, setModalImageSrc] = useState(null);
132134

133135
const openModal = (content, language) => {
134136
setModalContent(content);
@@ -297,6 +299,15 @@ const BlogPostPage = () => {
297299
const backLink = post.attributes.series ? `/blog/series/${post.attributes.series.slug}` : '/blog';
298300
const backLinkText = post.attributes.series ? `Back to ${post.attributes.series.title}` : 'Back to Blog';
299301

302+
const ImageRenderer = ({ src, alt }) => (
303+
<img
304+
src={src}
305+
alt={alt}
306+
className="cursor-pointer max-w-full h-auto"
307+
onClick={() => setModalImageSrc(src)}
308+
/>
309+
);
310+
300311
return (
301312
<div className="bg-gray-900 py-16 sm:py-24">
302313
<div className="mx-auto max-w-7xl px-6 lg:px-8">
@@ -320,6 +331,7 @@ const BlogPostPage = () => {
320331
code: (props) => (
321332
<CodeBlock {...props} openModal={openModal} />
322333
),
334+
img: ImageRenderer,
323335
}}
324336
>
325337
{post.body}
@@ -361,6 +373,11 @@ const BlogPostPage = () => {
361373
<CodeModal isOpen={isModalOpen} onClose={closeModal} language={modalLanguage}>
362374
{modalContent}
363375
</CodeModal>
376+
<ImageModal
377+
src={modalImageSrc}
378+
alt="Full size image"
379+
onClose={() => setModalImageSrc(null)}
380+
/>
364381
</div>
365382
);
366383
};

0 commit comments

Comments
 (0)