This commit is contained in:
Thomas Chartron 2021-11-07 19:28:26 +01:00
parent b6a6d58069
commit abe3ad67c6
2 changed files with 5 additions and 4 deletions

View file

@ -57,11 +57,12 @@ document.addEventListener("DOMContentLoaded", function() {
if ([...document.body.classList].includes('search-active') && search_input.value.trim().length > 3) { if ([...document.body.classList].includes('search-active') && search_input.value.trim().length > 3) {
// console.log('search') // console.log('search')
search_term = search_input.value.trim(); search_term = search_input.value.trim();
console.log(search_term) // console.log(search_term)
search_results = search_index.search(search_term, elasticlunr_options); search_results = search_index.search(search_term, elasticlunr_options);
// console.log(search_results) // console.log(search_results)
if (Array.isArray(search_results) && search_results.length > 0) { if (Array.isArray(search_results) && search_results.length > 0) {
let result_list = document.getElementById('results-list'); let result_list = document.getElementById('results-list');
result_list.replaceChildren();
let item = ""; let item = "";
for (i = 0; i < search_results.length; i++) { for (i = 0; i < search_results.length; i++) {
let item = formatResultItem(search_results[i]); let item = formatResultItem(search_results[i]);
@ -91,7 +92,7 @@ function toggleSearchModal () {
function formatResultItem(search_result) { function formatResultItem(search_result) {
console.log(search_result) console.log(search_result)
let formatted_result = `<li class="flex flex-col gap-y-2 hover:shadow-lg"> let formatted_result = `<li class="flex flex-col gap-y-2 hover:bg-white dark:hover:bg-gray-600 text-black dark:text-white">
<span class="text-xl text-bold">${search_result.doc.title}</span> <span class="text-xl text-bold">${search_result.doc.title}</span>
<span class="text-lg">${search_result.doc.description}</span> <span class="text-lg">${search_result.doc.description}</span>
</li>` </li>`

View file

@ -96,8 +96,8 @@
<!-- Modal Body --> <!-- Modal Body -->
<input id="search-input" class="rounded-xl border border-black h-12 text-bold text-2xl pl-2 text-black" type="text"> <input id="search-input" class="rounded-xl border border-black h-12 text-bold text-2xl pl-2 text-black" type="text">
<!-- Search results --> <!-- Search results -->
<div id="search-results" class="flex flex-col gap-y-4 border border-black max-h-2xl"> <div id="search-results">
<ul id="results-list"></ul> <ul id="results-list" class="flex flex-col gap-y-4 max-h-2xl mt-2 divide-y"></ul>
<!--Footer--> <!--Footer-->
<!-- <div class="flex justify-end pt-2"> <!-- <div class="flex justify-end pt-2">
<button class="px-4 bg-transparent p-3 rounded-lg text-indigo-500 hover:bg-gray-100 hover:text-indigo-400 mr-2">Action</button> <button class="px-4 bg-transparent p-3 rounded-lg text-indigo-500 hover:bg-gray-100 hover:text-indigo-400 mr-2">Action</button>