Custom Themes
VuePress uses Vue single file components for custom themes. To use a custom layout, create a directory in your docs root, and then create a Layout.vue
file:
From there it’s the same as developing a normal Vue application. It is entirely up to you how to organize your theme.
The Layout
component will be invoked once for every .md
file in docs
, and the metadata for the entire site and that specific page will be exposed respectively as this.$site
and this.$page
properties which are injected into every component in the app.
This is the value of $site
of this very website:
{
"title": "VuePress",
"base": "/",
"pages": [
{
"lastUpdated": 1524027677000,
"path": "/",
"title": "VuePress",
"frontmatter": {}
]
}
title
, description
and base
are copied from respective fields in .vuepress/config.js
. pages
contains an array of metadata objects for each page, including its path, page title (explicitly specified in YAML front matter or inferred from the first header on the page), and any YAML front matter data in that file.
If the user provided themeConfig
in .vuepress/config.js
, it will also be available as $site.themeConfig
. You can use this to allow users to customize behavior of your theme - for example, specifying categories and page order. You can then use these data together with $site.pages
to dynamically construct navigation links.
Finally, don’t forget that this.$route
and this.$router
are also available as part of Vue Router’s API.
::: tip
lastUpdated
is the UNIX timestamp of this file’s last git commit, for more details, refer to .
:::
Content Excerpt
If a markdown file contains a <!-- more -->
comment, any content above the comment will be extracted and exposed as . If you are building custom theme for blogging, this data can be used to render a post list with excerpts.
<template>
<div class="theme-container">
<Content/>
</div>
</template>
App Level Enhancements
Themes can enhance the Vue app that VuePress uses by exposing an enhanceApp.js
file at the root of the theme. The file should export default
a hook function which will receive an object containing some app level values. You can use this hook to install additional Vue plugins, register global components, or add additional router hooks:
Themes can be published on npm in raw Vue SFC format as vuepress-theme-xxx
.
To use a theme from an npm dependency, provide a theme
option in .vuepress/config.js
:
module.exports = {
}
VuePress will attempt to locate and use node_modules/vuepress-theme-awesome/Layout.vue
.
Customizing the Default Theme
The command will copy the default theme source code into .vuepress/theme
to allow complete customization. Note, however, once you eject, you are on your own and won’t be receiving future updates or bug fixes to the default theme even if you upgrade VuePress.