diff --git a/best-cigars-guide/blocks/hero/hero.js b/best-cigars-guide/blocks/hero/hero.js index 3391517..fd80039 100644 --- a/best-cigars-guide/blocks/hero/hero.js +++ b/best-cigars-guide/blocks/hero/hero.js @@ -63,6 +63,29 @@ function addSecondParagraphToHero() { } } +// Format picute path +function formatPicturePath() { + const picture = document.querySelector('.hero picture'); + if (picture) { + picture.querySelectorAll('img, source').forEach((element) => { + const url = new URL(element.src || element.srcset, window.location.origin); + + // Check if the pathname begins with "/best-cigars-guide" + if (!url.pathname.startsWith('/best-cigars-guide')) { + // Prepend "/best-cigars-guide" to the pathname + url.pathname = `/best-cigars-guide${url.pathname}`; + } + + if (element.tagName === 'IMG') { + element.src = url.href; + } else if (element.tagName === 'SOURCE') { + element.srcset = url.href; + } + }); + } +} + export default function decorate() { addSecondParagraphToHero(); + formatPicturePath(); }