跳到主要内容
版本:Canary 🚧

📦 plugin-sitemap

这个插件会为你的站点创建一个站点地图,以便搜索引擎的爬虫能够更准确地爬取你的网站。

production only

这个插件在开发过程中始终不工作,只在生产环境中启用,因为它会在构建输出上工作。

安装流程

npm install --save @docusaurus/plugin-sitemap
提示

如果你已经安装了 @docusaurus/preset-classic,就不需要安装这个包了。

You can configure this plugin through the preset options.

配置

接受的字段:

参数类型默认值描述
lastmod'date' | 'datetime' | nullnulldate is YYYY-MM-DD. datetime is a ISO 8601 datetime. null is disabled. See sitemap docs.
changefreqstring | null'weekly'站点地图文档
prioritynumber | null0.5站点地图文档
ignorePatternsstring[][]一列 glob 模式。匹配成功的路径不会出现在站点地图中。 注意你可能要在这里加上 base URL。
filenamestringsitemap.xml创建的站点地图的路径,相对于输出目录。 如果你有两个插件实例输出两个文件,会很有用。
信息

这个插件会读取某些站点配置:

  • noIndex: results in no sitemap generated
  • trailingSlash: determines if the URLs in the sitemap have trailing slashes
About lastmod

The lastmod option will only output a sitemap <lastmod> tag if plugins provide route metadata attributes sourceFilePath and/or lastUpdatedAt.

All the official content plugins provide the metadata for routes backed by a content file (Markdown, MDX or React page components), but it is possible third-party plugin authors do not provide this information, and the plugin will not be able to output a <lastmod> tag for their routes.

示例配置

你可以通过预设选项或插件选项来配置这个插件。

提示

大多数 Docusaurus 用户通过预设选项配置此插件。

如果你使用预设,你可以通过预设选项配置这个插件:

docusaurus.config.js
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
sitemap: {
lastmod: 'date',
changefreq: 'weekly',
priority: 0.5,
ignorePatterns: ['/tags/**'],
filename: 'sitemap.xml',
},
},
],
],
};

你可以在 /sitemap.xml 找到你的网站地图。