Skip to content

Commit 0cb14ce

Browse files
committed
Fix version and error handling
1 parent 55e9645 commit 0cb14ce

File tree

2 files changed

+98
-57
lines changed

2 files changed

+98
-57
lines changed
Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1+
{{/* Should match baseof.html but have breadcrumbs, toc, and main block removed */ -}}
2+
{{ partial "shortcodes/version.html" (dict "page" .Page) -}}
3+
{{ $isProduction := eq site.BaseURL "https://docs.arango.ai" -}}
14

25
<!DOCTYPE html>
36
<html lang="{{ .Page.Language | default "en" }}">
4-
5-
<head>
6-
{{- partialCached "stylesheet.html" . }}
7-
{{- partial "meta.html" . }}
8-
{{- partialCached "favicon.html" . }}
9-
{{- partialCached "javascript.html" . }}
10-
</head>
11-
12-
<body>
7+
{{ partial "head.html" . -}}
8+
<body>
9+
{{ if $isProduction }}{{ partialCached "tracking/body-start.html" . }}{{ end -}}
1310
<noscript>You need to enable JavaScript to use the Arango documentation.</noscript>
14-
<div class="page-wrapper page_content_splash" style="height: auto;opacity: 1;">
15-
<section class="page-main">
16-
<section class="page-container">
17-
{{ partialCached "header.html" . }}
18-
<iframe src="/nav.html" title="description" class="menu-iframe active" style="opacity: 0;"></iframe>
19-
20-
21-
<div class="container-main">
22-
<div class="row-main">
23-
</div>
24-
</main><!-- #body-inner -->
25-
</div><!-- #body -->
26-
{{- partialCached "back-to-top.html" . }}
27-
{{ partialCached "search.html" . }}
28-
</body>
29-
</html>
11+
<div class="page-wrapper page_content_splash" style="height: auto; opacity: 1;">
12+
<section class="page-main">
13+
<section class="page-container">
14+
{{ partialCached "header.html" . -}}
15+
<nav class="main-nav" aria-label="Main"></nav>
16+
<div class="container-main">
17+
<div class="row-main"></div>
18+
</div>
19+
</section>
20+
</section>
21+
</div>
22+
{{ partialCached "back-to-top.html" . -}}
23+
{{ partialCached "search.html" . -}}
24+
{{ if $isProduction }}{{ partialCached "tracking/body-end.html" . }}{{ end -}}
25+
</body>
26+
</html>

site/themes/arangodb-docs-theme/static/js/theme.js

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ function loadPage(target) {
9292

9393
fetch(href)
9494
.then(response => {
95+
if (!response.ok) {
96+
// Handle 404 and other HTTP errors
97+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
98+
}
9599
if (response.url && href.replace(/#.*/, "") !== response.url) {
96100
updateHistory(response.url.replace(version, getVersionFromURL()));
97101
return;
@@ -112,14 +116,26 @@ function loadPage(target) {
112116
return true;
113117
})
114118
.catch(error => {
115-
loadNotFoundPage(href)
119+
console.error('Error loading page:', error);
120+
loadNotFoundPage(href);
116121
});
117122
}
118123

119124
function getSelectedVersion() {
120125
const version = getVersionFromURL();
121126
if (version) return version;
122127
return localStorage.getItem("docs-version") ?? "stable";
128+
129+
/*
130+
const storedVersion = localStorage.getItem("docs-version");
131+
let alias = "stable";
132+
if (version) {
133+
alias = getVersionInfo(version).alias;
134+
} else if (storedVersion) {
135+
alias = getVersionInfo(storedVersion).alias;
136+
}
137+
return alias;
138+
*/
123139
}
124140

125141
function updateActiveNavItem(pathname) {
@@ -139,35 +155,58 @@ function updateActiveNavItem(pathname) {
139155
}
140156

141157
async function loadNav() {
142-
const res = await fetch("/nav.html");
143-
if (!res.ok) {
144-
throw new Error("Failed to fetch navigation");
158+
const mainNavPlaceholder = document.querySelector(".main-nav");
159+
if (!mainNavPlaceholder) {
160+
console.error("Main navigation placeholder not found");
161+
return;
145162
}
146-
const text = await res.text();
147-
const doc = new DOMParser().parseFromString(text, "text/html");
148-
const mainNavContent = doc.querySelector(".main-nav-ol");
149-
// TODO: Support multiple versions
150-
const selectedVersion = getSelectedVersion();
151-
const versionSelector = mainNavContent.querySelector(".version-selector");
152-
if (versionSelector && versionSelector.querySelector(`option[value="${selectedVersion}"]`)) {
153-
versionSelector.value = selectedVersion;
163+
164+
try {
165+
const res = await fetch(window.location.origin + "/nav.html");
166+
if (!res.ok) {
167+
mainNavPlaceholder.textContent = "Failed to fetch navigation";
168+
return;
169+
}
170+
const text = await res.text();
171+
const doc = new DOMParser().parseFromString(text, "text/html");
172+
173+
const mainNavContent = doc.querySelector(".main-nav-ol");
174+
if (!mainNavContent) {
175+
mainNavPlaceholder.textContent = "Failed to find navigation content";
176+
return;
177+
}
178+
179+
// TODO: Support multiple versions
180+
const selectedVersion = getSelectedVersion();
181+
const versionInfo = getVersionInfo(selectedVersion);
182+
if (!versionInfo) {
183+
console.log("Selected version not found in version info");
184+
}
185+
const selectedVersionAlias = versionInfo.alias;
186+
const versionSelector = mainNavContent.querySelector(".version-selector");
187+
if (versionSelector && versionSelector.querySelector(`option[value="${selectedVersionAlias}"]`)) {
188+
versionSelector.value = selectedVersionAlias;
189+
190+
versionSelector.parentElement.querySelectorAll(":scope > .nav-ol").forEach(navList => {
191+
if (navList.dataset.version == selectedVersion) {
192+
navList.classList.add("selected-version");
193+
} else {
194+
navList.classList.remove("selected-version");
195+
}
196+
});
197+
} else {
198+
console.log("Selected/stored version not available in version selector");
199+
}
200+
201+
mainNavPlaceholder.appendChild(mainNavContent);
154202

155-
versionSelector.parentElement.querySelectorAll(":scope > .nav-ol").forEach(navList => {
156-
if (navList.dataset.version == selectedVersion) {
157-
navList.classList.add("selected-version");
158-
} else {
159-
navList.classList.remove("selected-version");
160-
}
161-
});
162-
} else {
163-
throw new Error("Stored version not available in version selector");
203+
// Set initial active state
204+
updateActiveNavItem(window.location.pathname);
205+
} catch (error) {
206+
console.error("Error loading navigation:", error);
207+
mainNavPlaceholder.textContent = "Failed to load navigation";
164208
}
165-
166-
const mainNavPlaceholder = document.querySelector(".main-nav");
167-
mainNavPlaceholder.appendChild(mainNavContent);
168-
169-
// Set initial active state
170-
updateActiveNavItem(window.location.pathname);
209+
return true;
171210
}
172211

173212
function trackPageView(title, urlPath) {
@@ -461,12 +500,12 @@ function linkToVersionedContent() {
461500
const originalUrl = el.getAttribute("href");
462501
const matches = originalUrl.match(/^\/arangodb\/(.+?)(\/.*)/);
463502
const previousVersion = localStorage.getItem('docs-version') ?? "stable";
464-
if (matches && matches.length > 2 && previousVersion) {
503+
if (matches && matches.length > 2 && previousVersion) {
465504
const newUrl = "/arangodb/" + previousVersion + matches[2];
466505
console.log("linkToVersionedContent: " + originalUrl + " -> " + newUrl);
467506
el.setAttribute("href", newUrl);
468-
}
469-
});
507+
}
508+
});
470509
}
471510
}
472511

@@ -477,6 +516,8 @@ function handleDocumentChange(event) {
477516
const currentPath = window.location.pathname;
478517
//const versionedPath = target.dataset.path;
479518

519+
window.setupDocSearch(selectedVersion);
520+
480521
localStorage.setItem('docs-version', selectedVersion); // TODO: handle multiple
481522
target.closest(".nav-section").querySelectorAll(":scope > .nav-ol").forEach(
482523
el => {
@@ -622,12 +663,15 @@ function handleDocumentClick(event) {
622663

623664
window.onload = () => {
624665

625-
loadNav();
666+
loadNav().catch(err => console.error("Failed to initialize navigation:", err));
626667

627668
window.history.pushState("popstate", "Arango Documentation", window.location.href);
628669
trackPageView(document.title, window.location.pathname);
629670

630-
getCurrentVersion(window.location.href);
671+
const currentVersion = getVersionFromURL();
672+
if (currentVersion) {
673+
localStorage.setItem('docs-version', currentVersion);
674+
}
631675

632676
loadPage(window.location.href)
633677

0 commit comments

Comments
 (0)