vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
4.39k stars 351 forks source link

Markdown Frontmatter not accessible #215

Closed oliverpool closed 2 years ago

oliverpool commented 2 years ago

According to https://vite-plugin-ssr.com/markdown

We can also use a so-called front matter to define the page's metadata.

however I can't get it to work.


I have created a fork with a md_frontmatter_example branch to reproduce.

https://github.com/oliverpool/vite-plugin-ssr/commit/25d1bfbacacadde7da19ff949322290dbe82ff48

The title is however modifeid, when visiting /markdown:

<script>
export const documentProps = {
  title: 'Some Markdown Page'
}
</script>

Is there something missing to make the frontmatter work?

brillout commented 2 years ago

It's very likely a problem with your code

oliverpool commented 2 years ago

I took the code of the vue-full example of this repo. What should I change to make it work?

I couldn't find any hint in the documentation

brillout commented 2 years ago

Updated docs

oliverpool commented 2 years ago

With vue 3, vite-plugin-md exposes the frontmatter with defineExpose({ frontmatter }) : https://github.com/antfu/vite-plugin-md/blob/24ae1046f02669dcaf0040483920544b4277a12b/src/markdown.ts#L91

I am looking into your source, how support for defineExpose could be added, but I currently have no clue, where and how the files are imported into vite-plugin-ssr.

Could you give a hint, so that I can try to add support of this feature into your repo?

brillout commented 2 years ago

Why not simply using https://vite-plugin-ssr.com/markdown#head-pagecontext-pageexports instead of a frontmatter?

oliverpool commented 2 years ago

Because it is much more user/editor friendly to edit a frontmatter in mardown than a JS-Block:

export const documentProps = {
  title: 'A Markdown Page',
  description: 'Example of setting `<title>` and `<meta name="description">`'
}

(for instance the Netlify CMS supports Frontmatter very nicely).

This is probably more of a general vite question, so I asked on the vite-plugin-md repo: https://github.com/antfu/vite-plugin-md/issues/38

brillout commented 2 years ago

👍