Skip to content

Commit

Permalink
Cater for query params and hash
Browse files Browse the repository at this point in the history
  • Loading branch information
amoore108 committed Oct 22, 2024
1 parent 215101a commit 7a134a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ describe('litePageTransforms', () => {
<a href="https://www.bbc.com/serbian/lat">News</a>
<a href="https://www.bbc.com/mundo">News</a>
<a href="https://www.bbcrussian.com/news">News</a>
<a href="https://www.bbc.com/mundo?something=value&another=one#content">News</a>
<a href="/news">News</a>
<a href="/news?something=value&another=one#content">News</a>
`;

const modifiedHtml = litePageTransforms(html);
Expand All @@ -18,7 +20,9 @@ describe('litePageTransforms', () => {
<a href="https://www.bbc.com/serbian/lat.lite">News</a>
<a href="https://www.bbc.com/mundo.lite">News</a>
<a href="https://www.bbcrussian.com/news.lite">News</a>
<a href="https://www.bbc.com/mundo.lite?something=value&another=one#content">News</a>
<a href="/news.lite">News</a>
<a href="/news.lite?something=value&another=one#content">News</a>
`);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ const addLiteExtension = (href?: string) => {
url.pathname += '.lite';

// Retain relative path if passed in 'href' starts with a forward slash
if (href.startsWith('/')) return url.pathname;
if (href.startsWith('/')) {
return `${url.pathname}${url.search}${url.hash}`;
}

// Else return the full URL
return url.href;
return url.toString();
}

return null;
Expand Down

0 comments on commit 7a134a8

Please sign in to comment.