From 2123ba978da370cd14f75005a39668be77013939 Mon Sep 17 00:00:00 2001 From: Rob Bos Date: Wed, 21 Aug 2024 13:13:46 +0200 Subject: [PATCH] fix for prod --- public/404.html | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/public/404.html b/public/404.html index aadafb2..d0f0857 100644 --- a/public/404.html +++ b/public/404.html @@ -6,26 +6,32 @@ // Redirect to the correct URL var pathname = window.location.pathname; var search = window.location.search; - + // Remove leading slash from pathname if it exists if (pathname.startsWith('/')) { pathname = pathname.substring(1); } - - // Construct the new URL - let basePath = '/copilot-videos/#' + pathname.replace('copilot-videos', ''); - // If there are double slashes anywhere in the url, remove one + console.log(`pathname: ${basePath}`); + + // Construct the new URL (only needed for forks with a subfolder, should not be used on https://github-copilot.xebia.ms!) + let basePath = '/'; + if (!pathname.startsWith('https://github-copilot.xebia.ms')) { + // Redirect to the root of the fork + basePath = '/copilot-videos/#' + pathname.replace('copilot-videos', ''); + } + + // If there are double slashes anywhere in the url, remove them if (basePath.includes('//')) { basePath = basePath.replace('//', '/'); } // log the parts for debugging console.log(`search: ${search}`); - console.log(`pathname: ${basePath}`); - + console.log(`basePath: ${basePath}`); + // Build the new URL const url = search ? basePath + search : basePath; console.log(`redirecting to url: ${url}`); - + // Redirect to the new URL window.location.href = url;