From 5a80dfc210675584e2817d82e7637e042a0bb515 Mon Sep 17 00:00:00 2001 From: Ben Schlegel Date: Tue, 29 Aug 2023 22:17:57 +0200 Subject: [PATCH] =?UTF-8?q?Quartz=20sync:=20Aug=2029,=202023,=2010:17?= =?UTF-8?q?=E2=80=AFPM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/index.md | 3 +++ content/stuff.md | 8 ++++++ content/things.md | 7 +++++ quartz/components/scripts/search.inline.ts | 30 +++++++++++++++------- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 content/index.md create mode 100644 content/stuff.md create mode 100644 content/things.md diff --git a/content/index.md b/content/index.md new file mode 100644 index 000000000..5367e3489 --- /dev/null +++ b/content/index.md @@ -0,0 +1,3 @@ +test + +#cool diff --git a/content/stuff.md b/content/stuff.md new file mode 100644 index 000000000..a6653bb23 --- /dev/null +++ b/content/stuff.md @@ -0,0 +1,8 @@ +--- +title: Example Title +draft: false +tags: + - cool +--- + +this contains cool things diff --git a/content/things.md b/content/things.md new file mode 100644 index 000000000..5dfbc65ed --- /dev/null +++ b/content/things.md @@ -0,0 +1,7 @@ +stuff + +#example + +content + +#cool diff --git a/quartz/components/scripts/search.inline.ts b/quartz/components/scripts/search.inline.ts index ef26ba380..f1543d7d6 100644 --- a/quartz/components/scripts/search.inline.ts +++ b/quartz/components/scripts/search.inline.ts @@ -8,6 +8,7 @@ interface Item { slug: FullSlug title: string content: string + tags: string } let index: Document | undefined = undefined @@ -102,6 +103,11 @@ document.addEventListener("nav", async (e: unknown) => { e.preventDefault() const searchBarOpen = container?.classList.contains("active") searchBarOpen ? hideSearch() : showSearch() + } else if (e.shiftKey && (e.ctrlKey || e.metaKey) && e.key === "K") { + e.preventDefault() + console.log("open tag search") + const searchBarOpen = container?.classList.contains("active") + searchBarOpen ? hideSearch() : showSearch() } else if (e.key === "Enter") { const anchor = document.getElementsByClassName("result-card")[0] as HTMLInputElement | null if (anchor) { @@ -117,10 +123,11 @@ document.addEventListener("nav", async (e: unknown) => { slug, title: highlight(term, data[slug].title ?? ""), content: highlight(term, data[slug].content ?? "", true), + tags: data[slug].tags } } - const resultToHTML = ({ slug, title, content }: Item) => { + const resultToHTML = ({ slug, title, content, tags }: Item) => { const button = document.createElement("button") button.classList.add("result-card") button.id = slug @@ -156,7 +163,7 @@ document.addEventListener("nav", async (e: unknown) => { } // order titles ahead of content - const allIds: Set = new Set([...getByField("title"), ...getByField("content")]) + const allIds: Set = new Set([...getByField("title"), ...getByField("content"), ...getByField("tags")]) const finalResults = [...allIds].map((id) => formatForDisplay(term, id)) displayResults(finalResults) } @@ -182,14 +189,18 @@ document.addEventListener("nav", async (e: unknown) => { document: { id: "id", index: [ + // { + // field: "title", + // tokenize: "reverse", + // }, + // { + // field: "content", + // tokenize: "reverse", + // }, { - field: "title", - tokenize: "reverse", - }, - { - field: "content", - tokenize: "reverse", - }, + field: "tags", + tokenize: "reverse" + } ], }, }) @@ -201,6 +212,7 @@ document.addEventListener("nav", async (e: unknown) => { slug: slug as FullSlug, title: fileData.title, content: fileData.content, + tags: fileData.tags.join("") }) id++ }