Skip to main content
Version: 3.2.1

📦 插件-站点地图

此插件为您的网站创建站点地图,以便搜索引擎爬虫能够更准确地抓取您的网站。

production only

此插件在开发中始终处于非活动状态,仅在生产环境中激活,因为它作用于构建输出。

安装

npm install --save @docusaurus/plugin-sitemap
tip

如果你使用预设的@docusaurus/preset-classic,你不需要将此插件作为依赖项安装。

你可以通过预设选项来配置此插件。

配置

接受的字段:

NameTypeDefaultDescription
lastmod'date' | 'datetime' | nullnulldate is YYYY-MM-DD. datetime is a ISO 8601 datetime. null is disabled. See sitemap docs.
changefreqstring | null'weekly'See sitemap docs
prioritynumber | null0.5See sitemap docs
ignorePatternsstring[][]A list of glob patterns; matching route paths will be filtered from the sitemap. Note that you may need to include the base URL in here.
filenamestringsitemap.xmlThe path to the created sitemap file, relative to the output directory. Useful if you have two plugin instances outputting two files.
info

此插件还遵循一些站点配置:

  • noIndex: 导致不生成站点地图
  • trailingSlash: 确定站点地图中的URL是否带有尾部斜杠

About lastmod

只有在插件提供路由元数据属性sourceFilePath和/或lastUpdatedAt时,lastmod选项才会输出站点地图标签。

所有官方内容插件都为由内容文件(Markdown、MDX或React页面组件)支持的路由提供元数据,但第三方插件作者可能不提供此信息,插件将无法为他们的路由输出标签。

示例配置

您可以通过预设选项或插件选项来配置此插件。

tip

大多数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找到您的网站地图。