Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. |
Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved

</APITable>

Expand Down