From 20f6fef835c30f12bc27918f851de2d28986137c Mon Sep 17 00:00:00 2001 From: Jason Slavin Date: Thu, 20 Jun 2024 13:39:10 -0700 Subject: [PATCH] MWPW-146743 - Fix get image caption (#54) * Removes returning 'undefined' which shows up in the DOM when a figure is not wrapped around the image * Returning '' --------- Co-authored-by: Megan Thomas --- blog/scripts/utils.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/blog/scripts/utils.js b/blog/scripts/utils.js index cf261f4..32afb0c 100644 --- a/blog/scripts/utils.js +++ b/blog/scripts/utils.js @@ -69,10 +69,9 @@ function getImageCaption(picture) { // If the parent element doesn't have a caption, check if the next sibling does const parentSiblingEl = parentEl.nextElementSibling; - if (!parentSiblingEl || !parentSiblingEl.querySelector('picture')) return undefined; + if (!parentSiblingEl || !parentSiblingEl.querySelector('picture')) return ''; const firstChildEl = parentSiblingEl.firstChild; - caption = firstChildEl?.tagName === 'EM' ? firstChildEl : undefined; - return caption; + if (firstChildEl?.tagName === 'EM') return firstChildEl; } async function buildArticleHeader(el) {