format, make search async

This commit is contained in:
Jacky Zhao 2023-08-12 00:03:11 -07:00
parent 9b1b832dc3
commit 7e97757776
2 changed files with 3 additions and 3 deletions

View File

@ -139,9 +139,9 @@ document.addEventListener("nav", async (e: unknown) => {
} }
} }
function onType(e: HTMLElementEventMap["input"]) { async function onType(e: HTMLElementEventMap["input"]) {
const term = (e.target as HTMLInputElement).value const term = (e.target as HTMLInputElement).value
const searchResults = index?.search(term, numSearchResults) ?? [] const searchResults = (await index?.searchAsync(term, numSearchResults)) ?? []
const getByField = (field: string): CanonicalSlug[] => { const getByField = (field: string): CanonicalSlug[] => {
const results = searchResults.filter((x) => x.field === field) const results = searchResults.filter((x) => x.field === field)
return results.length === 0 ? [] : ([...results[0].result] as CanonicalSlug[]) return results.length === 0 ? [] : ([...results[0].result] as CanonicalSlug[])

View File

@ -165,7 +165,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>
const fp = rawFp ?? "" const fp = rawFp ?? ""
const anchor = rawHeader?.trim().slice(1) const anchor = rawHeader?.trim().slice(1)
const displayAnchor = anchor ? `#${slugAnchor(anchor)}` : "" const displayAnchor = anchor ? `#${slugAnchor(anchor)}` : ""
const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? "" const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? ""
const embedDisplay = value.startsWith("!") ? "!" : "" const embedDisplay = value.startsWith("!") ? "!" : ""
return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]` return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]`
}) })