fix: tweak search

This commit is contained in:
taskylizard
2023-12-21 14:15:21 +00:00
parent 1ab86fa03a
commit 0ca6c65c0d
4 changed files with 168 additions and 120 deletions

View File

@@ -78,7 +78,24 @@ export default defineConfig({
themeConfig: {
search: {
options: {
miniSearch: { searchOptions: { combineWith: "AND" } },
miniSearch: {
searchOptions: {
combineWith: "AND",
fuzzy: false,
// @ts-ignore
boostDocument: (_, term, storedFields: Record<string, string | string[]>) => {
const titles = (storedFields?.titles as string[])
.filter((t) => !!t)
.map((t) => t.toLowerCase());
// Uprate if term appears in titles. Add bonus for higher levels (i.e. lower index)
const titleIndex =
titles.map((t, i) => (t?.includes(term) ? i : -1)).find((i) => i >= 0) ?? -1;
if (titleIndex >= 0) return 10000 - titleIndex;
return 1;
},
},
},
detailedView: true,
},
provider: "local",

View File

@@ -13,10 +13,10 @@ export const commitRef = process.env.COMMIT_REF
process.env.COMMIT_REF
}">${process.env.COMMIT_REF.slice(0, 8)}</a>`
: process.env.CF_PAGES
? `<a href="https://github.com/fmhy/FMHYEdit/commit/${
process.env.CF_PAGES_COMMIT_SHA
}">${process.env.CF_PAGES_COMMIT_SHA.slice(0, 8)}</a>`
: "dev";
? `<a href="https://github.com/fmhy/FMHYEdit/commit/${
process.env.CF_PAGES_COMMIT_SHA
}">${process.env.CF_PAGES_COMMIT_SHA.slice(0, 8)}</a>`
: "dev";
export const socials: DefaultTheme.SocialLink[] = [
{ icon: "github", link: "https://github.com/fmhy/FMHYEdit" },