Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWPW-146056] Links are not converted to their stage counterparts #2361

Merged
merged 13 commits into from
Jun 5, 2024
Merged
9 changes: 9 additions & 0 deletions libs/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ import {
// Production Domain
const prodDomains = ['milo.adobe.com'];

const stageDomainsMap = {
robert-bogos marked this conversation as resolved.
Show resolved Hide resolved
'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' },
Expand Down Expand Up @@ -127,6 +135,7 @@ const config = {
codeRoot: '/libs',
locales,
prodDomains,
stageDomainsMap,
jarvis: {
id: 'milo',
version: '1.0',
Expand Down
4 changes: 4 additions & 0 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
robert-bogos marked this conversation as resolved.
Show resolved Hide resolved
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', '');
Expand Down
18 changes: 18 additions & 0 deletions test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Loading