Files
fundor333.com/static/js/search.min.js
Fundor333 5acba397b4 Add Lunr.js for client-side search functionality and implement search results display
- Integrated Lunr.js library for indexing and searching content.
- Created search.js to handle search queries and display results dynamically.
- Implemented displayResults function to format and show search results.
- Enhanced search functionality with boosted fields for title and content.
- Added search.min.js for optimized production use.
2025-04-18 22:26:40 +02:00

2 lines
914 B
JavaScript

// @ts-nocheck
function displayResults(t,e){const n=document.getElementById("results");if(t.length){let s="";for(const n in t){const i=e[t[n].ref];s+=`\n\t\t<li>\n\t\t <h2>\n\t\t\t<a href="${i.url}">${i.title}</a>\n\t\t </h2>'\n\t\t <p>${i.content.substring(0,150)}...</p>\n\t\t <p>${i.tags}</p>\n\t\t</li>\n\t `}n.innerHTML=s}else n.innerHTML="No results found."}const params=new URLSearchParams(window.location.search),query=params.get("query");if(query){document.getElementById("search-input").setAttribute("value",query);displayResults(lunr((function(){this.ref("id"),this.field("title",{boost:15}),this.field("tags"),this.field("content",{boost:10});for(const t in window.store)this.add({id:t,title:window.store[t].title,tags:window.store[t].category,content:window.store[t].content})})).search(query),window.store),document.getElementById("search-title").innerText="Search Results for "+query}