Skip to content

Commit

Permalink
fix: remove head and options from params
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyreilly committed Apr 30, 2024
1 parent 0065a3f commit fb069b1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
32 changes: 22 additions & 10 deletions packages/docusaurus-plugin-sitemap/src/createSitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -89,16 +89,28 @@ export default async function createSitemap(
params: DefaultCreateSitemapParams,
): Promise<string | null> {
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;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/docusaurus-plugin-sitemap/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ type CreateSitemapItemsFn = (
params: CreateSitemapItemsParams,
) => Promise<SitemapItem[]>;

type CreateSitemapItemsParams = DefaultCreateSitemapParams & {
type CreateSitemapItemsParams = Omit<
DefaultCreateSitemapParams,
'head' | 'options'
> & {
defaultCreateSitemapItems: (
params: DefaultCreateSitemapParams,
params: Omit<DefaultCreateSitemapParams, 'head' | 'options'>,
) => Promise<SitemapItem[]>;
};

Expand Down
2 changes: 0 additions & 2 deletions website/docs/api/plugins/plugin-sitemap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ Accepted fields:
type CreateSitemapItemsFn = (params: {
siteConfig: DocusaurusConfig;
routes: RouteConfig[];
head: {[location: string]: HelmetServerState};
options: PluginOptions;
}) => Promise<SitemapItem[]>;
```

Expand Down

0 comments on commit fb069b1

Please sign in to comment.