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

39 lines
1003 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')
2021-08-19 14:31:28 +00:00
wrapper.className = "article"
extra_info = document.createElement('p')
extra_info.className = "smallText"
extra_info.innerHTML = "tags: "
if (r.item.tags == null) {
extra_info.innerHTML += "none"
} else {
extra_info.innerHTML += "[" + r.item.tags.join(', ') + ']'
}
extra_info.innerHTML += ' path: ' + r.item.path
2021-08-19 13:43:42 +00:00
content = document.createElement('a')
content.innerHTML = r.item.title
content.href = r.item.path
2021-08-19 14:31:28 +00:00
2021-08-19 13:43:42 +00:00
wrapper.appendChild(content)
2021-08-19 14:31:28 +00:00
wrapper.appendChild(extra_info)
2021-08-19 13:43:42 +00:00
results.appendChild(wrapper)
})
}
searchBar.addEventListener('keyup', callback)
2021-08-19 14:31:28 +00:00
callback()