1
1
import reservedNames from 'github-reserved-names/reserved-names.json' with { type : 'json' } ;
2
- import punycode from 'punycode.js' ;
3
2
4
3
const patchDiffRegex = / [ . ] ( p a t c h | d i f f ) $ / ;
5
4
const releaseRegex = / ^ r e l e a s e s [ / ] t a g [ / ] ( [ ^ / ] + ) / ;
@@ -159,12 +158,13 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
159
158
* Shorten URL
160
159
*/
161
160
if ( isReserved || pathname === '/' || ( ! isLocal && ! isRaw && ! isRedirection ) ) {
161
+ const origin = href . split ( '/' , 3 ) . join ( '/' ) ;
162
162
const parsedUrl = new URL ( href ) ;
163
163
const cleanHref = [
164
- parsedUrl . origin
164
+ origin
165
165
. replace ( / ^ h t t p s : [ / ] [ / ] / , '' )
166
166
. replace ( / ^ w w w [ . ] / , '' ) ,
167
- parsedUrl . pathname
167
+ decodeURI ( parsedUrl . pathname )
168
168
. replace ( / [ / ] $ / , '' ) ,
169
169
] ;
170
170
@@ -175,15 +175,9 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
175
175
cleanHref . push ( parsedUrl . search ) ;
176
176
}
177
177
178
- cleanHref . push ( parsedUrl . hash ) ;
178
+ cleanHref . push ( decodeURI ( parsedUrl . hash ) ) ;
179
179
180
- // The user prefers seeing the URL as it was typed, so we need to decode it
181
- try {
182
- return decodeURI ( cleanHref . map ( x => punycode . toUnicode ( x ) ) . join ( '' ) ) ;
183
- } catch {
184
- // Decoding fails if the URL includes '%%'
185
- return href ;
186
- }
180
+ return cleanHref . join ( '' ) ;
187
181
}
188
182
189
183
if ( user && ! repo ) {
@@ -324,7 +318,7 @@ export function applyToLink(a, currentUrl) {
324
318
// And if there are no additional images in the link
325
319
&& ! a . firstElementChild
326
320
) {
327
- const url = getLinkHref ( a ) ;
321
+ const url = a . textContent ;
328
322
const shortened = shortenRepoUrl ( url , currentUrl ) ;
329
323
a . replaceChildren (
330
324
...shortened . split (
0 commit comments