The document is only used for theme display, please go to the official site for the latest Vuepress documentation

Adding Extra Pages

Sometimes you might want to add some extra pages without creating a markdown file in the source directory.

With the help of Plugin API and Node API, we can do that with ease.

Add a Default Homepage

As a theme author, you may not require users to create a /README.md file as the homepage, but you want to provide a default one:

import { createPage } from '@vuepress/core';

export default {
  // all pages have been loaded after initialization
  async onInitialized(app) {
    // if the homepage does not exist
    if (app.pages.every((page) => page.path !== '/')) {
      // create a homepage
      const homepage = await createPage(app, {
        path: '/',
        // set frontmatter
        frontmatter: {
          layout: 'Layout',
        },
        // set markdown content
        content: `\
# Welcome to ${app.options.title}

This is the default homepage
`,
      })
      // add it to `app.pages`
      app.pages.push(homepage)
    }
  }
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26