diff --git a/packages/docusaurus-plugin-sitemap/src/createSitemap.ts b/packages/docusaurus-plugin-sitemap/src/createSitemap.ts index 87a897db6cdb..7c35ab22372c 100644 --- a/packages/docusaurus-plugin-sitemap/src/createSitemap.ts +++ b/packages/docusaurus-plugin-sitemap/src/createSitemap.ts @@ -10,7 +10,7 @@ import {createMatcher, flattenRoutes} from '@docusaurus/utils'; import {sitemapItemsToXmlString} from './xml'; import {createSitemapItem} from './createSitemapItem'; import type {SitemapItem, DefaultCreateSitemapParams} from './types'; -import type {RouteConfig} from '@docusaurus/types'; +import type {DocusaurusConfig, RouteConfig} from '@docusaurus/types'; import type {HelmetServerState} from 'react-helmet-async'; // Maybe we want to add a routeConfig.metadata.noIndex instead? @@ -89,16 +89,28 @@ export default async function createSitemap( params: DefaultCreateSitemapParams, ): Promise { const {head, options, routes, siteConfig} = params; - const createSitemapItems = - params.options.createSitemapItems ?? defaultCreateSitemapItems; - const sitemapItems = await createSitemapItems({ - head, - options, - routes, - siteConfig, - defaultCreateSitemapItems, - }); + const sitemapItems = params.options.createSitemapItems + ? await params.options.createSitemapItems({ + routes, + siteConfig, + defaultCreateSitemapItems: (userParams: { + routes: RouteConfig[]; + siteConfig: DocusaurusConfig; + }) => + defaultCreateSitemapItems({ + head, + options, + ...userParams, + }), + }) + : await defaultCreateSitemapItems({ + head, + options, + routes, + siteConfig, + }); + if (sitemapItems.length === 0) { return null; } diff --git a/packages/docusaurus-plugin-sitemap/src/options.ts b/packages/docusaurus-plugin-sitemap/src/options.ts index c24a1c02ffa4..3211b0bc86bd 100644 --- a/packages/docusaurus-plugin-sitemap/src/options.ts +++ b/packages/docusaurus-plugin-sitemap/src/options.ts @@ -58,9 +58,12 @@ type CreateSitemapItemsFn = ( params: CreateSitemapItemsParams, ) => Promise; -type CreateSitemapItemsParams = DefaultCreateSitemapParams & { +type CreateSitemapItemsParams = Omit< + DefaultCreateSitemapParams, + 'head' | 'options' +> & { defaultCreateSitemapItems: ( - params: DefaultCreateSitemapParams, + params: Omit, ) => Promise; }; diff --git a/website/docs/api/plugins/plugin-sitemap.mdx b/website/docs/api/plugins/plugin-sitemap.mdx index 0f54d412248e..16d5539fc6b8 100644 --- a/website/docs/api/plugins/plugin-sitemap.mdx +++ b/website/docs/api/plugins/plugin-sitemap.mdx @@ -58,8 +58,6 @@ Accepted fields: type CreateSitemapItemsFn = (params: { siteConfig: DocusaurusConfig; routes: RouteConfig[]; - head: {[location: string]: HelmetServerState}; - options: PluginOptions; }) => Promise; ```