unplugin / unplugin-vue-markdown

Compile Markdown to Vue component
MIT License
508 stars 27 forks source link

Accessing frontmatter from outside #26

Closed angelokezimana closed 1 year ago

angelokezimana commented 1 year ago

I'm currently working on a Vue 3 project and using the unplugin-vue-markdown package to render markdown content. I have frontmatter metadata in my markdown files that I need to access in my Vue component.

Code Snippets: markdown:

---
title: My Markdown Title
otherData: Some Value
---
## Content
This is my markdown content.

Vue Component:

<template>
  <div>
    <h1>{{ frontmatter.title }}</h1>
    <!-- ...other content -->
  </div>
</template>

I've reviewed the documentation of unplugin-vue-markdown but haven't found a solution that addresses accessing frontmatter from outside the markdown file.

Packages and Versions:

Vue: 3.3.4 unplugin-vue-markdown: 0.24.2

antfu commented 1 year ago

I think this would work

import { frontmatter } from './foo.vue'
angelokezimana commented 1 year ago

Thank you @antfu , however, my question was how to extract/get frontmatter from .md file to vue component.

I tried

foo.md

---
title: My Markdown Title
otherData: Some Value
---
## Content
This is my markdown content.

App.vue

<script setup>
import { frontmatter } from './foo.md';
</script>
<template>
  <div>
    {{ frontmatter.title }}
  </div>
</template>

And I got this error

errorvue