Skip to content

Commit

Permalink
[MWPW-150668] Get utils ready for Helix 5 (adobecom#2376)
Browse files Browse the repository at this point in the history
  • Loading branch information
overmyheadandbody authored and mokimo committed Jun 11, 2024
1 parent 1cdf568 commit 8219d2a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 };
Expand Down Expand Up @@ -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 || [];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8219d2a

Please sign in to comment.