Skip to content

Commit

Permalink
MWPW-108710 - Handle Emdashes
Browse files Browse the repository at this point in the history
* Change makeRelative to swap emdashes for double hyphen.

Resolves: MWPW-108710
  • Loading branch information
auniverseaway committed Apr 22, 2022
1 parent 2993a1f commit 98b92dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ export async function loadBlock(block) {
}

export function makeRelative(href) {
const fixedHref = href.replace(/\u2013|\u2014/g, '--');
const hosts = [`${PROJECT_NAME}.hlx.page`, `${PROJECT_NAME}.hlx.live`, ...PRODUCTION_DOMAINS];
const url = new URL(href);
const url = new URL(fixedHref);
const relative = hosts.some((host) => url.hostname.includes(host));
return relative ? `${url.pathname}${url.search}${url.hash}` : href;
}
Expand Down
6 changes: 6 additions & 0 deletions test/scripts/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ describe('Utilities', () => {
expect(scripts.getMetadata('og:title')).to.equal('Milo');
expect(scripts.getMetadata('description')).to.equal('Website foundation technology.');
});

it('Makes relative URLs', () => {
const emdashHref = 'https://main—milo—adobecom.hlx.page/img/bg-dots.svg';
const relativeUrl = scripts.makeRelative(emdashHref);
expect(relativeUrl).to.equal('/img/bg-dots.svg');
});
});

0 comments on commit 98b92dc

Please sign in to comment.