diff --git a/themes/arm-design-system-hugo-theme/layouts/partials/package-display/table.html b/themes/arm-design-system-hugo-theme/layouts/partials/package-display/table.html index e4dbc76370..352a790d6c 100644 --- a/themes/arm-design-system-hugo-theme/layouts/partials/package-display/table.html +++ b/themes/arm-design-system-hugo-theme/layouts/partials/package-display/table.html @@ -13,7 +13,7 @@ {{ $id_index := 0}} {{ $os := .context.Params.os }} - {{ $dashboard_page_path := .context.RelPermalink }} + {{ $dashboard_page_path := .context.RelPermalink | strings.TrimRight "/" }} {{ if eq .context.Site.BaseURL "/" }} {{ $base_path := (.context.Site.Params.dashboard_base_path | default "/ecosystem-dashboard") | strings.TrimRight "/" }} {{ if ne $base_path "" }} diff --git a/themes/arm-design-system-hugo-theme/static/js/eco-dashboard/search.js b/themes/arm-design-system-hugo-theme/static/js/eco-dashboard/search.js index eb27ad50b3..f921b3a529 100644 --- a/themes/arm-design-system-hugo-theme/static/js/eco-dashboard/search.js +++ b/themes/arm-design-system-hugo-theme/static/js/eco-dashboard/search.js @@ -58,6 +58,11 @@ function normalizePackageName(input) { .toLowerCase(); // Convert to lowercase } +function shouldUseTrailingSlashForPackageUrl() { + const currentHost = window.location.hostname.toLowerCase(); + return currentHost.includes('cloudfront.net'); +} + function getDashboardPath(dashboardPath) { let normalizedPath = dashboardPath; @@ -74,12 +79,36 @@ function getDashboardPath(dashboardPath) { normalizedPath = '/' + normalizedPath; } - if (!normalizedPath.endsWith('/')) { + normalizedPath = normalizedPath.replace(/\/+$/, '') || '/'; + + if (normalizedPath !== '/' && shouldUseTrailingSlashForPackageUrl()) { normalizedPath = normalizedPath + '/'; } return normalizedPath; } + +function normalizeDashboardUrlInAddressBar() { + const currentPath = window.location.pathname; + if (!currentPath || currentPath === '/') { + return; + } + + let normalizedPath = currentPath.replace(/\/+$/, '') || '/'; + if (normalizedPath !== '/' && shouldUseTrailingSlashForPackageUrl()) { + normalizedPath = normalizedPath + '/'; + } + + if (normalizedPath === currentPath) { + return; + } + + window.history.replaceState( + window.history.state, + '', + normalizedPath + window.location.search + window.location.hash + ); +} function buildPackageDashboardUrl(packageSlug, dashboardPath) { const packageUrl = new URL(window.location.href); @@ -755,6 +784,8 @@ function ifNeededMoveFiltersToMobileOrDesktop(state_is_below_breakpoint) { */ document.addEventListener("DOMContentLoaded", function () { + normalizeDashboardUrlInAddressBar(); + // 1