Skip to content

Commit b1ba1cc

Browse files
authored
Merge pull request #955 from ArmDeveloperEcosystem/copy-link-url
environment specific changes copy url
2 parents 2f6068f + a0405fa commit b1ba1cc

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

  • themes/arm-design-system-hugo-theme

themes/arm-design-system-hugo-theme/layouts/partials/package-display/table.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<tbody id="sw-tablebody">
1414
{{ $id_index := 0}}
1515
{{ $os := .context.Params.os }}
16-
{{ $dashboard_page_path := .context.RelPermalink }}
16+
{{ $dashboard_page_path := .context.RelPermalink | strings.TrimRight "/" }}
1717
{{ if eq .context.Site.BaseURL "/" }}
1818
{{ $base_path := (.context.Site.Params.dashboard_base_path | default "/ecosystem-dashboard") | strings.TrimRight "/" }}
1919
{{ if ne $base_path "" }}

themes/arm-design-system-hugo-theme/static/js/eco-dashboard/search.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ function normalizePackageName(input) {
5858
.toLowerCase(); // Convert to lowercase
5959
}
6060

61+
function shouldUseTrailingSlashForPackageUrl() {
62+
const currentHost = window.location.hostname.toLowerCase();
63+
return currentHost.includes('cloudfront.net');
64+
}
65+
6166
function getDashboardPath(dashboardPath) {
6267
let normalizedPath = dashboardPath;
6368

@@ -74,12 +79,36 @@ function getDashboardPath(dashboardPath) {
7479
normalizedPath = '/' + normalizedPath;
7580
}
7681

77-
if (!normalizedPath.endsWith('/')) {
82+
normalizedPath = normalizedPath.replace(/\/+$/, '') || '/';
83+
84+
if (normalizedPath !== '/' && shouldUseTrailingSlashForPackageUrl()) {
7885
normalizedPath = normalizedPath + '/';
7986
}
8087

8188
return normalizedPath;
8289
}
90+
91+
function normalizeDashboardUrlInAddressBar() {
92+
const currentPath = window.location.pathname;
93+
if (!currentPath || currentPath === '/') {
94+
return;
95+
}
96+
97+
let normalizedPath = currentPath.replace(/\/+$/, '') || '/';
98+
if (normalizedPath !== '/' && shouldUseTrailingSlashForPackageUrl()) {
99+
normalizedPath = normalizedPath + '/';
100+
}
101+
102+
if (normalizedPath === currentPath) {
103+
return;
104+
}
105+
106+
window.history.replaceState(
107+
window.history.state,
108+
'',
109+
normalizedPath + window.location.search + window.location.hash
110+
);
111+
}
83112

84113
function buildPackageDashboardUrl(packageSlug, dashboardPath) {
85114
const packageUrl = new URL(window.location.href);
@@ -755,6 +784,8 @@ function ifNeededMoveFiltersToMobileOrDesktop(state_is_below_breakpoint) {
755784
*/
756785
document.addEventListener("DOMContentLoaded", function () {
757786

787+
normalizeDashboardUrlInAddressBar();
788+
758789

759790

760791
// 1

0 commit comments

Comments
 (0)