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
3 changes: 3 additions & 0 deletions libs/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
// Production Domain
const prodDomains = ['milo.adobe.com'];

const stageDomainsMap = { 'www.adobe.com': 'www.stage.adobe.com' };
robert-bogos marked this conversation as resolved.
Show resolved Hide resolved

const locales = {
'': { ietf: 'en-US', tk: 'hah7vzn.css' },
ae_ar: { ietf: 'ar-AE', tk: 'lpk1hwn.css', dir: 'rtl' },
Expand Down Expand Up @@ -127,6 +129,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
7 changes: 7 additions & 0 deletions test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ 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 links = document.body.querySelectorAll('a[href*="www.adobe.com"]');
utils.setConfig({ ...config, env: { name: 'stage' }, stageDomainsMap: { 'www.adobe.com': 'www.stage.adobe.com' } });
await utils.decorateLinks(document.body);
for (const link of links) expect(link.hostname === 'www.stage.adobe.com').to.be.true;
robert-bogos marked this conversation as resolved.
Show resolved Hide resolved
});
});

describe('title-append', async () => {
Expand Down
Loading