| | |
| | | removeAllChildren(preview) |
| | | } |
| | | if (searchLayout) { |
| | | searchLayout.style.visibility = "hidden" |
| | | searchLayout.classList.remove("display-results") |
| | | } |
| | | |
| | | searchType = "basic" // reset search type after closing |
| | |
| | | async function onType(e: HTMLElementEventMap["input"]) { |
| | | if (!searchLayout || !index) return |
| | | currentSearchTerm = (e.target as HTMLInputElement).value |
| | | searchLayout.style.visibility = currentSearchTerm === "" ? "hidden" : "visible" |
| | | searchLayout.classList.toggle("display-results", currentSearchTerm !== "") |
| | | searchType = currentSearchTerm.startsWith("#") ? "tags" : "basic" |
| | | |
| | | let searchResults: FlexSearch.SimpleDocumentSearchResultSetUnit[] |
| | |
| | | searchBar?.addEventListener("input", onType) |
| | | window.addCleanup(() => searchBar?.removeEventListener("input", onType)) |
| | | |
| | | await fillDocument(data) |
| | | registerEscapeHandler(container, hideSearch) |
| | | await fillDocument(data) |
| | | }) |
| | | |
| | | /** |
| | |
| | | */ |
| | | async function fillDocument(data: { [key: FullSlug]: ContentDetails }) { |
| | | let id = 0 |
| | | const promises: Array<Promise<unknown>> = [] |
| | | for (const [slug, fileData] of Object.entries<ContentDetails>(data)) { |
| | | await index.addAsync(id++, { |
| | | id, |
| | | slug: slug as FullSlug, |
| | | title: fileData.title, |
| | | content: fileData.content, |
| | | tags: fileData.tags, |
| | | }) |
| | | promises.push( |
| | | index.addAsync(id++, { |
| | | id, |
| | | slug: slug as FullSlug, |
| | | title: fileData.title, |
| | | content: fileData.content, |
| | | tags: fileData.tags, |
| | | }), |
| | | ) |
| | | } |
| | | |
| | | return await Promise.all(promises) |
| | | } |