From 0403fa70aa24cd3c16fbd9caf434cdcd277f1a14 Mon Sep 17 00:00:00 2001
From: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
Date: Mon, 22 Jan 2024 04:50:00 +0000
Subject: [PATCH] fix(search): use anchor element (closes #698) (#717)
---
quartz/components/scripts/search.inline.ts | 21 ++++++++++++---------
1 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/quartz/components/scripts/search.inline.ts b/quartz/components/scripts/search.inline.ts
index 2858e0f..ab76b5f 100644
--- a/quartz/components/scripts/search.inline.ts
+++ b/quartz/components/scripts/search.inline.ts
@@ -122,7 +122,10 @@
// add "#" prefix for tag search
if (searchBar) searchBar.value = "#"
- } else if (e.key === "Enter") {
+ }
+
+ if (!container?.classList.contains("active")) return
+ else if (e.key === "Enter") {
// If result has focus, navigate to that one, otherwise pick first result
if (results?.contains(document.activeElement)) {
const active = document.activeElement as HTMLInputElement
@@ -219,16 +222,16 @@
const resultToHTML = ({ slug, title, content, tags }: Item) => {
const htmlTags = tags.length > 0 ? `<ul>${tags.join("")}</ul>` : ``
- const button = document.createElement("button")
- button.classList.add("result-card")
- button.id = slug
- button.innerHTML = `<h3>${title}</h3>${htmlTags}<p>${content}</p>`
- button.addEventListener("click", () => {
- const targ = resolveRelative(currentSlug, slug)
- window.spaNavigate(new URL(targ, window.location.toString()))
+ const itemTile = document.createElement("a")
+ itemTile.classList.add("result-card")
+ itemTile.id = slug
+ itemTile.href = new URL(resolveRelative(currentSlug, slug), location.toString()).toString()
+ itemTile.innerHTML = `<h3>${title}</h3>${htmlTags}<p>${content}</p>`
+ itemTile.addEventListener("click", (event) => {
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
hideSearch()
})
- return button
+ return itemTile
}
function displayResults(finalResults: Item[]) {
--
Gitblit v1.10.0