vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.25k stars 2.14k forks source link

improve: missing `env` properties for Content Loader when `render` is specified #4349

Closed nekomeowww closed 2 weeks ago

nekomeowww commented 2 weeks ago

Summary

For general VitePress page renders, properties of env are available for markdown-it plugins to peek file path related info:

https://github.com/vuejs/vitepress/blob/36e0c1a3dbd3e5259fe08a480cc0ca3a1d48ba9b/src/node/markdownToVue.ts#L113-L122

However, for content loader, if specified such

export default createContentLoader('/**/*.md', {
  render: true,
  transform() {
    return []
  },
})

content loader function, with our Lazy loading blurred thumbnails | Nólëbase Integrations markdown-it plugin where env.path and env.relativePath are required, since users are not allowed to toggle these unsupported markdown-it plugins for content loaders, they will not be able to use content loaders with markdown-it-unlazy-img together.

I found the code here, for content loaderss, within the render function, env properties are not injected as what VitePress's render would do:

https://github.com/vuejs/vitepress/blob/36e0c1a3dbd3e5259fe08a480cc0ca3a1d48ba9b/src/node/contentLoader.ts#L147

Proposal

brc-dd commented 2 weeks ago

Duplicate of #4331

Please track it instead. We actually need a bunch of refactoring for this to work correctly. I'll do it next when I get time.