This repository has been archived on 2024-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
notes2web/search.js
2021-08-19 14:43:42 +01:00

24 lines
628 B
JavaScript

const fuse = new Fuse(data, {
keys: ['path', 'title', 'tags']
})
const searchBar = document.getElementById('search')
const results = document.getElementById('results')
function callback() {
console.log("called")
console.log(searchBar.value)
results.innerHTML = ''
fuse.search(searchBar.value).forEach(r => {
wrapper = document.createElement('div')
content = document.createElement('a')
content.innerHTML = r.item.title
content.href = r.item.path
wrapper.appendChild(content)
wrapper.className = "article"
results.appendChild(wrapper)
})
}
searchBar.addEventListener('keyup', callback)