diff options
-rw-r--r-- | source/features/forked-to.tsx | 18 | ||||
-rw-r--r-- | source/github-helpers/github-url.ts | 2 |
2 files changed, 9 insertions, 11 deletions
diff --git a/source/features/forked-to.tsx b/source/features/forked-to.tsx index fd009f3d..6241a147 100644 --- a/source/features/forked-to.tsx +++ b/source/features/forked-to.tsx @@ -31,18 +31,16 @@ const updateCache = cache.function(async (): Promise<string[] | undefined> => { }); function createLink(baseRepo: string): string { - if (pageDetect.isRepoRoot() || !(pageDetect.isSingleFile() || pageDetect.isRepoTree())) { - return '/' + baseRepo; + if (pageDetect.isSingleFile() || pageDetect.isRepoTree() || pageDetect.isEditingFile()) { + const [user, repository] = baseRepo.split('/', 2); + const url = new GitHubURL(location.href).assign({ + user, + repository + }); + return url.pathname; } - const [user, repository] = baseRepo.split('/'); - const url = new GitHubURL(location.href).assign({ - user, - repository, - branch: 'HEAD' - }); - - return url.pathname; + return '/' + baseRepo; } async function updateUI(forks: string[]): Promise<void> { diff --git a/source/github-helpers/github-url.ts b/source/github-helpers/github-url.ts index 97c347a0..489f4f9e 100644 --- a/source/github-helpers/github-url.ts +++ b/source/github-helpers/github-url.ts @@ -67,7 +67,7 @@ export default class GitHubURL { } get pathname() { - return `/${this.user}/${this.repository}/${this.route}/${this.branch}/${this.filePath}`.replace(/\/+$/, ''); + return `/${this.user}/${this.repository}/${this.route}/${this.branch}/${this.filePath}`.replace(/((undefined)?\/)+$/g, ''); } set pathname(pathname) { |