mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
3 years ago
|
# Frontmatter
|
||
|
|
||
2 years ago
|
## Usage
|
||
|
|
||
|
VitePress supports YAML frontmatter in all Markdown files, parsing them with [gray-matter](https://github.com/jonschlinkert/gray-matter). The frontmatter must be at the top of the Markdown file (before any elements including `<script>` tags), and must take the form of valid YAML set between triple-dashed lines. Example:
|
||
3 years ago
|
|
||
|
```md
|
||
|
---
|
||
|
title: Docs with VitePress
|
||
|
editLink: true
|
||
|
---
|
||
|
```
|
||
|
|
||
2 years ago
|
Many site or default theme config options have corresponding options in frontmatter. You can use frontmatter to override specific behavior for the current page only. For details, see [Frontmatter Config Reference](../reference/frontmatter-config).
|
||
2 years ago
|
|
||
2 years ago
|
You can also define custom frontmatter data of your own, to be used in dynamic Vue expressions on the page.
|
||
|
|
||
|
## Accessing Frontmatter Data
|
||
|
|
||
|
Frontmatter data can be accessed via the special `$frontmatter` global variable:
|
||
3 years ago
|
|
||
2 years ago
|
Here's an example of how you could use it in your Markdown file:
|
||
3 years ago
|
|
||
|
```md
|
||
|
---
|
||
|
title: Docs with VitePress
|
||
|
editLink: true
|
||
|
---
|
||
|
|
||
|
# {{ $frontmatter.title }}
|
||
|
|
||
|
Guide content
|
||
|
```
|
||
|
|
||
2 years ago
|
You can also access current page's frontmatter data in `<script setup>` with the [`useData()`](../reference/runtime-api#usedata) helper.
|
||
2 years ago
|
|
||
3 years ago
|
## Alternative Frontmatter Formats
|
||
3 years ago
|
|
||
|
VitePress also supports JSON frontmatter syntax, starting and ending in curly braces:
|
||
|
|
||
|
```json
|
||
|
---
|
||
|
{
|
||
|
"title": "Blogging Like a Hacker",
|
||
|
"editLink": true
|
||
|
}
|
||
|
---
|
||
|
```
|