Skip to content

Commit

Permalink
MWPW-151448 | Fixing dot media issue in locale (#312)
Browse files Browse the repository at this point in the history
Adding dotmedia replacement for locale pages of root
Resolves: MWPW-151448

Test URLs:
Before: https://main--cc--adobecom.hlx.live/downloads/?martech=off
After: https://replacemedialocale--cc--adobecom.hlx.live/downloads?martech=off

https://www.stage.adobe.com/uk/downloads.html - To be verified after merge
  • Loading branch information
aishwaryamathuria authored Jun 4, 2024
1 parent ad6fa19 commit e8c50fe
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions creativecloud/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ function getDecorateAreaFn() {
if (lcpImg) lcpImgSet = true;
};

function replaceDotMedia(area = document) {
function isRootPage() {
const currUrl = new URL(window.location);
const pathSeg = currUrl.pathname.split('/').length;
if (pathSeg >= 3) return;
const locale = getConfig().locale?.prefix;
return (locale === '' && pathSeg < 3) || (locale !== '' && pathSeg < 4);
}

function replaceDotMedia(area = document) {
const resetAttributeBase = (tag, attr) => {
area.querySelectorAll(`${tag}[${attr}^="./media_"]`).forEach((el) => {
el[attr] = `${new URL(`${getConfig().contentRoot}${el.getAttribute(attr).substring(1)}`, window.location).href}`;
Expand Down Expand Up @@ -101,7 +105,7 @@ function getDecorateAreaFn() {
}

return (area, options) => {
replaceDotMedia();
if (isRootPage()) replaceDotMedia();
if (!lcpImgSet) loadLCPImage(area, options);
};
}
Expand Down

0 comments on commit e8c50fe

Please sign in to comment.