/* * search.js -- Alternative search results processor for pagefind. * Copyright © 2022 - 2026 Jakob L. Kreuze * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see * . */ window.addEventListener("load", async () => { const pagefind = await import("/_pagefind/pagefind.js"); pagefind.init(); const params = new URLSearchParams(window.location.search); const query = params.get('q'); const outputContainer = document.getElementById('search-output'); if (query) { const search = await pagefind.search(query); if (search.results.length === 0) { outputContainer.innerHTML = `

No results found for "${query}".

`; return; } outputContainer.innerHTML = `

Found ${search.results.length} result(s) for "${query}":

`; for (let result of search.results) { const data = await result.data(); const resultElement = document.createElement('article'); resultElement.className = 'update-entry'; console.log(data); resultElement.innerHTML = `

${data.meta.title}

${data.excerpt} ...

view page →

`; outputContainer.appendChild(resultElement); } } else { outputContainer.innerHTML = `

Searching for '${query}'...

`; } });