feat(sitemap): allow customizing the output name (#7469)

* feat(sitemap): allow customizing the output name

* add docs
This commit is contained in:
Joshua Chen 2022-05-27 22:30:59 +08:00 committed by GitHub
parent 9398bb2487
commit 7ab97d4726
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View file

@ -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) {

View file

@ -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<PluginOptions>;
@ -27,6 +32,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
changefreq: EnumChangefreq.WEEKLY,
priority: 0.5,
ignorePatterns: [],
filename: 'sitemap.xml',
};
const PluginOptionSchema = Joi.object<PluginOptions>({
@ -46,6 +52,7 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
'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({

View file

@ -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. |
</APITable>
@ -70,6 +71,7 @@ const config = {
changefreq: 'weekly',
priority: 0.5,
ignorePatterns: ['/tags/**'],
filename: 'sitemap.xml',
};
```