From e8c50fe8cded25806fd59ea684c440bb3b9b7429 Mon Sep 17 00:00:00 2001 From: Aishwarya Mathuria Date: Tue, 4 Jun 2024 11:53:57 +0530 Subject: [PATCH] MWPW-151448 | Fixing dot media issue in locale (#312) 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 --- creativecloud/scripts/utils.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/creativecloud/scripts/utils.js b/creativecloud/scripts/utils.js index ad7fe958a..58a519ed6 100644 --- a/creativecloud/scripts/utils.js +++ b/creativecloud/scripts/utils.js @@ -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}`; @@ -101,7 +105,7 @@ function getDecorateAreaFn() { } return (area, options) => { - replaceDotMedia(); + if (isRootPage()) replaceDotMedia(); if (!lcpImgSet) loadLCPImage(area, options); }; }