vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

Can expose the frontmatter to the md object?

Open dewfall123 opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

I write a VirePress md plugin in this project. And i wanted to use frontmatter data in the markdown plugin, but I had to re-parse the file contents to get it.

It would be much better to expose frontmatter to md object like md.__path

  md.renderer.rules.html_block = (tokens, idx, ...args) => {
    ...
    const mdContent = fsExtra.readFileSync(md.__path);
    const { data: frontmatter } = matter(mdContent);
    ...
  };

Describe the solution you'd like

https://github.com/vuejs/vitepress/blob/main/src/node/markdownToVue.ts#L69

const { content, data: frontmatter } = matter(src)

md.__path = file
md.__relativePath = relativePath
// add this
md.__frontmatter = frontmatter

Describe alternatives you've considered

No response

Additional context

No response

Validations

dewfall123 avatar Aug 05 '22 07:08 dewfall123

#856 will fix this

brc-dd avatar Aug 05 '22 08:08 brc-dd