mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-19 10:54:06 -06:00
Merge 8de40437a1 into e77a051144
This commit is contained in:
commit
d7e7d7665c
@ -9,6 +9,8 @@ interface Item {
|
|||||||
title: string
|
title: string
|
||||||
content: string
|
content: string
|
||||||
tags: string[]
|
tags: string[]
|
||||||
|
aliases: string[]
|
||||||
|
[key: string]: any
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can be expanded with things like "term" in the future
|
// Can be expanded with things like "term" in the future
|
||||||
@ -35,6 +37,10 @@ let index = new FlexSearch.Document<Item>({
|
|||||||
field: "tags",
|
field: "tags",
|
||||||
tokenize: "forward",
|
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 ?? ""),
|
title: searchType === "tags" ? data[slug].title : highlight(term, data[slug].title ?? ""),
|
||||||
content: highlight(term, data[slug].content ?? "", true),
|
content: highlight(term, data[slug].content ?? "", true),
|
||||||
tags: highlightTags(term.substring(1), data[slug].tags),
|
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,
|
query: query,
|
||||||
// return at least 10000 documents, so it is enough to filter them by tag (implemented in flexsearch)
|
// return at least 10000 documents, so it is enough to filter them by tag (implemented in flexsearch)
|
||||||
limit: Math.max(numSearchResults, 10000),
|
limit: Math.max(numSearchResults, 10000),
|
||||||
index: ["title", "content"],
|
index: ["title", "content", "aliases"],
|
||||||
tag: tag,
|
tag: tag,
|
||||||
})
|
})
|
||||||
for (let searchResult of searchResults) {
|
for (let searchResult of searchResults) {
|
||||||
@ -430,7 +437,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data:
|
|||||||
searchResults = await index.searchAsync({
|
searchResults = await index.searchAsync({
|
||||||
query: currentSearchTerm,
|
query: currentSearchTerm,
|
||||||
limit: numSearchResults,
|
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
|
// order titles ahead of content
|
||||||
const allIds: Set<number> = new Set([
|
const allIds: Set<number> = new Set([
|
||||||
...getByField("title"),
|
...getByField("title"),
|
||||||
|
...getByField("aliases"),
|
||||||
...getByField("content"),
|
...getByField("content"),
|
||||||
...getByField("tags"),
|
...getByField("tags"),
|
||||||
])
|
])
|
||||||
@ -478,6 +486,7 @@ async function fillDocument(data: ContentIndex) {
|
|||||||
title: fileData.title,
|
title: fileData.title,
|
||||||
content: fileData.content,
|
content: fileData.content,
|
||||||
tags: fileData.tags,
|
tags: fileData.tags,
|
||||||
|
aliases: fileData.aliases,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ export type ContentDetails = {
|
|||||||
links: SimpleSlug[]
|
links: SimpleSlug[]
|
||||||
tags: string[]
|
tags: string[]
|
||||||
content: string
|
content: string
|
||||||
|
aliases: string[]
|
||||||
richContent?: string
|
richContent?: string
|
||||||
date?: Date
|
date?: Date
|
||||||
description?: string
|
description?: string
|
||||||
@ -110,6 +111,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
links: file.data.links ?? [],
|
links: file.data.links ?? [],
|
||||||
tags: file.data.frontmatter?.tags ?? [],
|
tags: file.data.frontmatter?.tags ?? [],
|
||||||
content: file.data.text ?? "",
|
content: file.data.text ?? "",
|
||||||
|
aliases: file.data.frontmatter?.aliases ?? [],
|
||||||
richContent: opts?.rssFullHtml
|
richContent: opts?.rssFullHtml
|
||||||
? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true }))
|
? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true }))
|
||||||
: undefined,
|
: undefined,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user