Skip to content

Commit

Permalink
Detect isRepoRoot on branches with slashes (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
FloEdelmann authored Jul 1, 2020
1 parent 1ceb204 commit 4ff46aa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ collect.set('isRepoHome', [
'https://github.com/sindresorhus/refined-github?files=1',
]);

export const isRepoRoot = (url: URL | Location = location): boolean => /^(tree\/[^/]+)?$/.test(getRepoPath(url)!);
export const isRepoRoot = (url?: URL | Location): boolean =>
/^(tree\/[^/]+)?$/.test(getRepoPath(url ?? location)!) ||
(!url && document.title.startsWith(getRepoURL()) && !document.title.endsWith(getRepoURL())); // #15
collect.set('isRepoRoot', [
...collect.get('isRepoHome') as string[],
'https://github.com/sindresorhus/refined-github/tree/native-copy-buttons',
Expand Down Expand Up @@ -442,7 +444,7 @@ const getCleanPathname = (url: URL | Location = location): string => url.pathnam
/** Parses a repo's subpage
@example '/user/repo/issues/' -> 'issues'
@example '/user/repo/' -> ''
@exampke '/settings/token/' -> undefined
@example '/settings/token/' -> undefined
*/
const getRepoPath = (url: URL | Location = location): string | undefined => {
if (isRepo(url)) {
Expand All @@ -452,8 +454,12 @@ const getRepoPath = (url: URL | Location = location): string | undefined => {
return undefined;
};

/** Get the 'user/repo' part from an URL */
const getRepoURL = (url: URL | Location = location): string => url.pathname.slice(1).split('/', 2).join('/');

export const utils = {
getUsername,
getCleanPathname,
getRepoPath,
getRepoURL,
};

0 comments on commit 4ff46aa

Please sign in to comment.