Quartz sync: Aug 29, 2023, 10:17 PM

This commit is contained in:
Ben Schlegel 2023-08-29 22:17:57 +02:00
parent 5fa6fc9789
commit 5a80dfc210
4 changed files with 39 additions and 9 deletions

3
content/index.md Normal file
View File

@ -0,0 +1,3 @@
test
#cool

8
content/stuff.md Normal file
View File

@ -0,0 +1,8 @@
---
title: Example Title
draft: false
tags:
- cool
---
this contains cool things

7
content/things.md Normal file
View File

@ -0,0 +1,7 @@
stuff
#example
content
#cool

View File

@ -8,6 +8,7 @@ interface Item {
slug: FullSlug slug: FullSlug
title: string title: string
content: string content: string
tags: string
} }
let index: Document<Item> | undefined = undefined let index: Document<Item> | undefined = undefined
@ -102,6 +103,11 @@ document.addEventListener("nav", async (e: unknown) => {
e.preventDefault() e.preventDefault()
const searchBarOpen = container?.classList.contains("active") const searchBarOpen = container?.classList.contains("active")
searchBarOpen ? hideSearch() : showSearch() 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") { } else if (e.key === "Enter") {
const anchor = document.getElementsByClassName("result-card")[0] as HTMLInputElement | null const anchor = document.getElementsByClassName("result-card")[0] as HTMLInputElement | null
if (anchor) { if (anchor) {
@ -117,10 +123,11 @@ document.addEventListener("nav", async (e: unknown) => {
slug, slug,
title: highlight(term, data[slug].title ?? ""), title: highlight(term, data[slug].title ?? ""),
content: highlight(term, data[slug].content ?? "", true), 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") const button = document.createElement("button")
button.classList.add("result-card") button.classList.add("result-card")
button.id = slug button.id = slug
@ -156,7 +163,7 @@ document.addEventListener("nav", async (e: unknown) => {
} }
// order titles ahead of content // order titles ahead of content
const allIds: Set<number> = new Set([...getByField("title"), ...getByField("content")]) const allIds: Set<number> = new Set([...getByField("title"), ...getByField("content"), ...getByField("tags")])
const finalResults = [...allIds].map((id) => formatForDisplay(term, id)) const finalResults = [...allIds].map((id) => formatForDisplay(term, id))
displayResults(finalResults) displayResults(finalResults)
} }
@ -182,14 +189,18 @@ document.addEventListener("nav", async (e: unknown) => {
document: { document: {
id: "id", id: "id",
index: [ index: [
// {
// field: "title",
// tokenize: "reverse",
// },
// {
// field: "content",
// tokenize: "reverse",
// },
{ {
field: "title", field: "tags",
tokenize: "reverse", tokenize: "reverse"
}, }
{
field: "content",
tokenize: "reverse",
},
], ],
}, },
}) })
@ -201,6 +212,7 @@ document.addEventListener("nav", async (e: unknown) => {
slug: slug as FullSlug, slug: slug as FullSlug,
title: fileData.title, title: fileData.title,
content: fileData.content, content: fileData.content,
tags: fileData.tags.join("")
}) })
id++ id++
} }