--- sidebar_position: 10 slug: /api/plugins/@docusaurus/plugin-sitemap --- # 📦 plugin-sitemap import APITable from '@site/src/components/APITable'; This plugin creates sitemaps for your site so that search engine crawlers can crawl your site more accurately. :::warning production only This plugin is always inactive in development and **only active in production** because it works on the build output. ::: ## Installation {/* #installation */} ```bash npm2yarn npm install --save @docusaurus/plugin-sitemap ``` :::tip If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: ## Configuration {/* #configuration */} Accepted fields: ```mdx-code-block ``` | Name | Type | Default | Description | | --- | --- | --- | --- | | `lastmod` | `'date' \| 'datetime' \| null` | `'date'` | `date` is YYYY-MM-DD. `datetime` is a ISO 8601 datetime. `null` is disabled. See [sitemap docs](https://www.sitemaps.org/protocol.html#xmlTagDefinitions). | | `ignorePatterns` | `string[]` | `[]` | 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. | | `filename` | `string` | `sitemap.xml` | The path to the created sitemap file, relative to the output directory. Useful if you have two plugin instances outputting two files. | | `createSitemapItems` | [CreateSitemapItemsFn](#CreateSitemapItemsFn) \| undefined | `undefined` | An optional function which can be used to transform and / or filter the items in the sitemap. | ```mdx-code-block ``` ### Types {/* #types */} #### `CreateSitemapItemsFn` {/* #CreateSitemapItemsFn */} ```ts type CreateSitemapItemsFn = (params: { siteConfig: DocusaurusConfig; routes: RouteConfig[]; defaultCreateSitemapItems: CreateSitemapItemsFn; }) => Promise; ``` #### `SitemapItem` {/* #SitemapItem */} ```ts type SitemapItem = { url: string; lastmod?: string | null; changefreq?: | 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never' | null; priority?: number | null; }; ``` See the [sitemap protocol docs](https://www.sitemaps.org/protocol.html#xmlTagDefinitions) for the meaning of each field. :::info This plugin also respects some site config: - [`noIndex`](../docusaurus.config.js.mdx#noIndex): results in no sitemap generated - [`trailingSlash`](../docusaurus.config.js.mdx#trailingSlash): determines if the URLs in the sitemap have trailing slashes ::: :::note About `lastmod` The `lastmod` option will only output a sitemap `` tag if plugins provide [route metadata](../plugin-methods/lifecycle-apis.mdx#addRoute) 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 `` tag for their routes. ::: ### Example configuration {/* #ex-config */} You can configure this plugin through preset options or plugin options. :::tip Most Docusaurus users configure this plugin through the preset options. ::: ```js config-tabs // Preset Options: sitemap // Plugin Options: @docusaurus/plugin-sitemap const config = { lastmod: 'date', 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/')); }, }; ``` You can find your sitemap at `/sitemap.xml`. ### Emitting `changefreq` and `priority` {/* #changefreq-priority */} The plugin doesn't emit `` and `` tags, which [Google ignores](https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap). If you need them, use `createSitemapItems` to emit distinct values per URL: ```js config-tabs // Preset Options: sitemap // Plugin Options: @docusaurus/plugin-sitemap const config = { createSitemapItems: async (params) => { const {defaultCreateSitemapItems, ...rest} = params; const items = await defaultCreateSitemapItems(rest); return items.map((item) => ({ ...item, changefreq: item.url.includes('/blog/') ? 'weekly' : 'monthly', priority: item.url.includes('/docs/') ? 0.8 : 0.5, })); }, }; ```