diff --git a/libs/scripts/scripts.js b/libs/scripts/scripts.js index f91876dc1a..956f075193 100644 --- a/libs/scripts/scripts.js +++ b/libs/scripts/scripts.js @@ -19,6 +19,14 @@ import { // Production Domain const prodDomains = ['milo.adobe.com']; +const stageDomainsMap = { + 'www.adobe.com': 'www.stage.adobe.com', + 'blog.adobe.com': 'blog.stage.adobe.com', + 'business.adobe.com': 'business.stage.adobe.com', + 'helpx.adobe.com': 'helpx.stage.adobe.com', + 'news.adobe.com': 'news.stage.adobe.com', +}; + const locales = { '': { ietf: 'en-US', tk: 'hah7vzn.css' }, ae_ar: { ietf: 'ar-AE', tk: 'lpk1hwn.css', dir: 'rtl' }, @@ -127,6 +135,7 @@ const config = { codeRoot: '/libs', locales, prodDomains, + stageDomainsMap, jarvis: { id: 'milo', version: '1.0', diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 35ac66358c..956de2277a 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -608,12 +608,16 @@ export function decorateAutoBlock(a) { } export function decorateLinks(el) { + const config = getConfig(); decorateImageLinks(el); const anchors = el.getElementsByTagName('a'); return [...anchors].reduce((rdx, a) => { appendHtmlToLink(a); a.href = localizeLink(a.href); decorateSVG(a); + if (config.env?.name === 'stage' && config.stageDomainsMap?.[a.hostname]) { + a.href = a.href.replace(a.hostname, config.stageDomainsMap[a.hostname]); + } if (a.href.includes('#_blank')) { a.setAttribute('target', '_blank'); a.href = a.href.replace('#_blank', ''); diff --git a/test/utils/utils.test.js b/test/utils/utils.test.js index e11ca57669..8bcae61006 100644 --- a/test/utils/utils.test.js +++ b/test/utils/utils.test.js @@ -414,6 +414,24 @@ describe('Utils', () => { expect(block).to.be.null; expect(document.querySelector('.quote.hide-block')).to.be.null; }); + + it('should convert prod links to stage links on stage env', async () => { + const stageDomainsMap = { + 'www.adobe.com': 'www.stage.adobe.com', + 'blog.adobe.com': 'blog.stage.adobe.com', + 'business.adobe.com': 'business.stage.adobe.com', + 'helpx.adobe.com': 'helpx.stage.adobe.com', + 'news.adobe.com': 'news.stage.adobe.com', + }; + utils.setConfig({ + ...config, + env: { name: 'stage' }, + stageDomainsMap, + }); + const links = Object.keys(stageDomainsMap).map((prodDom) => document.body.appendChild(createTag('a', { href: `https://${prodDom}`, 'data-prod-dom': prodDom }))); + await utils.decorateLinks(document.body); + links.forEach((l) => expect(l.hostname === stageDomainsMap[l.dataset.prodDom]).to.be.true); + }); }); describe('title-append', async () => {