From ca1356c3ac5dcc0e7ea9eead1a18fb2617da00bc Mon Sep 17 00:00:00 2001 From: Rares Munteanu Date: Tue, 28 May 2024 15:20:12 +0200 Subject: [PATCH] [MWPW-150668] Get utils ready for Helix 5 --- libs/utils/utils.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 35ac66358c..250e37b172 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -138,6 +138,7 @@ export const MILO_EVENTS = { DEFERRED: 'milo:deferred' }; const LANGSTORE = 'langstore'; const PAGE_URL = new URL(window.location.href); +const SLD = PAGE_URL.hostname.includes('.aem.') ? 'aem' : 'hlx'; function getEnv(conf) { const { host } = window.location; @@ -146,8 +147,8 @@ function getEnv(conf) { if (query) return { ...ENVS[query], consumer: conf[query] }; if (host.includes('localhost')) return { ...ENVS.local, consumer: conf.local }; /* c8 ignore start */ - if (host.includes('hlx.page') - || host.includes('hlx.live') + if (host.includes(`${SLD}.page`) + || host.includes(`${SLD}.live`) || host.includes('stage.adobe') || host.includes('corp.adobe')) { return { ...ENVS.stage, consumer: conf.stage }; @@ -230,7 +231,7 @@ export const [setConfig, updateConfig, getConfig] = (() => { console.log('Invalid or missing locale:', e); } config.locale.contentRoot = `${origin}${config.locale.prefix}${config.contentRoot ?? ''}`; - config.useDotHtml = !PAGE_URL.origin.includes('.hlx.') + config.useDotHtml = !PAGE_URL.origin.includes(`.${SLD}.`) && (conf.useDotHtml ?? PAGE_URL.pathname.endsWith('.html')); config.entitlements = handleEntitlements; config.consumerEntitlements = conf.entitlements || []; @@ -489,7 +490,7 @@ export function decorateSVG(a) { ? new URL(`${window.location.origin}${a.href}`) : new URL(a.href); - const src = textUrl.hostname.includes('.hlx.') ? textUrl.pathname : textUrl; + const src = textUrl.hostname.includes(`.${SLD}.`) ? textUrl.pathname : textUrl; const img = createTag('img', { loading: 'lazy', src }); if (altText) img.alt = altText; @@ -515,7 +516,7 @@ export function decorateImageLinks(el) { const [source, alt, icon] = img.alt.split('|'); try { const url = new URL(source.trim()); - const href = url.hostname.includes('.hlx.') ? `${url.pathname}${url.hash}` : url.href; + const href = url.hostname.includes(`.${SLD}.`) ? `${url.pathname}${url.hash}` : url.href; if (alt?.trim().length) img.alt = alt.trim(); const pic = img.closest('picture'); const picParent = pic.parentElement; @@ -1026,7 +1027,7 @@ function initSidekick() { function decorateMeta() { const { origin } = window.location; - const contents = document.head.querySelectorAll('[content*=".hlx."]'); + const contents = document.head.querySelectorAll(`[content*=".${SLD}."]`); contents.forEach((meta) => { if (meta.getAttribute('property') === 'hlx:proxyUrl') return; try {