Skip to content

Commit

Permalink
feat(sitemap): allow customizing the output name
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed May 23, 2022
1 parent 3666a2e commit 0e06c40
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion packages/docusaurus-plugin-sitemap/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginOptions>;
Expand All @@ -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<PluginOptions>({
// @ts-expect-error: forbidden
cacheTime: Joi.forbidden().messages({
'any.unknown':
'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
Expand All @@ -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({
Expand Down
1 change: 1 addition & 0 deletions website/docs/api/plugins/plugin-sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

</APITable>

Expand Down

0 comments on commit 0e06c40

Please sign in to comment.