mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-25 15:07:17 +02:00
feat(sitemap): allow customizing the output name (#7469)
* feat(sitemap): allow customizing the output name * add docs
This commit is contained in:
parent
9398bb2487
commit
7ab97d4726
3 changed files with 10 additions and 1 deletions
|
@ -32,7 +32,7 @@ export default function pluginSitemap(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Write sitemap file.
|
// Write sitemap file.
|
||||||
const sitemapPath = path.join(outDir, 'sitemap.xml');
|
const sitemapPath = path.join(outDir, options.filename);
|
||||||
try {
|
try {
|
||||||
await fs.outputFile(sitemapPath, generatedSitemap);
|
await fs.outputFile(sitemapPath, generatedSitemap);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -19,6 +19,11 @@ export type PluginOptions = {
|
||||||
* sitemap. Note that you may need to include the base URL in here.
|
* sitemap. Note that you may need to include the base URL in here.
|
||||||
*/
|
*/
|
||||||
ignorePatterns: string[];
|
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>;
|
export type Options = Partial<PluginOptions>;
|
||||||
|
@ -27,6 +32,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
|
||||||
changefreq: EnumChangefreq.WEEKLY,
|
changefreq: EnumChangefreq.WEEKLY,
|
||||||
priority: 0.5,
|
priority: 0.5,
|
||||||
ignorePatterns: [],
|
ignorePatterns: [],
|
||||||
|
filename: 'sitemap.xml',
|
||||||
};
|
};
|
||||||
|
|
||||||
const PluginOptionSchema = Joi.object<PluginOptions>({
|
const PluginOptionSchema = Joi.object<PluginOptions>({
|
||||||
|
@ -46,6 +52,7 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
|
||||||
'any.unknown':
|
'any.unknown':
|
||||||
'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
|
'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({
|
export function validateOptions({
|
||||||
|
|
|
@ -40,6 +40,7 @@ Accepted fields:
|
||||||
| `changefreq` | `string` | `'weekly'` | See [sitemap docs](https://www.sitemaps.org/protocol.html#xmlTagDefinitions) |
|
| `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) |
|
| `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. |
|
| `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>
|
</APITable>
|
||||||
|
|
||||||
|
@ -70,6 +71,7 @@ const config = {
|
||||||
changefreq: 'weekly',
|
changefreq: 'weekly',
|
||||||
priority: 0.5,
|
priority: 0.5,
|
||||||
ignorePatterns: ['/tags/**'],
|
ignorePatterns: ['/tags/**'],
|
||||||
|
filename: 'sitemap.xml',
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue