From 0fbbc12949c8d59ea5ddcfb463d2c48140bfb490 Mon Sep 17 00:00:00 2001 From: Jimmy Cai Date: Sat, 12 Feb 2022 13:23:38 +0000 Subject: [PATCH] fix: check if paragraph exists before accessing it's textContent closes https://github.com/CaiJimmy/hugo-theme-stack/issues/490 --- assets/ts/gallery.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/ts/gallery.ts b/assets/ts/gallery.ts index ec7c02d..218658d 100644 --- a/assets/ts/gallery.ts +++ b/assets/ts/gallery.ts @@ -67,6 +67,8 @@ class StackGallery { /// This is done to allow inline images within paragraphs const paragraph = img.closest('p'); + if (!paragraph || !container.contains(paragraph)) continue; + if (paragraph.textContent.trim() == '') { /// Once we insert figcaption, this check no longer works /// So we add a class to paragraph to mark it