New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: allow customizing markdown renderer used for local search indexing #2770
Conversation
Removed "fileContents" as the raw markdown is available as env.content. |
Hi, sorry for the delay. But this might need some more consideration as |
No problem, thanks for the update. Let me know if there is anything I can help with. |
I think we probably can decide on some name conventions like The other alternative I see is using some property to indicate node only: Other thing I tried was using some magic comments, but turns out esbuild removes them while loading the config, so those won't work. First should be good IMO, wdyt? |
Thanks for the update. I'll update the serializer part. |
Can you verify if the example mentioned in https://deploy-preview-2770--vitepress-docs.netlify.app/reference/default-theme-search#example-transforming-content-adding-anchors works for you with the latest commit? |
Confirmed working, my H1-adding scenario is now: themeConfig: {
search: {
provider: "local",
options: {
detailedView: true,
_render: (src, env, md) => {
const html = md.render(src, env)
if (env.frontmatter?.search === false) return ""
return env.frontmatter?.title ? md.render("# " + env.frontmatter?.title) + html : html
},
},
}, Thanks! |
Localsearch indexes content directly rendered from the file system without opportunity to change the HTML before indexing.
This can be a problem if your layout normally adds important elements such as a
<h1>
based on a Frontmatter title (as the VueJS blog does).This PR introduces a hook where, for
localsearch
, you can provide a function that takes the HTML, environmental data such as the page path and Frontmatter, and a render function. You can then use these elements to either re-process the markdown or to manipulate it in some way.,In the VueJS blog scenario you can now do this to ensure titles are headings on your search results:
Thanks for your consideration!