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

24 lines
628 B
JavaScript
Raw Normal View History

2021-08-19 13:43:42 +00:00
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)