| | |
| | | const idx = [ |
| | | {{- range .Site.Pages }} |
| | | { |
| | | "link": "{{ .Permalink }}", |
| | | "title": "{{ .Title }}", |
| | | "body": `{{ .PlainWords }}`.toLowerCase() // @TODO: move this definition to an index.json file. |
| | | }, |
| | | {{- end }} |
| | | ]; |
| | | |
| | | function initializeSearch(index) { |
| | | const searchKeys = ['title', 'link', 'body', 'id']; |
| | | |
| | | const searchPageElement = elem('#searchpage'); |
| | |
| | | threshold: 0.0 |
| | | }; |
| | | |
| | | const index = new Fuse(idx, searchOptions); |
| | | index = new Fuse(index, searchOptions); |
| | | |
| | | function minQueryLen(query) { |
| | | query = query.trim(); |
| | |
| | | main = elem('.main'); |
| | | } |
| | | |
| | | window.addEventListener('load', function() { |
| | | searchPageElement ? false : liveSearch(); |
| | | passiveSearch(); |
| | | |
| | | wrapText(findQuery(), main); |
| | | |
| | | onEscape(clearSearchResults); |
| | | }); |
| | | |
| | | window.addEventListener('click', function(event){ |
| | | const target = event.target; |
| | |
| | | clearSearchResults(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | window.addEventListener('load', function() { |
| | | fetch("/index.json") |
| | | .then(response => response.json()) |
| | | .then(function(data) { |
| | | data = data.length ? data : []; |
| | | initializeSearch(data); |
| | | }) |
| | | .catch((error) => console.error(error)); |
| | | }); |