diff --git a/packages/docusaurus-plugin-sitemap/src/index.ts b/packages/docusaurus-plugin-sitemap/src/index.ts index 9d9f75a442c5..3044f1feff8b 100644 --- a/packages/docusaurus-plugin-sitemap/src/index.ts +++ b/packages/docusaurus-plugin-sitemap/src/index.ts @@ -32,7 +32,7 @@ export default function pluginSitemap( ); // Write sitemap file. - const sitemapPath = path.join(outDir, 'sitemap.xml'); + const sitemapPath = path.join(outDir, options.filename); try { await fs.outputFile(sitemapPath, generatedSitemap); } catch (err) { diff --git a/packages/docusaurus-plugin-sitemap/src/options.ts b/packages/docusaurus-plugin-sitemap/src/options.ts index 5a8302424e83..9cc1fe1b8cc1 100644 --- a/packages/docusaurus-plugin-sitemap/src/options.ts +++ b/packages/docusaurus-plugin-sitemap/src/options.ts @@ -19,6 +19,11 @@ export type PluginOptions = { * sitemap. Note that you may need to include the base URL in here. */ ignorePatterns: string[]; + /** + * The path to the created sitemap file, relative to the output directory. + * Useful if you have two plugin instances outputting two files. + */ + filename: string; }; export type Options = Partial; @@ -27,9 +32,11 @@ export const DEFAULT_OPTIONS: PluginOptions = { changefreq: EnumChangefreq.WEEKLY, priority: 0.5, ignorePatterns: [], + filename: 'sitemap.xml', }; -const PluginOptionSchema = Joi.object({ +const PluginOptionSchema = Joi.object({ + // @ts-expect-error: forbidden cacheTime: Joi.forbidden().messages({ 'any.unknown': 'Option `cacheTime` in sitemap config is deprecated. Please remove it.', @@ -45,6 +52,7 @@ const PluginOptionSchema = Joi.object({ 'any.unknown': 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.', }), + filename: Joi.string().default(DEFAULT_OPTIONS.filename), }); export function validateOptions({ diff --git a/website/docs/api/plugins/plugin-sitemap.md b/website/docs/api/plugins/plugin-sitemap.md index 0d37d2345151..145b62d9e258 100644 --- a/website/docs/api/plugins/plugin-sitemap.md +++ b/website/docs/api/plugins/plugin-sitemap.md @@ -40,6 +40,7 @@ Accepted fields: | `changefreq` | `string` | `'weekly'` | See [sitemap docs](https://www.sitemaps.org/protocol.html#xmlTagDefinitions) | | `priority` | `number` | `0.5` | 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. | @@ -70,6 +71,7 @@ const config = { changefreq: 'weekly', priority: 0.5, ignorePatterns: ['/tags/**'], + filename: 'sitemap.xml', }; ```