document.addEventListener("DOMContentLoaded", function () { let index = []; // Load JSON index fetch("/index.json") .then((res) => res.json()) .then((data) => { index = data; console.log("Index loaded:", index.length, "posts"); }) .catch((err) => console.error("Error loading index.json", err)); const searchInput = document.getElementById("search"); const resultsList = document.getElementById("results"); function runSearch() { const query = searchInput.value.trim().toLowerCase(); resultsList.innerHTML = ""; if (!query) return; // filter out posts that don't match const matches = index.filter( (post) => post.title.toLowerCase().includes(query) || post.content.toLowerCase().includes(query), ); if (matches.length === 0) { resultsList.innerHTML = "