From 0e06c40830376ec05c65c2c8ce9289c0e9f32ec4 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Mon, 23 May 2022 15:48:56 +0800 Subject: [PATCH 1/2] feat(sitemap): allow customizing the output name --- packages/docusaurus-plugin-sitemap/src/index.ts | 2 +- packages/docusaurus-plugin-sitemap/src/options.ts | 9 ++++++++- website/docs/api/plugins/plugin-sitemap.md | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) 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..b256ee89b875 100644 --- a/packages/docusaurus-plugin-sitemap/src/options.ts +++ b/packages/docusaurus-plugin-sitemap/src/options.ts @@ -19,6 +19,10 @@ 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. + */ + filename: string; }; export type Options = Partial; @@ -27,9 +31,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 +51,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..d36d4c1524c3 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. | From 5f5b9929b49fda4d065c5c456fcb8aa0e814293b Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 27 May 2022 20:43:32 +0800 Subject: [PATCH 2/2] add docs --- packages/docusaurus-plugin-sitemap/src/options.ts | 1 + website/docs/api/plugins/plugin-sitemap.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-sitemap/src/options.ts b/packages/docusaurus-plugin-sitemap/src/options.ts index b256ee89b875..9cc1fe1b8cc1 100644 --- a/packages/docusaurus-plugin-sitemap/src/options.ts +++ b/packages/docusaurus-plugin-sitemap/src/options.ts @@ -21,6 +21,7 @@ export type PluginOptions = { 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; }; diff --git a/website/docs/api/plugins/plugin-sitemap.md b/website/docs/api/plugins/plugin-sitemap.md index d36d4c1524c3..145b62d9e258 100644 --- a/website/docs/api/plugins/plugin-sitemap.md +++ b/website/docs/api/plugins/plugin-sitemap.md @@ -40,7 +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. | +| `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. | @@ -71,6 +71,7 @@ const config = { changefreq: 'weekly', priority: 0.5, ignorePatterns: ['/tags/**'], + filename: 'sitemap.xml', }; ```