Then you can import front matter attributes from .md file as default.
---
title: Awesome Title
description: Describe this awesome content
tags:
- "great"
- "awesome"
- "rad"
---
# This is awesome
Vite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production.
"Mode" enables you to import markdown file in various formats (HTML, ToC, React/Vue Component)
Mode.HTML
Import compiled HTML
# This is awesome
Vite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production.
import{html}from'./contents/the-doc.md';console.log(html)//=> "<h1>This is awesome</h1><p>ite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production.</p>"
Mode.TOC
Import ToC metadata
# vite
Vite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production.
## Status
## Getting Started
# Notes
MyComponent on markdown perform as a Vue component.
Type declarations
In TypeScript project, need to declare typedefs for .md file as you need.
declare module '*.md'{// "unknown" would be more detailed depends on how you structure frontmatterconstattributes: Record<string,unknown>;// When "Mode.TOC" is requestedconsttoc: {level: string,content: string}[];// When "Mode.HTML" is requestedconsthtml: string;// When "Mode.React" is requested. VFC could take a generic like React.VFC<{ MyComponent: TypeOfMyComponent }>importReactfrom'react'constReactComponent: React.VFC;// When "Mode.Vue" is requestedimport{ComponentOptions,Component}from'vue';constVueComponent: ComponentOptions;constVueComponentWith: (components: Record<string,Component>)=>ComponentOptions;// Modify below per your usageexport{attributes,toc,html,ReactComponent,VueComponent,VueComponentWith};}
请发表评论