Skip to content

Commit

Permalink
Format hero picture path.
Browse files Browse the repository at this point in the history
  • Loading branch information
codecodeio committed Jun 18, 2024
1 parent a0962aa commit 3949d4b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions best-cigars-guide/blocks/hero/hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 3949d4b

Please sign in to comment.