Remove JSON search file

This commit is contained in:
Guillaume Gomez 2025-02-20 23:07:16 +01:00
parent 43281c85c5
commit a0eb8c0a0e
2 changed files with 13 additions and 12 deletions

View file

@ -64,7 +64,6 @@ pub fn create_files(
} }
if search_config.copy_js { if search_config.copy_js {
static_files.add_builtin("searchindex.json", index.as_bytes());
static_files.add_builtin( static_files.add_builtin(
"searchindex.js", "searchindex.js",
format!("Object.assign(window.search, {});", index).as_bytes(), format!("Object.assign(window.search, {});", index).as_bytes(),

View file

@ -441,7 +441,6 @@ window.search = window.search || {};
} }
function doSearch(searchterm) { function doSearch(searchterm) {
// Don't search the same twice // Don't search the same twice
if (current_searchterm == searchterm) { return; } if (current_searchterm == searchterm) { return; }
else { current_searchterm = searchterm; } else { current_searchterm = searchterm; }
@ -468,15 +467,18 @@ window.search = window.search || {};
showResults(true); showResults(true);
} }
fetch(path_to_root + '{{ resource "searchindex.json" }}') function loadScript(url, id) {
.then(response => response.json()) const script = document.createElement('script');
.then(json => init(json)) script.src = url;
.catch(error => { // Try to load searchindex.js if fetch failed script.id = id;
var script = document.createElement('script'); script.onload = () => init(window.search);
script.src = path_to_root + '{{ resource "searchindex.js" }}'; script.onerror = error => {
script.onload = () => init(window.search); console.error(`Failed to load \`${url}\`: ${error}`);
document.head.appendChild(script); };
}); document.head.append(script);
}
loadScript(path_to_root + '{{ resource "searchindex.js" }}', 'search-index');
// Exported functions // Exported functions
search.hasFocus = hasFocus; search.hasFocus = hasFocus;