From 685c06ce2e7c559b4e2cc544e300c1262c739b1c Mon Sep 17 00:00:00 2001
From: K Gopal Krishna <30401343+kayg04@users.noreply.github.com>
Date: Fri, 04 Apr 2025 17:36:29 +0000
Subject: [PATCH] fix(RecentNotes): Prevent folder pages from always appearing first (closes #1901) (#1904)
---
quartz/components/scripts/search.inline.ts | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/quartz/components/scripts/search.inline.ts b/quartz/components/scripts/search.inline.ts
index c9bbcce..d95f468 100644
--- a/quartz/components/scripts/search.inline.ts
+++ b/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()
}
@@ -384,7 +383,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 +487,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)
}
--
Gitblit v1.10.0