| | |
| | | import { Document } from "flexsearch" |
| | | import { ContentDetails } from "../../plugins/emitters/contentIndex" |
| | | import { registerEscapeHandler, removeAllChildren } from "./util" |
| | | import { CanonicalSlug, getClientSlug, resolveRelative } from "../../path" |
| | | import { FullSlug, getFullSlug, resolveRelative, simplifySlug } from "../../util/path" |
| | | |
| | | interface Item { |
| | | id: number |
| | | slug: CanonicalSlug |
| | | slug: FullSlug |
| | | title: string |
| | | content: string |
| | | } |
| | |
| | | const searchIcon = document.getElementById("search-icon") |
| | | const searchBar = document.getElementById("search-bar") as HTMLInputElement | null |
| | | const results = document.getElementById("results-container") |
| | | const idDataMap = Object.keys(data) as CanonicalSlug[] |
| | | const idDataMap = Object.keys(data) as FullSlug[] |
| | | |
| | | function hideSearch() { |
| | | container?.classList.remove("active") |
| | |
| | | button.innerHTML = `<h3>${title}</h3><p>${content}</p>` |
| | | button.addEventListener("click", () => { |
| | | const targ = resolveRelative(currentSlug, slug) |
| | | window.spaNavigate(new URL(targ, getClientSlug(window))) |
| | | window.spaNavigate(new URL(targ, window.location.toString())) |
| | | }) |
| | | return button |
| | | } |
| | |
| | | async function onType(e: HTMLElementEventMap["input"]) { |
| | | const term = (e.target as HTMLInputElement).value |
| | | const searchResults = (await index?.searchAsync(term, numSearchResults)) ?? [] |
| | | console.log(searchResults) |
| | | const getByField = (field: string): number[] => { |
| | | const results = searchResults.filter((x) => x.field === field) |
| | | return results.length === 0 ? [] : ([...results[0].result] as number[]) |
| | |
| | | for (const [slug, fileData] of Object.entries<ContentDetails>(data)) { |
| | | await index.addAsync(id, { |
| | | id, |
| | | slug: slug as CanonicalSlug, |
| | | slug: slug as FullSlug, |
| | | title: fileData.title, |
| | | content: fileData.content, |
| | | }) |