File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -455,8 +455,15 @@ const getRepoPath = (url: URL | Location = location): string | undefined => {
455
455
return undefined ;
456
456
} ;
457
457
458
- /** Get the 'user/repo' part from an URL */
459
- const getRepoURL = ( url : URL | Location = location ) : string => url . pathname . slice ( 1 ) . split ( '/' , 2 ) . join ( '/' ) ;
458
+ /** Get the 'user/repo' part from an URL. Tries using the canonical URL to avoid capitalization errors in the `location` URL */
459
+ const getRepoURL = ( url ?: URL | Location ) : string => {
460
+ if ( ! url ) {
461
+ const canonical = document . querySelector < HTMLMetaElement > ( '[property="og:url"]' ) ; // `rel=canonical` doesn't appear on every page
462
+ url = canonical ? new URL ( canonical . content ) : location ;
463
+ }
464
+
465
+ return url . pathname . slice ( 1 ) . split ( '/' , 2 ) . join ( '/' ) ;
466
+ } ;
460
467
461
468
export const utils = {
462
469
getUsername,
You can’t perform that action at this time.
0 commit comments