Makes the webpack build use relative paths to allow for deploying on web subdirectories
Some checks are pending
build-docker / Build Image (push) Waiting to run

This commit is contained in:
mrkmntal 2026-04-08 21:31:56 -04:00
commit ea8c3bf602
10 changed files with 74 additions and 36 deletions

View file

@ -0,0 +1,25 @@
const normalizeBasePath = (pathname) => {
if (!pathname) return '/';
if (pathname.endsWith('/index.html')) {
const trimmed = pathname.slice(0, -'index.html'.length);
return trimmed.endsWith('/') ? trimmed : `${trimmed}/`;
}
if (pathname.endsWith('/')) return pathname;
const lastSlash = pathname.lastIndexOf('/');
if (lastSlash === -1) return '/';
return `${pathname.slice(0, lastSlash + 1)}`;
};
const getBasePath = () => normalizeBasePath(window.location.pathname);
const withBasePath = (relativePath = '') => {
const sanitizedPath = relativePath.replace(/^\/+/, '');
const basePath = getBasePath();
if (basePath === '/') return `/${sanitizedPath}`;
return `${basePath}${sanitizedPath}`;
};
export {
getBasePath,
withBasePath,
};