Skip to main content
Version: 3.5.1

📦 plugin-sitemap

该插件为你的网站创建站点地图,以便搜索引擎抓取工具可以更准确地抓取你的网站。

¥This plugin creates sitemaps for your site so that search engine crawlers can crawl your site more accurately.

仅限生产

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

¥This plugin is always inactive in development and only active in production because it works on the build output.

安装

¥Installation

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

如果你使用预设 @docusaurus/preset-classic,则无需安装此插件作为依赖。

¥If you use the preset @docusaurus/preset-classic, you don't need to install this plugin as a dependency.

你可以通过 预设选项.conf 配置该插件。

¥You can configure this plugin through the preset options.

配置

¥Configuration

接受的字段:

¥Accepted fields:

名称类型默认描述
lastmod'date' | 'datetime' | nullnulldate 是 YYYY-MM-DD。datetime 是 ISO 8601 日期时间。null 已禁用。参见 站点地图文档
changefreqstring | null'weekly'站点地图文档
prioritynumber | null0.5站点地图文档
ignorePatternsstring[][]通配符模式列表;匹配的路由路径将从站点地图中过滤掉。请注意,你可能需要在此处包含基本 URL。
filenamestringsitemap.xml创建的站点地图文件的路径,相对于输出目录。如果你有两个输出两个文件的插件实例,则很有用。
createSitemapItemsCreateSitemapItemsFn | undefinedundefined一个可选函数,可用于转换和/或过滤站点地图中的项目。

类型

¥Types

CreateSitemapItemsFn

type CreateSitemapItemsFn = (params: {
siteConfig: DocusaurusConfig;
routes: RouteConfig[];
defaultCreateSitemapItems: CreateSitemapItemsFn;
}) => Promise<SitemapItem[]>;
信息

该插件还尊重一些站点配置:

¥This plugin also respects some site config:

  • noIndex:结果没有生成站点地图

    ¥noIndex: results in no sitemap generated

  • trailingSlash:确定站点地图中的 URL 是否有尾部斜杠

    ¥trailingSlash: determines if the URLs in the sitemap have trailing slashes

lastmod关于

如果插件提供 路由元数据 属性 sourceFilePath 和/或 lastUpdatedAt,则 lastmod 选项将仅输出站点地图 <lastmod> 标记。

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

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

¥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.

配置示例

¥Example configuration

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

¥You can configure this plugin through preset options or plugin options.

提示

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

¥Most Docusaurus users configure this plugin through the preset options.

If you use a preset, configure this plugin through the preset options:

docusaurus.config.js
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
sitemap: {
lastmod: 'date',
changefreq: 'weekly',
priority: 0.5,
ignorePatterns: ['/tags/**'],
filename: 'sitemap.xml',
createSitemapItems: async (params) => {
const {defaultCreateSitemapItems, ...rest} = params;
const items = await defaultCreateSitemapItems(rest);
return items.filter((item) => !item.url.includes('/page/'));
},
},
},
],
],
};

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

¥You can find your sitemap at /sitemap.xml.