sitemap
Generate a sitemap for your site.
Usage
npm i -D @vuepress/plugin-sitemap@nextimport { sitemapPlugin } from '@vuepress/plugin-sitemap'
export default {
plugins: [
sitemapPlugin({
hostname: 'https://example.com',
}),
],
}The hostname option is required, as the sitemap links are generated from it.
The plugin uses the last update time from @vuepress/plugin-git, and declares the alternative links of every page in other languages according to the locale config.
Link Control
By default, every link of the site is included in the sitemap, except the 404 page.
- Use the extraUrls option to include pages that are not generated by VuePress, typically files in the public directory.
- Use the excludePaths option, or set the
sitemapfrontmatter tofalse, to exclude a page.
Update Frequency
The default update frequency of a page is daily, which can be changed with the changefreq option, or per page with the sitemap.changefreq frontmatter.
The legal frequencies are always, hourly, daily, weekly, monthly, yearly and never.
Modify Time
The modifyTimeGetter option returns the last update time of a page in the ISO string format, which comes from @vuepress/plugin-git by default.
// Based on the last modified time of the file
;({
modifyTimeGetter: (page, app) =>
fs.statSync(app.dir.source(page.filePathRelative)).mtime.toISOString(),
})robots.txt
The sitemap is read by search engines, so you should provide a valid robots.txt in the .vuepress/public directory to allow the crawlers. The simplest one is:
User-agent: *
Allow: /Options
stringThe hostname where the site is deployed.
string[]The extra links to be included, e.g. ['/about.html', '/api/'].
string[]['/404.html']The page paths to be excluded, starting with an absolute path.
string'sitemap.xml'The output filename of the sitemap, relative to the output directory.
string'sitemap.xsl'The output filename of the XSL file, relative to the output directory.
stringThe content of the XSL template, which defaults to the built-in sitemap.xsl.
'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never''daily'The default update frequency of a page. See also: Update Frequency.
(page: Page, app: App) => stringThe getter of the last update time of a page. See also: Modify Time.
{ news: boolean; video: boolean; xhtml: boolean; image: boolean; custom?: string[] }The XML namespaces to enable, all of them are enabled by default.
booleanWhether to generate the sitemap in the development server.
string'http://localhost:${port}'The hostname used in the development server.
Frontmatter
SitemapFrontmatterOption | falseWhether to include the page in the sitemap, or the sitemap config of the page.
'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never''daily'The update frequency of the page.
numberThe priority of the page, from 0 to 1.
SitemapImageOption[]The images of the page.
SitemapVideoOption[]The videos of the page.
SitemapNewsOption[]The news of the page.
