|
| 1 | +--- |
| 2 | +date: 2018-11-7 |
| 3 | +tag: |
| 4 | + - frontmatter |
| 5 | + - vuepress |
| 6 | +--- |
| 7 | + |
| 8 | +# Front Matter in VuePress |
| 9 | + |
| 10 | +Any markdown file that contains a YAML front matter block will be processed by [gray-matter](https://github.com/jonschlinkert/gray-matter). The front matter must be the first thing in the markdown file and must take the form of valid YAML set between triple-dashed lines. Here is a basic example: |
| 11 | + |
| 12 | +```markdown |
| 13 | +--- |
| 14 | +title: Blogging Like a Hacker |
| 15 | +lang: en-US |
| 16 | +--- |
| 17 | +``` |
| 18 | + |
| 19 | +Between these triple-dashed lines, you can set predefined variables (see [below](#predefined-variables) for a reference), or even create custom ones of your own. These variables will then be available to you to access using <code>[$frontmatter](./global-computed.md#frontmatter)</code> at the rest of the page, plus all custom and theming components. |
| 20 | + |
| 21 | +::: tip |
| 22 | +Front matter variables are **optional** in VuePress. |
| 23 | +::: |
| 24 | + |
| 25 | +## Alternative Front Matter Formats |
| 26 | + |
| 27 | +In addition, VuePress also supports JSON or [TOML](https://github.com/toml-lang/toml) front matter. |
| 28 | + |
| 29 | +JSON front matter needs to start and end in curly braces: |
| 30 | + |
| 31 | +``` |
| 32 | +--- |
| 33 | +{ |
| 34 | + "title": "Blogging Like a Hacker", |
| 35 | + "lang": "en-US" |
| 36 | +} |
| 37 | +--- |
| 38 | +``` |
| 39 | + |
| 40 | +TOML front matter needs to be explicitly marked as TOML: |
| 41 | + |
| 42 | +``` |
| 43 | +---toml |
| 44 | +title = "Blogging Like a Hacker" |
| 45 | +lang = "en-US" |
| 46 | +--- |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | +## Predefined Variables |
| 51 | + |
| 52 | +### title |
| 53 | + |
| 54 | +- Type: `string` |
| 55 | +- Default: `h1_title || siteConfig.title` |
| 56 | + |
| 57 | +Title of current page. |
| 58 | + |
| 59 | +### lang |
| 60 | + |
| 61 | +- Type: `string` |
| 62 | +- Default: `en-US` |
| 63 | + |
| 64 | +Language of current page. |
| 65 | + |
| 66 | +### description |
| 67 | + |
| 68 | +- Type: `string` |
| 69 | +- Default: `siteConfig.description` |
| 70 | + |
| 71 | +Description of current page. |
| 72 | + |
| 73 | +### layout |
| 74 | + |
| 75 | +- Type: `string` |
| 76 | +- Default: `Layout` |
| 77 | + |
| 78 | +Set the layout component of the current page. |
| 79 | + |
| 80 | +### permalink |
| 81 | + |
| 82 | +- Type: `string` |
| 83 | +- Default: `siteConfig.permalink` |
| 84 | + |
| 85 | +Refer to: [Permalinks](./permalinks.md). |
| 86 | + |
| 87 | +### metaTitle |
| 88 | + |
| 89 | +- Type: `string` |
| 90 | +- Default: <code>\`${page.title} | ${siteConfig.title}\`</code> |
| 91 | + |
| 92 | +Override the default meta title. |
| 93 | + |
| 94 | +### meta |
| 95 | + |
| 96 | +- Type: `array` |
| 97 | +- Default: `undefined` |
| 98 | + |
| 99 | +Specify extra meta tags to be injected: |
| 100 | + |
| 101 | +``` yaml |
| 102 | +--- |
| 103 | +meta: |
| 104 | + - name: description |
| 105 | + content: hello |
| 106 | + - name: keywords |
| 107 | + content: super duper SEO |
| 108 | +--- |
| 109 | +``` |
| 110 | + |
| 111 | +## Predefined Variables Powered By Default Theme |
| 112 | + |
| 113 | +### navbar |
| 114 | + |
| 115 | +- Type: `boolean` |
| 116 | +- Default: `undefined` |
| 117 | + |
| 118 | +See: [Default Theme Config > Disable the Navbar](../theme/default-theme-config.md#disable-the-navbar). |
| 119 | + |
| 120 | +### sidebar |
| 121 | + |
| 122 | +- Type: `boolean|'auto'` |
| 123 | +- Default: `undefined` |
| 124 | + |
| 125 | +See: [Default Theme Config > Sidebar](../theme/default-theme-config.md#sidebar). |
0 commit comments