Skip to content

Commit

Permalink
Drop ?tab=readme-ov-file from isRepoHome links (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute committed Sep 12, 2023
1 parent 838eb0f commit 2c44c2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ function shortenURL(href, currentUrl = 'https://github.com') {
query = ` (${query.replaceAll(/\s+/g, ' ').trim()})`;
}

if (searchParams.get('tab') === 'readme-ov-file') {
searchParams.delete('tab');
}

// Drop leading and trailing slash of relative path
return pathname.replaceAll(/^[/]|[/]$/g, '') + url.search + hash + query;
}
Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ test('GitHub.com URLs', urlMatcherMacro, new Map([
'https://github.com/fregante/shorten-repo-url/',
'fregante/shorten-repo-url',
],
[
'https://github.com/fregante/shorten-repo-url/?tab=readme-ov-file',
'fregante/shorten-repo-url',
],
[
'https://github.com/fregante/shorten-repo-url/tree/v0.12',
'<code>v0.12</code>',
Expand Down

0 comments on commit 2c44c2f

Please sign in to comment.