Default Theme Config

This project is sponsored by bit

TIP

All options listed on this page apply to the default theme only. If you are using a custom theme, the options may be different.

Homepage

The default theme provides a homepage layout (which is used on the homepage of this very website). To use it, specify home: true plus some other metadata in your root README.md's YAML front matter. This is the actual data used on this site:

---
home: true
heroImage: /hero.png
actionText: Get Started →
actionLink: /guide/
features:
- title: Simplicity First
  details: Minimal setup with markdown-centered project structure helps you focus on writing.
- title: Vue-Powered
  details: Enjoy the dev experience of Vue + webpack, use Vue components in markdown, and develop custom themes with Vue.
- title: Performant
  details: VuePress generates pre-rendered static HTML for each page, and runs as an SPA once a page is loaded.
footer: MIT Licensed | Copyright © 2018-present Evan You
---

Any additional content after the YAML front matter will be parsed as normal markdown and rendered after the features section.

If you want to use a completely custom homepage layout, you can also use a Custom Layout.

The Navbar may contain your page title, Search Box, Navbar Links, Languages and Repository Link, all of them depends on your configuration.

You can add a logo to the navbar via themeConfig.logo. Logo can be placed in public folder.

// .vuepress/config.js
module.exports = {
  themeConfig: {
    logo: '/assets/img/logo.png',
  }
}

You can add links to the navbar via themeConfig.nav:

// .vuepress/config.js
module.exports = {
  themeConfig: {
    nav: [
      { text: 'Home', link: '/' },
      { text: 'Guide', link: '/guide/' },
      { text: 'External', link: 'https://google.com' },
    ]
  }
}

These links can also be dropdown menus if you provide an array of items instead of a link:

module.exports = {
  themeConfig: {
    nav: [
      {
        text: 'Languages',
        items: [
          { text: 'Chinese', link: '/language/chinese' },
          { text: 'Japanese', link: '/language/japanese' }
        ]
      }
    ]
  }
}

In addition, you can have sub groups inside a dropdown by having nested items:

module.exports = {
  themeConfig: {
    nav: [
      {
        text: 'Languages',
        items: [
          { text: 'Group1', items: [/*  */] },
          { text: 'Group2', items: [/*  */] }
        ]
      }
    ]
  }
}

Disable the Navbar

To disable the navbar globally, use themeConfig.navbar:

// .vuepress/config.js
module.exports = {
  themeConfig: {
    navbar: false
  }
}

You can disable the navbar for a specific page via YAML front matter:

---
navbar: false
---

To enable the sidebar, use themeConfig.sidebar. The basic configuration expects an Array of links:

// .vuepress/config.js
module.exports = {
  themeConfig: {
    sidebar: [
      '/',
      '/page-a',
      ['/page-b', 'Explicit link text']
    ]
  }
}

You can omit the .md extension, and paths ending with / are inferred as */README.md. The text for the link is automatically inferred (either from the first header in the page or explicit title in YAML front matter). If you wish to explicitly specify the link text, use an Array in form of [link, text].

The sidebar automatically displays links for headers in the current active page, nested under the link for the page itself. You can customize this behavior using themeConfig.sidebarDepth. The default depth is 1, which extracts the h2 headers. Setting it to 0 disables the header links, and the max value is 2 which extracts both h2 and h3 headers.

A page can also override this value via YAML front matter:

---
sidebarDepth: 2
---

The sidebar only displays links for headers in the current active page. You can display all header links for every page with themeConfig.displayAllHeaders: true:

module.exports = {
  themeConfig: {
    displayAllHeaders: true // Default: false
  }
}

By default, the nested header links and the hash in the URL are updated as the user scrolls to view the different sections of the page. This behavior can be disabled with the following theme config:

module.exports = {
  themeConfig: {
    activeHeaderLinks: false, // Default: true
  }
}

TIP

It is worth mentioning that when you disable this option, the corresponding script of this functionality will not be loaded. This is a small point in our performance optimization.

You can divide sidebar links into multiple groups by using objects:

// .vuepress/config.js
module.exports = {
  themeConfig: {
    sidebar: [
      {
        title: 'Group 1',
        collapsable: false,
        children: [
          '/'
        ]
      },
      {
        title: 'Group 2',
        children: [ /* ... */ ]
      }
    ]
  }
}

Sidebar groups are collapsable by default. You can force a group to be always open with collapsable: false.

Multiple Sidebars

If you wish to display different sidebars for different sections of content, first organize your pages into directories for each desired section:

.
├─ README.md
├─ contact.md
├─ about.md
├─ foo/
│  ├─ README.md
│  ├─ one.md
│  └─ two.md
└─ bar/
   ├─ README.md
   ├─ three.md
   └─ four.md

Then, update your configuration to define your sidebar for each section.

// .vuepress/config.js
module.exports = {
  themeConfig: {
    sidebar: {
      '/foo/': [
        '',     /* /foo/ */
        'one',  /* /foo/one.html */
        'two'   /* /foo/two.html */
      ],

      '/bar/': [
        '',      /* /bar/ */
        'three', /* /bar/three.html */
        'four'   /* /bar/four.html */
      ],

      // fallback
      '/': [
        '',        /* / */
        'contact', /* /contact.html */
        'about'    /* /about.html */
      ]
    }
  }
}

WARNING

Make sure to define the fallback configuration last.

VuePress checks each sidebar config from top to bottom. If the fallback configuration was first, VuePress would incorrectly match /foo/ or /bar/four.html because they both start with /.

Auto Sidebar for Single Pages

If you wish to automatically generate a sidebar that contains only the header links for the current page, you can use YAML front matter on that page:

---
sidebar: auto
---

You can also enable it in all pages by using config:

// .vuepress/config.js
module.exports = {
  themeConfig: {
    sidebar: 'auto'
  }
}

In multi-language mode, you can also apply it to a specific locale:

// .vuepress/config.js
module.exports = {
  themeConfig: {
     '/': {
       sidebar: 'auto'
     }
  }
}

Disabling the Sidebar

You can disable the sidebar on a specific page with YAML front matter:

---
sidebar: false
---

You can disable the built-in search box with themeConfig.search: false, and customize how many suggestions will be shown with themeConfig.searchMaxSuggestions:

module.exports = {
  themeConfig: {
    search: false,
    searchMaxSuggestions: 10
  }
}

TIP

Built-in Search only builds index from the title, h2 and h3 headers, if you need full text search, you can use Algolia Search.

The themeConfig.algolia option allows you to use Algolia DocSearch to replace the simple built-in search. To enable it, you need to provide at least apiKey and indexName:

module.exports = {
  themeConfig: {
    algolia: {
      apiKey: '<API_KEY>',
      indexName: '<INDEX_NAME>'
    }
  }
}

Note

Unlike the built-in search engine which works out of the box, Algolia DocSearch requires you to submit your site to them for indexing before it starts working.

For more options, refer to Algolia DocSearch's documentation.

Last Updated

The themeConfig.lastUpdated option allows you to get the UNIX timestamp(ms) of each file's last git commit, and it will also display at the bottom of each page in an appropriate format:

module.exports = {
  themeConfig: {
    lastUpdated: 'Last Updated', // string | boolean
  }
}

Note that it's off by default. If given a string, it will be displayed as a prefix (default value: Last Updated).

WARNING

Since lastUpdated is based on git, you can only use it in a git repository. Also, since the timestamp used comes from the git commit, it will display only after a first commit for a given page, and update only on subsequent commits of that page.

Service Worker

The themeConfig.serviceWorker option allows you to configure the service worker.

TIP

Please do not confuse this option with Config > serviceWorker, Config > serviceWorker is site-level, while this option is theme-level.

The themeConfig.serviceWorker.updatePopup option enables a popup to refresh site content. The popup will be shown when the site is updated (i.e. service worker is updated). It provides a refresh button to allow users to refresh contents immediately.

NOTE

If without the refresh button, the new service worker will be active after all clients are closed. This means that visitors cannot see new contents until they close all tabs of your site. But the refresh button activates the new service worker immediately.

module.exports = {
  themeConfig: {
    serviceWorker: {
      updatePopup: true // Boolean | Object, default to undefined.
      // If set to true, the default text config will be: 
      // updatePopup: { 
      //    message: "New content is available.", 
      //    buttonText: "Refresh" 
      // }
    }
  }
}

Prev and next links are automatically inferred based on the sidebar order of the active page. You can also explicitly overwrite or disable them using YAML front matter:

---
prev: ./some-other-page
next: false
---

Providing themeConfig.repo auto generates a GitHub link in the navbar and "Edit this page" links at the bottom of each page.

// .vuepress/config.js
module.exports = {
  themeConfig: {
    // Assumes GitHub. Can also be a full GitLab url.
    repo: 'vuejs/vuepress',
    // Customising the header label
    // Defaults to "GitHub"/"GitLab"/"Bitbucket" depending on `themeConfig.repo`
    repoLabel: 'Contribute!',

    // Optional options for generating "Edit this page" link

    // if your docs are in a different repo from your main project:
    docsRepo: 'vuejs/vuepress',
    // if your docs are not at the root of the repo:
    docsDir: 'docs',
    // if your docs are in a specific branch (defaults to 'master'):
    docsBranch: 'master',
    // defaults to false, set to true to enable
    editLinks: true,
    // custom text for edit link. Defaults to "Edit this page"
    editLinkText: 'Help us improve this page!'
  }
}

You can also hide the edit link on a specific page via YAML front matter:

---
editLink: false
---

Simple CSS Override

If you wish to apply simple overrides to the styling of the default theme, you can create an .vuepress/override.styl file. This is a Stylus file but you can use normal CSS syntax as well.

There are a few color variables you can tweak:

// showing default values
$accentColor = #3eaf7c
$textColor = #2c3e50
$borderColor = #eaecef
$codeBgColor = #282c34
$badgeTip = #42b983
$badgeWarning = darken(#ffe564, 35%)
$badgeError = #DA596

Existing issues < 0.12.0

In order to override the default variables mentioned above, override.styl will be imported at the end of the config.styl in default theme, and this file will be used by multiple files, so once you wrote styles here, your style would be duplicated by multiple times. See #637.

Migrate your styles to style.styl 0.12.0+

In fact, The stylus constants override should be completed before all Stylus files are compiled; and the user's additional CSS styles should be generated at the end of the final style file. Therefore, these two duties should not be completed by the same stylus file.

Start from 0.12.0, we split override.styl into two APIs: override.styl and style.styl. If you wrote styles at override.styl in the past, e.g.

// .vuepress/override.styl
$textColor = red // stylus constants override.

#my-style {} // your extra styles.

You'll need to separate the style part to style.styl:

// .vuepress/override.styl, SHOULD ONLY contain "stylus constants override".
$textColor = red
// .vuepress/style.styl, your extra styles.
#my-style {}

Custom Page Class

Sometimes, you may need to add a unique class for a specific page so that you can target content on that page only in custom CSS. You can add a class to the theme container div with pageClass in YAML front matter:

---
pageClass: custom-page-class
---

Then you can write CSS targeting that page only:

/* .vuepress/style.styl */

.theme-container.custom-page-class {
  /* page-specific rules */
}

Custom Layout for Specific Pages

By default the content of each *.md file is rendered in a <div class="page"> container, along with the sidebar, auto-generated edit links and prev/next links. If you wish to use a completely custom component in place of the page (while only keeping the navbar), you can again specify the component to use using YAML front matter:

---
layout: SpecialLayout
---

This will render .vuepress/components/SpecialLayout.vue for the given page.

Ejecting

You can copy the default theme source code into .vuepress/theme to fully customize the theme using the vuepress eject [targetDir] command. 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.

Last Updated: 10/21/2019, 3:28:22 PM