diff --git a/libs/scripts/scripts.js b/libs/scripts/scripts.js index 2c62d13178..bb4e690d87 100644 --- a/libs/scripts/scripts.js +++ b/libs/scripts/scripts.js @@ -19,7 +19,7 @@ import { import locales from '../utils/locales.js'; // Production Domain -const prodDomains = ['milo.adobe.com']; +const prodDomains = ['milo.adobe.com', 'business.adobe.com', 'www.adobe.com']; const stageDomainsMap = { 'www.stage.adobe.com': { diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 3da9d8bada..1d0e9b111b 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -647,21 +647,27 @@ const decorateCopyLink = (a, evt) => { }; export function convertStageLinks({ anchors, config, hostname, href }) { - if (config.env?.name === 'prod' || !config.stageDomainsMap) return; - const matchedRules = Object.entries(config.stageDomainsMap) + const { env, stageDomainsMap, locale } = config; + if (env?.name === 'prod' || !stageDomainsMap) return; + const matchedRules = Object.entries(stageDomainsMap) .find(([domain]) => (new RegExp(domain)).test(href)); if (!matchedRules) return; const [, domainsMap] = matchedRules; [...anchors].forEach((a) => { + const hasLocalePrefix = a.pathname.startsWith(locale.prefix); + const noLocaleLink = hasLocalePrefix ? a.href.replace(locale.prefix, '') : a.href; const matchedDomain = Object.keys(domainsMap) - .find((domain) => (new RegExp(domain)).test(a.href)); + .find((domain) => (new RegExp(domain)).test(noLocaleLink)); if (!matchedDomain) return; - a.href = a.href.replace( + const convertedLink = noLocaleLink.replace( new RegExp(matchedDomain), domainsMap[matchedDomain] === 'origin' ? `${matchedDomain.includes('https') ? 'https://' : ''}${hostname}` : domainsMap[matchedDomain], ); + const convertedUrl = new URL(convertedLink); + convertedUrl.pathname = `${hasLocalePrefix ? locale.prefix : ''}${convertedUrl.pathname}`; + a.href = convertedUrl.toString(); if (/(\.page|\.live).*\.html(?=[?#]|$)/.test(a.href)) a.href = a.href.replace(/\.html(?=[?#]|$)/, ''); }); } diff --git a/test/utils/utils.test.js b/test/utils/utils.test.js index c211ddbf76..196d44df8b 100644 --- a/test/utils/utils.test.js +++ b/test/utils/utils.test.js @@ -537,16 +537,18 @@ describe('Utils', () => { it('should convert links when stageDomainsMap provided without regex', async () => { const stageConfig = { ...config, + locale: { prefix: '/ae_ar' }, env: { name: 'stage' }, stageDomainsMap, }; Object.entries(stageDomainsMap).forEach(([hostname, domainsMap]) => { const anchors = Object.keys(domainsMap).map((d) => utils.createTag('a', { href: `https://${d}` })); + const localizedAnchors = Object.keys(domainsMap).map((d) => utils.createTag('a', { href: `https://${d}/ae_ar` })); const externalAnchors = externalDomains.map((url) => utils.createTag('a', { href: url })); utils.convertStageLinks({ - anchors: [...anchors, ...externalAnchors], + anchors: [...anchors, ...localizedAnchors, ...externalAnchors], config: stageConfig, hostname, href: `https://${hostname}`, @@ -565,16 +567,22 @@ describe('Utils', () => { const { hostname, map } = stageDomainsMapWRegex; const stageConfigWRegex = { ...config, + locale: { prefix: '/de' }, env: { name: 'stage' }, stageDomainsMap: map, }; Object.entries(map).forEach(([, domainsMap]) => { const anchors = Object.keys(domainsMap).map((d) => utils.createTag('a', { href: d.replace('^', '') })); + const localizedAnchors = Object.keys(domainsMap).map((d) => { + const convertedUrl = new URL(d.replace('^', '')); + convertedUrl.pathname = `de/${convertedUrl.pathname}`; + return utils.createTag('a', { href: convertedUrl.toString() }); + }); const externalAnchors = externalDomains.map((url) => utils.createTag('a', { href: url })); utils.convertStageLinks({ - anchors: [...anchors, ...externalAnchors], + anchors: [...anchors, ...localizedAnchors, ...externalAnchors], config: stageConfigWRegex, hostname, href: `https://${hostname}`,