sitemap
为你的站点生成网站地图。
使用
npm i -D @vuepress/plugin-sitemap@nextimport { sitemapPlugin } from '@vuepress/plugin-sitemap'
export default {
plugins: [
sitemapPlugin({
hostname: 'https://example.com',
}),
],
}hostname 选项是必须的,网站地图的链接由它生成。
插件会使用来自 @vuepress/plugin-git 的最后更新时间,并根据多语言配置声明每个页面的其他语言版本地址。
链接控制
默认情况下,除 404 页面外站点的所有链接都会被包含在网站地图中。
- 使用 extraUrls 选项包含非 VuePress 生成的页面,通常是 public 目录下的文件;
- 使用 excludePaths 选项,或将页面的
sitemapFrontmatter 设置为false,来排除页面。
更新周期
页面默认的更新周期为 daily,可以通过 changefreq 选项修改,也可以通过页面的 sitemap.changefreq Frontmatter 单独设置。
合法的周期为 always、hourly、daily、weekly、monthly、yearly 与 never。
修改时间
modifyTimeGetter 选项以 ISO 字符串格式返回页面的最后修改时间,默认来自 @vuepress/plugin-git。
// 基于文件的最后修改时间
;({
modifyTimeGetter: (page, app) =>
fs.statSync(app.dir.source(page.filePathRelative)).mtime.toISOString(),
})robots.txt
网站地图会被搜索引擎读取,因此你应当在 .vuepress/public 目录下提供有效的 robots.txt 以允许爬虫访问。最简单的写法为:
User-agent: *
Allow: /选项
hostname必填
string站点部署的域名。
extraUrls
string[]需要额外包含的链接,例如 ['/about.html', '/api/']。
excludePaths
string[]默认值
['/404.html']不需要收录的页面路径,请以绝对路径开头。
sitemapFilename
string默认值
'sitemap.xml'网站地图的输出文件名,相对于输出目录。
sitemapXSLFilename
string默认值
'sitemap.xsl'XSL 文件的输出文件名,相对于输出目录。
sitemapXSLTemplate
stringXSL 模板的内容,默认为内置的 sitemap.xsl。
changefreq
'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never'默认值
'daily'页面默认的更新周期。参考:更新周期。
modifyTimeGetter
(page: Page, app: App) => string页面最后修改时间的获取器。参考:修改时间。
xmlNameSpace
{ news: boolean; video: boolean; xhtml: boolean; image: boolean; custom?: string[] }需要启用的 XML 命名空间,默认全部启用。
devServer
boolean是否在开发服务器中生成网站地图。
devHostname
string默认值
'http://localhost:${port}'开发服务器中使用的域名。
Frontmatter
sitemap
SitemapFrontmatterOption | false是否将页面包含在网站地图中,或页面的网站地图配置。
sitemap.changefreq
'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never'默认值
'daily'页面的更新周期。
sitemap.priority
number页面的优先级,范围 0 至 1。
sitemap.img
SitemapImageOption[]页面的图片。
sitemap.video
SitemapVideoOption[]页面的视频。
sitemap.news
SitemapNewsOption[]页面的新闻。
