diff --git a/docs/reference/default-theme-search.md b/docs/reference/default-theme-search.md index a7bfe79b..891ab8e8 100644 --- a/docs/reference/default-theme-search.md +++ b/docs/reference/default-theme-search.md @@ -120,7 +120,7 @@ export default defineConfig({ - Type: `(html: string, env: MarkdownEnv, render: (markdown: string) => string) => string` -You can pass a `preIndexRender` function to `themeConfig.search.options` that can modify or return entirely different HTML content before it is indexed. +While processing in Node (not available client-side) you can pass a `node_preIndexRender` function to `themeConfig.search.options` that can modify or return entirely different HTML content before it is indexed. The function receives the following parameters: @@ -137,7 +137,7 @@ export default defineConfig({ themeConfig: { search: { options: { - preIndexRender: (html, env, render) => + node_preIndexRender: (html, env, render) => env.frontmatter?.title ? render('# ' + env.frontmatter?.title) + html : html diff --git a/src/node/plugins/localSearchPlugin.ts b/src/node/plugins/localSearchPlugin.ts index b5936a70..a32fbd10 100644 --- a/src/node/plugins/localSearchPlugin.ts +++ b/src/node/plugins/localSearchPlugin.ts @@ -64,8 +64,8 @@ export async function localSearchPlugin( if (searchConfig.options?.exclude?.(relativePath)) { return '' } - if (searchConfig?.options?.preIndexRender) { - return searchConfig.options.preIndexRender(html, env, (markdown) => + if (searchConfig?.options?.node_preIndexRender) { + return searchConfig.options.node_preIndexRender(html, env, (markdown) => md.render(markdown, env) ) } diff --git a/types/default-theme.d.ts b/types/default-theme.d.ts index c12ce0c5..3d19a021 100644 --- a/types/default-theme.d.ts +++ b/types/default-theme.d.ts @@ -388,9 +388,9 @@ export namespace DefaultTheme { exclude?: (relativePath: string) => boolean /** - * Allow transformation of content before indexing + * Allow transformation of content before indexing (from Node only) */ - preIndexRender?: ( + node_preIndexRender?: ( html: string, env: MarkdownEnv, render: (string) => string