From bac52b092c3b95b811bfe386751773893713b136 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 30 Jan 2025 12:35:06 -0400 Subject: client: make rebase() a bit more sensible --- src/static/js/client-util.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/static/js/client-util.js b/src/static/js/client-util.js index f06b707a..71112313 100644 --- a/src/static/js/client-util.js +++ b/src/static/js/client-util.js @@ -1,12 +1,19 @@ /* eslint-env browser */ export function rebase(href, rebaseKey = 'rebaseLocalized') { - const relative = (document.documentElement.dataset[rebaseKey] || '.') + '/'; - if (relative) { - return relative + href; - } else { - return href; + let result = document.documentElement.dataset[rebaseKey] || './'; + + if (!result.endsWith('/')) { + result += '/'; + } + + if (href.startsWith('/')) { + href = href.slice(1); } + + result += href; + + return result; } export function cssProp(el, ...args) { -- cgit 1.3.0-6-gf8a5