@@ -8,7 +8,7 @@ interface Props {
88const { entry } = Astro .props ;
99const { Content } = await render (entry );
1010
11- const images = entry .data .images
11+ const images = entry .data .images
1212 ? entry .data .images .map ((img ) => ({
1313 src: img .src ,
1414 alt: entry .data .title ,
@@ -19,7 +19,9 @@ const images = entry.data.images
1919<li class =" py-0.5" >
2020 <div class =" flex gap-5" >
2121 <div class =" relative min-w-28 shrink-0" >
22- <span class =" text-muted-foreground text-sm" >{ entry .data .from } - { entry .data .to } </span >
22+ <span class =" text-muted-foreground text-sm"
23+ >{ entry .data .from } - { entry .data .to ?? ' Present' } </span
24+ >
2325 </div >
2426 <div class =" flex flex-col gap-3" >
2527 <div class =" flex flex-col" >
@@ -29,24 +31,26 @@ const images = entry.data.images
2931 <div class =" prose dark:prose-invert prose-sm" >
3032 <Content />
3133 </div >
32-
33- { images .length > 0 && (
34- <div class = " flex gap-2 flex-wrap mt-2" >
35- { images .map ((image , idx ) => (
36- <button
37- class = " work-image-thumb overflow-hidden rounded-lg border border-border hover:opacity-80 transition-opacity"
38- data-images = { JSON .stringify (images )}
39- data-index = { idx }
40- >
41- <img
42- src = { image .src }
43- alt = { image .alt }
44- class = " w-20 h-20 object-cover"
45- />
46- </button >
47- ))}
48- </div >
49- )}
34+
35+ {
36+ images .length > 0 && (
37+ <div class = " flex gap-2 flex-wrap mt-2" >
38+ { images .map ((image , idx ) => (
39+ <button
40+ class = " work-image-thumb overflow-hidden rounded-lg border border-border hover:opacity-80 transition-opacity"
41+ data-images = { JSON .stringify (images )}
42+ data-index = { idx }
43+ >
44+ <img
45+ src = { image .src }
46+ alt = { image .alt }
47+ class = " w-20 h-20 object-cover"
48+ />
49+ </button >
50+ ))}
51+ </div >
52+ )
53+ }
5054 </div >
5155 </div >
5256</li >
@@ -57,19 +61,19 @@ const images = entry.data.images
5761 import { createElement } from 'react';
5862
5963 const container = document.querySelector('.flex.gap-2.flex-wrap.mt-2');
60-
64+
6165 if (container) {
6266 const clickHandler = (event: Event) => {
6367 const thumb = (event.target as HTMLElement).closest('.work-image-thumb');
6468 if (!thumb || !container.contains(thumb)) return;
65-
69+
6670 const images = JSON.parse(thumb.getAttribute('data-images') || '[]');
6771 const index = parseInt(thumb.getAttribute('data-index') || '0');
68-
72+
6973 const lightboxContainer = document.createElement('div');
7074 document.body.appendChild(lightboxContainer);
7175 const root = createRoot(lightboxContainer);
72-
76+
7377 const closeHandler = () => {
7478 root.unmount();
7579 try {
@@ -78,17 +82,17 @@ const images = entry.data.images
7882 // Container may have already been removed; ignore error
7983 }
8084 };
81-
85+
8286 root.render(
8387 createElement(ImageLightbox, {
8488 images,
8589 isOpen: true,
8690 initialIndex: index,
8791 onClose: closeHandler,
88- })
92+ }),
8993 );
9094 };
91-
95+
9296 container.addEventListener('click', clickHandler);
9397 }
94- </script >
98+ </script >
0 commit comments