From 8de40437a1a32e11e7214e7db46ec7b874bdbcc2 Mon Sep 17 00:00:00 2001 From: Amir Pourmand Date: Thu, 4 Sep 2025 18:53:02 +0330 Subject: [PATCH] add aliases support to plex search --- quartz/components/scripts/search.inline.ts | 13 +++++++++++-- quartz/plugins/emitters/contentIndex.tsx | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/quartz/components/scripts/search.inline.ts b/quartz/components/scripts/search.inline.ts index 28d47e9e2..428c43a72 100644 --- a/quartz/components/scripts/search.inline.ts +++ b/quartz/components/scripts/search.inline.ts @@ -9,6 +9,8 @@ interface Item { title: string content: string tags: string[] + aliases: string[] + [key: string]: any } // Can be expanded with things like "term" in the future @@ -35,6 +37,10 @@ let index = new FlexSearch.Document({ field: "tags", tokenize: "forward", }, + { + field: "aliases", + tokenize: "forward", + }, ], }, }) @@ -271,6 +277,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data: title: searchType === "tags" ? data[slug].title : highlight(term, data[slug].title ?? ""), content: highlight(term, data[slug].content ?? "", true), tags: highlightTags(term.substring(1), data[slug].tags), + aliases: data[slug].aliases ?? [], } } @@ -409,7 +416,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data: query: query, // return at least 10000 documents, so it is enough to filter them by tag (implemented in flexsearch) limit: Math.max(numSearchResults, 10000), - index: ["title", "content"], + index: ["title", "content", "aliases"], tag: tag, }) for (let searchResult of searchResults) { @@ -430,7 +437,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data: searchResults = await index.searchAsync({ query: currentSearchTerm, limit: numSearchResults, - index: ["title", "content"], + index: ["title", "content", "aliases"], }) } @@ -442,6 +449,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data: // order titles ahead of content const allIds: Set = new Set([ ...getByField("title"), + ...getByField("aliases"), ...getByField("content"), ...getByField("tags"), ]) @@ -478,6 +486,7 @@ async function fillDocument(data: ContentIndex) { title: fileData.title, content: fileData.content, tags: fileData.tags, + aliases: fileData.aliases, }), ) } diff --git a/quartz/plugins/emitters/contentIndex.tsx b/quartz/plugins/emitters/contentIndex.tsx index 56392b358..e78c5ff23 100644 --- a/quartz/plugins/emitters/contentIndex.tsx +++ b/quartz/plugins/emitters/contentIndex.tsx @@ -16,6 +16,7 @@ export type ContentDetails = { links: SimpleSlug[] tags: string[] content: string + aliases: string[] richContent?: string date?: Date description?: string @@ -110,6 +111,7 @@ export const ContentIndex: QuartzEmitterPlugin> = (opts) => { links: file.data.links ?? [], tags: file.data.frontmatter?.tags ?? [], content: file.data.text ?? "", + aliases: file.data.frontmatter?.aliases ?? [], richContent: opts?.rssFullHtml ? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true })) : undefined,