Skip to content

Commit e63b6c7

Browse files
committed
maybe this time will be different
1 parent 9359169 commit e63b6c7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

assets/static/search.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
async function loadIndex() {
3-
const response = await fetch(`${getBaseUrl()}/${getLang()}/search_index.json`);
3+
const response = await fetch(buildUrl(`/${getLang()}/search_index.json`));
44
return response.json();
55
}
66

@@ -20,7 +20,12 @@ function isLocal() {
2020
}
2121

2222
function getBaseUrl() {
23-
return isLocal() ? '' : 'Field-Guide';
23+
return isLocal() ? '' : '/Field-Guide';
24+
}
25+
26+
function buildUrl(path) {
27+
const baseUrl = getBaseUrl();
28+
return baseUrl ? `${baseUrl}${path}` : path;
2429
}
2530

2631
function boldQuery(text, query) {
@@ -65,16 +70,13 @@ document.getElementById('search-box').addEventListener('keydown', function (e) {
6570
const query = encodeURIComponent(this.value.trim());
6671
if (!query) return;
6772

68-
const target = `${getBaseUrl()}/${getLang()}/search.html?q=${query}`;
69-
70-
window.location.href = target;
73+
window.location.href = buildUrl(`/${getLang()}/search.html?q=${query}`);
7174
}
7275
});
7376

7477
function handleSearch(e) {
7578
e.preventDefault(); // Prevent page reload
7679
const query = document.getElementById('search-box').value.trim();
7780
if (!query) return;
78-
const target = `${getBaseUrl()}/${getLang()}/search.html?q=${query}`;
79-
window.location.href = target;
81+
window.location.href = buildUrl(`/${getLang()}/search.html?q=${query}`);
8082
}

0 commit comments

Comments
 (0)