| | |
| | | }; |
| | | </script> |
| | | <script> |
| | | async function run() { |
| | | const contentIndex = new FlexSearch.Document({ |
| | | cache: true, |
| | | charset: "latin:extra", |
| | |
| | | } |
| | | }) |
| | | |
| | | const { content } = await fetchData() |
| | | for (const [key, value] of Object.entries(content)) { |
| | | contentIndex.add({ |
| | | id: key, |
| | |
| | | window.location.href = "{{.Site.BaseURL}}" + `${id}#:~:text=${encodeURIComponent(term)}` |
| | | } |
| | | |
| | | const fetch = id => ({ |
| | | const formatForDisplay = id => ({ |
| | | id, |
| | | url: id, |
| | | title: content[id].title, |
| | |
| | | } |
| | | } |
| | | const allIds = new Set([...getByField('title'), ...getByField('content')]) |
| | | const finalResults = [...allIds].map(fetch) |
| | | const finalResults = [...allIds].map(formatForDisplay) |
| | | |
| | | // display |
| | | if (finalResults.length === 0) { |
| | |
| | | |
| | | |
| | | const searchContainer = document.getElementById("search-container") |
| | | |
| | | function openSearch() { |
| | | if (searchContainer.style.display === "none" || searchContainer.style.display === "") { |
| | | source.value = "" |
| | |
| | | evt.stopPropagation() |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | run() |
| | | </script> |