From 940b40688a7cf595eee061b696187e2fe4a578e2 Mon Sep 17 00:00:00 2001 From: Jieiku Date: Mon, 22 May 2023 22:31:34 -0700 Subject: Json-Index and config.toml optional --- static/search.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'static/search.js') diff --git a/static/search.js b/static/search.js index 61c67c0..e6adedf 100644 --- a/static/search.js +++ b/static/search.js @@ -165,11 +165,24 @@ Source: - https://github.com/aaranxu/adidoks/blob/main/static/js/search.js */ (function(){ - var index = elasticlunr.Index.load(window.searchIndex); + //var index = elasticlunr.Index.load(window.searchIndex); + var index; searchinput.addEventListener('input', show_results, true); suggestions.addEventListener('click', accept_suggestion, true); - function show_results(){ + async function show_results(){ + var initIndex = async function () { + if (index === undefined) { + index = fetch("/search_index.en.json") + .then( + async function(response) { + return await elasticlunr.Index.load(await response.json()); + } + ); + } + let res = await index; + return res; + } var value = this.value.trim(); var options = { bool: "OR", @@ -178,7 +191,8 @@ Source: body: {boost: 1}, } }; - var results = index.search(value, options); + //var results = index.search(value, options); + var results = (await initIndex()).search(value, options); var entry, childs = suggestions.childNodes; var i = 0, len = results.length; -- cgit v1.3.1