@@ -42,6 +42,42 @@ const PostBody = ({ content, tags, loading }: Props) => {
4242 }
4343 } ;
4444
45+ const addDescriptionUnderImage = (
46+ node : any ,
47+ index ?: number ,
48+ parent ?: Element
49+ ) => {
50+ if ( node . type === 'element' && node . tagName === 'img' ) {
51+ const altText = node . properties . alt ;
52+ if ( altText ) {
53+ const descriptionNode = {
54+ type : 'element' ,
55+ tagName : 'span' ,
56+ properties : {
57+ className : 'image-description' ,
58+ } ,
59+ children : [
60+ {
61+ type : 'text' ,
62+ value : altText ,
63+ } ,
64+ ] ,
65+ } ;
66+
67+ if (
68+ index !== undefined &&
69+ parent &&
70+ parent . children &&
71+ Array . isArray ( parent . children )
72+ ) {
73+ parent . children . splice ( index + 1 , 0 , descriptionNode ) ;
74+ }
75+ }
76+ }
77+
78+ return null ;
79+ } ;
80+
4581 const renderOpenGraph = ( node : any , index ?: number , parent ?: Element ) => {
4682 if ( node . type === 'element' && node . tagName === 'p' && node . children ) {
4783 const aTag = node . children . find (
@@ -226,7 +262,11 @@ const PostBody = ({ content, tags, loading }: Props) => {
226262 </ div >
227263 ) : (
228264 < >
229- < Overlay overlayOpen = { openImageBox } setOverlayOpen = { setOpenImageBox } >
265+ < Overlay
266+ overlayOpen = { openImageBox }
267+ setOverlayOpen = { setOpenImageBox }
268+ maxWidth = { '5xl' }
269+ >
230270 < ImageZoomOverlayContainer
231271 selectedImage = { selectedImage }
232272 setSelectedImage = { setSelectedImage }
@@ -253,6 +293,11 @@ const PostBody = ({ content, tags, loading }: Props) => {
253293 parent as Element | undefined
254294 ) ;
255295 addImageClickHandler ( node ) ;
296+ addDescriptionUnderImage (
297+ node ,
298+ index ,
299+ parent as Element | undefined
300+ ) ;
256301 } }
257302 />
258303 </ >
0 commit comments