anthops
2025-04-30 adf442036b244dfafea6287bf69c22f4eb133b79
quartz/components/scripts/search.inline.ts
@@ -147,8 +147,7 @@
  const container = searchElement.querySelector(".search-container") as HTMLElement
  if (!container) return
  const sidebar = container.closest(".sidebar") as HTMLElement
  if (!sidebar) return
  const sidebar = container.closest(".sidebar") as HTMLElement | null
  const searchButton = searchElement.querySelector(".search-button") as HTMLButtonElement
  if (!searchButton) return
@@ -180,7 +179,7 @@
  function hideSearch() {
    container.classList.remove("active")
    searchBar.value = "" // clear the input when we dismiss the search
    sidebar.style.zIndex = ""
    if (sidebar) sidebar.style.zIndex = ""
    removeAllChildren(results)
    if (preview) {
      removeAllChildren(preview)
@@ -192,7 +191,7 @@
  function showSearch(searchTypeNew: SearchType) {
    searchType = searchTypeNew
    sidebar.style.zIndex = "1"
    if (sidebar) sidebar.style.zIndex = "1"
    container.classList.add("active")
    searchBar.focus()
  }
@@ -301,9 +300,11 @@
    itemTile.classList.add("result-card")
    itemTile.id = slug
    itemTile.href = resolveUrl(slug).toString()
    itemTile.innerHTML = `<h3>${title}</h3>${htmlTags}${
      enablePreview && window.innerWidth > 600 ? "" : `<p>${content}</p>`
    }`
    itemTile.innerHTML = `
      <h3 class="card-title">${title}</h3>
      ${htmlTags}
      <p class="card-description">${content}</p>
    `
    itemTile.addEventListener("click", (event) => {
      if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
      hideSearch()
@@ -384,7 +385,7 @@
    preview.replaceChildren(previewInner)
    // scroll to longest
    const highlights = [...preview.querySelectorAll(".highlight")].sort(
    const highlights = [...preview.getElementsByClassName("highlight")].sort(
      (a, b) => b.innerHTML.length - a.innerHTML.length,
    )
    highlights[0]?.scrollIntoView({ block: "start" })
@@ -488,7 +489,7 @@
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
  const currentSlug = e.detail.url
  const data = await fetchData
  const searchElement = document.querySelectorAll(".search")
  const searchElement = document.getElementsByClassName("search")
  for (const element of searchElement) {
    await setupSearch(element, currentSlug, data)
  }