diff --git a/contents/static/suche.html b/contents/static/suche.html index e79531e..5728785 100644 --- a/contents/static/suche.html +++ b/contents/static/suche.html @@ -1,225 +1,280 @@ -
${total} Treffer (${questionCards.length} Fragen, ${indexCards.length} Begriffe)
+ ${questionCards.join("")} + ${indexCards.join("")} + `; + } + + async function loadSearchIndices() { + try { + const [questionResponse, indexResponse] = await Promise.all([ + fetch("/assets/question_index.json", { + cache: "no-cache", + headers: { Accept: "application/json" }, + }), + fetch("/assets/index.json", { + cache: "no-cache", + headers: { Accept: "application/json" }, + }), + ]); + + if (!questionResponse.ok) throw new Error("question_index.json: HTTP " + questionResponse.status); + if (!indexResponse.ok) throw new Error("index.json: HTTP " + indexResponse.status); + + const questionData = await questionResponse.json(); + const indexData = await indexResponse.json(); + + questionIndex = questionData || {}; + indexEntries = Array.isArray(indexData) ? indexData : []; + + searchInput.disabled = false; + searchInput.addEventListener("input", renderSearchResults); + searchInput.addEventListener("keydown", (event) => { + if (event.key === "Enter") { + event.preventDefault(); + renderSearchResults(); + } + }); + + renderSearchResults(); + } catch (error) { + errorBox.classList.remove("d-none"); + errorBox.textContent = "Suchindex konnte nicht geladen werden: " + error.message; + console.error("Failed to load search indices", error); + } + } + + loadSearchIndices(); +})(); +