From 8219d2ac43d97b6b8122a83caba551f9e7e53d0f Mon Sep 17 00:00:00 2001 From: Rares Munteanu Date: Mon, 10 Jun 2024 11:16:12 +0200 Subject: [PATCH] [MWPW-150668] Get utils ready for Helix 5 (#2376) --- 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 8c2103ca496..5eca10a4762 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; @@ -1043,7 +1044,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 {