From f2d2641cf2027de0fef3f1167c9373259363a956 Mon Sep 17 00:00:00 2001 From: Anatoli Nicolae Date: Fri, 5 Jul 2024 17:22:46 +0200 Subject: [PATCH] Attempt to include tags in search Signed-off-by: Anatoli Nicolae --- .vitepress/config.ts | 27 +++++++++++++++++++-------- notes/index.md | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.vitepress/config.ts b/.vitepress/config.ts index e26fb7f..a322c32 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -15,11 +15,24 @@ export default defineConfigWithTheme({ autoTitle: true, search: { - provider: "algolia", + provider: "local", options: { - indexName: "apiscpnotes", - appId: "TA7YISSZ4O", - apiKey: "64283e3b28dd9a7112d9a45ec6812751", + _render(src, env, md) { + let content = ""; + const rendered = md.render(src, env); + + // Excluding pages from search + if (env.frontmatter?.search === false) return ""; + + // Transforming content to include title and tags + if (env.frontmatter?.title) + content += md.render(`# ${env.frontmatter.title}`); + + if (env.frontmatter?.tags) + content += md.render(`- ${env.frontmatter.tags.join("\n- ")}`); + + return `${content}\n${rendered}`; + }, }, }, @@ -41,9 +54,7 @@ export default defineConfigWithTheme({ buildSidebar({ rootPath: "./notes", title: "Notes", - exclude: [ - 'index.md', - ], + exclude: ["index.md"], }), ], @@ -73,5 +84,5 @@ export default defineConfigWithTheme({ ignoreDeadLinks: [ // ignore all localhost links /^https?:\/\/localhost/, - ] + ], }); diff --git a/notes/index.md b/notes/index.md index 297fc69..41b3786 100644 --- a/notes/index.md +++ b/notes/index.md @@ -4,6 +4,7 @@ title: Home hide_title: true +search: false ---