Skip to main content
VitePress

Search documentation

Type to search this documentation.

On this pageOverview

Sitemap Generation

VitePress comes with out-of-the-box support for generating a sitemap.xml file for your site. To enable it, add the following to your .vitepress/config.js:

TypeScript
export default {
  sitemap: {
    hostname: 'https://example.com'
  }
}

To have <lastmod> tags in your sitemap.xml, you can enable the lastUpdated option.

Sitemap support is powered by the sitemap module. You can pass any options supported by it to the sitemap option in your config file. These will be passed directly to the SitemapStream constructor. Refer to the sitemap documentation for more details. Example:

TypeScript
export default {
  sitemap: {
    hostname: 'https://example.com',
    lastmodDateOnly: false
  }
}

If you're using base in your config, you should append it to the hostname option:

TypeScript
export default {
  base: '/my-site/',
  sitemap: {
    hostname: 'https://example.com/my-site/'
  }
}

You can use the sitemap.transformItems hook to modify the sitemap items before they are written to the sitemap.xml file. This hook is called with an array of sitemap items and expects an array of sitemap items to be returned. Example:

TypeScript
export default {
  sitemap: {
    hostname: 'https://example.com',
    transformItems: (items) => {
      // add new items or modify/filter existing items
      items.push({
        url: '/extra-page',
        changefreq: 'monthly',
        priority: 0.8
      })
      return items
    }
  }
}
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu