Skip to content

Commit

Permalink
check for /best-cigars-guide in path.
Browse files Browse the repository at this point in the history
  • Loading branch information
codecodeio committed Jun 18, 2024
1 parent 16887cd commit a0962aa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions best-cigars-guide/blocks/article-list/article-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,19 @@ export default function decorate(block) {
}
});

// optimize images
ul.querySelectorAll('img').forEach((img) => img.closest('picture').replaceWith(createOptimizedPicture(img.src, img.alt, false, [{ width: '750' }])));
// optimize and format images
ul.querySelectorAll('img').forEach((img) => {
// Create a new URL object
const url = new URL(img.src, 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}`;
}

img.closest('picture').replaceWith(createOptimizedPicture(url.href, img.alt, false, [{ width: '750' }]));
});

// Remove any empty div tags
[...ul.querySelectorAll('div')].forEach((div) => {
Expand Down

0 comments on commit a0962aa

Please sign in to comment.