Skip to content

Commit 29250bd

Browse files
committed
Trigger setupDocSearch on more events and don't pass an object when a version is expected
1 parent 6b341db commit 29250bd

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

site/themes/arangodb-docs-theme/layouts/partials/search.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3" />
2-
32
<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>
43

54
<script type="text/javascript">
65
window.setupDocSearch = function (facetVersion) {
7-
if (!window.docsearch) return;
6+
if (!window.docsearch) {
7+
return;
8+
}
9+
if (window.setupDocSearch.previousVersion && window.setupDocSearch.previousVersion == facetVersion) {
10+
return;
11+
}
12+
window.setupDocSearch.previousVersion = facetVersion;
813
docsearch({
914
appId: "OK3ZBQ5982",
1015
apiKey: "500c85ccecb335d507fe4449aed12e1d",

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ function loadPage(target) {
110110
updateHistory(match);
111111
return;
112112
}
113-
replaceArticle(href, newDoc)
113+
replaceArticle(href, newDoc);
114114
scrollToFragment();
115115
initArticle(href);
116+
if (window.setupDocSearch) {
117+
window.setupDocSearch(getSelectedVersion());
118+
}
116119
return true;
117120
})
118121
.catch(error => {
@@ -538,9 +541,10 @@ function handleDocumentChange(event) {
538541
const currentPath = window.location.pathname;
539542
//const versionedPath = target.dataset.path;
540543

541-
window.setupDocSearch(selectedVersion); // TODO: Only if on versioned page?
542-
543544
localStorage.setItem('docs-version', selectedVersion); // TODO: handle multiple
545+
if (window.setupDocSearch) {
546+
window.setupDocSearch(selectedVersion);
547+
}
544548
target.closest(".nav-section").querySelectorAll(":scope > .nav-ol").forEach(
545549
el => {
546550
if (el.dataset.version == selectedVersion) {
@@ -684,11 +688,8 @@ window.onload = () => {
684688

685689
loadPage(window.location.href)
686690

687-
window.setupDocSearch(currentVersion ?? stableVersion);
688-
689691
// Add central click handler to document
690692
document.addEventListener("click", handleDocumentClick);
691-
692693
document.addEventListener("change", handleDocumentChange);
693694

694695
var isMobile = window.innerWidth <= 768;

0 commit comments

Comments
 (0)