Skip to content

Commit

Permalink
Merge pull request #7 from adobecom/handle-emdash
Browse files Browse the repository at this point in the history
MWPW-108710 - Handle Emdashes
  • Loading branch information
auniverseaway authored Apr 22, 2022
2 parents 2993a1f + 98b92dc commit cf43ae6
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 cf43ae6

Please sign in to comment.