From 27e3ecb36aa3758e97c37bdaf2504cd567a8c4cd Mon Sep 17 00:00:00 2001 From: Federico Date: Mon, 3 Aug 2020 19:45:31 +0100 Subject: [PATCH] Fixes and improvements to `useful-not-found-page` --- source/features/useful-not-found-page.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source/features/useful-not-found-page.tsx b/source/features/useful-not-found-page.tsx index 85b48c5fdb09..f955991fd19a 100644 --- a/source/features/useful-not-found-page.tsx +++ b/source/features/useful-not-found-page.tsx @@ -68,7 +68,7 @@ async function addDefaultBranchLink(bar: Element): Promise { bar.after(

- See also the file on the default branch + See also the object on the default branch

); } @@ -82,8 +82,8 @@ function init(): false | void { const bar =

; for (const [i, part] of parts.entries()) { - if (i === 2 && part === 'tree') { - // `/tree/` is not a real part of the URL + if (i === 2 && ['tree', 'blob', 'edit'].includes(part)) { + // Exclude parts that don't exist as standalones continue; } @@ -103,8 +103,14 @@ function init(): false | void { void checkAnchor(bar.children[i] as HTMLAnchorElement); } - if (parts[2] === 'tree') { + if (parts[2] === 'tree' || parts[2] === 'blob') { + // Object might be 410 Gone void addCommitHistoryLink(bar); + } + + if (parts[2] === 'edit') { + // File might not be available on the current branch + // GitHub already redirects /tree/ and /blob/ natively void addDefaultBranchLink(bar); } }