Jacky Zhao
2023-08-12 827dd918476e225238d8412551df2866e4f9e616
format, make search async
2 files modified
6 ■■■■ changed files
quartz/components/scripts/search.inline.ts 4 ●●●● patch | view | raw | blame | history
quartz/plugins/transformers/ofm.ts 2 ●●● patch | view | raw | blame | history
quartz/components/scripts/search.inline.ts
@@ -139,9 +139,9 @@
    }
  }
  function onType(e: HTMLElementEventMap["input"]) {
  async function onType(e: HTMLElementEventMap["input"]) {
    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 results = searchResults.filter((x) => x.field === field)
      return results.length === 0 ? [] : ([...results[0].result] as CanonicalSlug[])
quartz/plugins/transformers/ofm.ts
@@ -165,7 +165,7 @@
          const fp = rawFp ?? ""
          const anchor = rawHeader?.trim().slice(1)
          const displayAnchor = anchor ? `#${slugAnchor(anchor)}` : ""
          const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? ""
          const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? ""
          const embedDisplay = value.startsWith("!") ? "!" : ""
          return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]`
        })