@docusaurus/plugin-sitemap 3.7.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,11 +5,11 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { CreateSitemapItemsParams } from './types';
8
+ import type { RouteBuildMetadata } from '@docusaurus/types';
8
9
  import type { PluginOptions } from './options';
9
- import type { HelmetServerState } from 'react-helmet-async';
10
10
  type CreateSitemapParams = CreateSitemapItemsParams & {
11
- head: {
12
- [location: string]: HelmetServerState;
11
+ routesBuildMetadata: {
12
+ [location: string]: RouteBuildMetadata;
13
13
  };
14
14
  options: PluginOptions;
15
15
  };
@@ -15,16 +15,16 @@ const head_1 = require("./head");
15
15
  // - parent routes, used for layouts
16
16
  // - routes matching options.ignorePatterns
17
17
  // - routes with no index metadata
18
- function getSitemapRoutes({ routes, head, options }) {
18
+ function getSitemapRoutes({ routes, routesBuildMetadata, options, }) {
19
19
  const { ignorePatterns } = options;
20
20
  const ignoreMatcher = (0, utils_1.createMatcher)(ignorePatterns);
21
21
  function isRouteExcluded(route) {
22
- return (ignoreMatcher(route.path) || (0, head_1.isNoIndexMetaRoute)({ head, route: route.path }));
22
+ return (ignoreMatcher(route.path) ||
23
+ (0, head_1.isNoIndexMetaRoute)({ routesBuildMetadata, route: route.path }));
23
24
  }
24
25
  return (0, utils_1.flattenRoutes)(routes).filter((route) => !isRouteExcluded(route));
25
26
  }
26
27
  // Our default implementation receives some additional parameters on purpose
27
- // Params such as "head" are "messy" and not directly exposed to the user
28
28
  function createDefaultCreateSitemapItems(internalParams) {
29
29
  return async (params) => {
30
30
  const sitemapRoutes = getSitemapRoutes({ ...params, ...internalParams });
@@ -39,8 +39,8 @@ function createDefaultCreateSitemapItems(internalParams) {
39
39
  };
40
40
  }
41
41
  async function createSitemap(params) {
42
- const { head, options, routes, siteConfig } = params;
43
- const defaultCreateSitemapItems = createDefaultCreateSitemapItems({ head, options });
42
+ const { routesBuildMetadata, options, routes, siteConfig } = params;
43
+ const defaultCreateSitemapItems = createDefaultCreateSitemapItems({ routesBuildMetadata, options });
44
44
  const sitemapItems = params.options.createSitemapItems
45
45
  ? await params.options.createSitemapItems({
46
46
  routes,
package/lib/head.d.ts CHANGED
@@ -4,10 +4,10 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { HelmetServerState } from 'react-helmet-async';
8
- export declare function isNoIndexMetaRoute({ head, route, }: {
9
- head: {
10
- [location: string]: HelmetServerState;
7
+ import type { RouteBuildMetadata } from '@docusaurus/types';
8
+ export declare function isNoIndexMetaRoute({ routesBuildMetadata, route, }: {
9
+ routesBuildMetadata: {
10
+ [location: string]: RouteBuildMetadata;
11
11
  };
12
12
  route: string;
13
13
  }): boolean;
package/lib/head.js CHANGED
@@ -9,18 +9,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.isNoIndexMetaRoute = isNoIndexMetaRoute;
10
10
  // Maybe we want to add a routeConfig.metadata.noIndex instead?
11
11
  // But using Helmet is more reliable for third-party plugins...
12
- function isNoIndexMetaRoute({ head, route, }) {
13
- const isNoIndexMetaTag = ({ name, content, }) => {
14
- if (!name || !content) {
15
- return false;
16
- }
17
- return (
18
- // meta name is not case-sensitive
19
- name.toLowerCase() === 'robots' &&
20
- // Robots directives are not case-sensitive
21
- content.toLowerCase().includes('noindex'));
22
- };
23
- // https://github.com/staylor/react-helmet-async/pull/167
24
- const meta = head[route]?.meta.toComponent();
25
- return (meta?.some((tag) => isNoIndexMetaTag({ name: tag.props.name, content: tag.props.content })) ?? false);
12
+ function isNoIndexMetaRoute({ routesBuildMetadata, route, }) {
13
+ const routeBuildMetadata = routesBuildMetadata[route];
14
+ if (routeBuildMetadata) {
15
+ return routeBuildMetadata.noIndex;
16
+ }
17
+ return false;
26
18
  }
package/lib/index.js CHANGED
@@ -21,7 +21,7 @@ function pluginSitemap(context, options) {
21
21
  }
22
22
  return {
23
23
  name: PluginName,
24
- async postBuild({ siteConfig, routes, outDir, head }) {
24
+ async postBuild({ siteConfig, routes, outDir, routesBuildMetadata }) {
25
25
  if (siteConfig.noIndex) {
26
26
  return;
27
27
  }
@@ -29,7 +29,7 @@ function pluginSitemap(context, options) {
29
29
  const generatedSitemap = await (0, createSitemap_1.default)({
30
30
  siteConfig,
31
31
  routes,
32
- head,
32
+ routesBuildMetadata,
33
33
  options,
34
34
  });
35
35
  if (!generatedSitemap) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-sitemap",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "Simple sitemap generation plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -18,12 +18,12 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "3.7.0",
22
- "@docusaurus/logger": "3.7.0",
23
- "@docusaurus/types": "3.7.0",
24
- "@docusaurus/utils": "3.7.0",
25
- "@docusaurus/utils-common": "3.7.0",
26
- "@docusaurus/utils-validation": "3.7.0",
21
+ "@docusaurus/core": "3.8.0",
22
+ "@docusaurus/logger": "3.8.0",
23
+ "@docusaurus/types": "3.8.0",
24
+ "@docusaurus/utils": "3.8.0",
25
+ "@docusaurus/utils-common": "3.8.0",
26
+ "@docusaurus/utils-validation": "3.8.0",
27
27
  "fs-extra": "^11.1.1",
28
28
  "sitemap": "^7.1.1",
29
29
  "tslib": "^2.6.0"
@@ -38,5 +38,5 @@
38
38
  "engines": {
39
39
  "node": ">=18.0"
40
40
  },
41
- "gitHead": "dd59750c16fe6908a26f18806a54d4c3dbe6db43"
41
+ "gitHead": "948d63c42fad0ba24b7b531a9deb6167e64dc845"
42
42
  }
@@ -10,22 +10,26 @@ import {sitemapItemsToXmlString} from './xml';
10
10
  import {createSitemapItem} from './createSitemapItem';
11
11
  import {isNoIndexMetaRoute} from './head';
12
12
  import type {CreateSitemapItemsFn, CreateSitemapItemsParams} from './types';
13
- import type {RouteConfig} from '@docusaurus/types';
13
+ import type {RouteConfig, RouteBuildMetadata} from '@docusaurus/types';
14
14
  import type {PluginOptions} from './options';
15
- import type {HelmetServerState} from 'react-helmet-async';
16
15
 
17
16
  // Not all routes should appear in the sitemap, and we should filter:
18
17
  // - parent routes, used for layouts
19
18
  // - routes matching options.ignorePatterns
20
19
  // - routes with no index metadata
21
- function getSitemapRoutes({routes, head, options}: CreateSitemapParams) {
20
+ function getSitemapRoutes({
21
+ routes,
22
+ routesBuildMetadata,
23
+ options,
24
+ }: CreateSitemapParams) {
22
25
  const {ignorePatterns} = options;
23
26
 
24
27
  const ignoreMatcher = createMatcher(ignorePatterns);
25
28
 
26
29
  function isRouteExcluded(route: RouteConfig) {
27
30
  return (
28
- ignoreMatcher(route.path) || isNoIndexMetaRoute({head, route: route.path})
31
+ ignoreMatcher(route.path) ||
32
+ isNoIndexMetaRoute({routesBuildMetadata, route: route.path})
29
33
  );
30
34
  }
31
35
 
@@ -33,9 +37,8 @@ function getSitemapRoutes({routes, head, options}: CreateSitemapParams) {
33
37
  }
34
38
 
35
39
  // Our default implementation receives some additional parameters on purpose
36
- // Params such as "head" are "messy" and not directly exposed to the user
37
40
  function createDefaultCreateSitemapItems(
38
- internalParams: Pick<CreateSitemapParams, 'head' | 'options'>,
41
+ internalParams: Pick<CreateSitemapParams, 'routesBuildMetadata' | 'options'>,
39
42
  ): CreateSitemapItemsFn {
40
43
  return async (params) => {
41
44
  const sitemapRoutes = getSitemapRoutes({...params, ...internalParams});
@@ -55,17 +58,17 @@ function createDefaultCreateSitemapItems(
55
58
  }
56
59
 
57
60
  type CreateSitemapParams = CreateSitemapItemsParams & {
58
- head: {[location: string]: HelmetServerState};
61
+ routesBuildMetadata: {[location: string]: RouteBuildMetadata};
59
62
  options: PluginOptions;
60
63
  };
61
64
 
62
65
  export default async function createSitemap(
63
66
  params: CreateSitemapParams,
64
67
  ): Promise<string | null> {
65
- const {head, options, routes, siteConfig} = params;
68
+ const {routesBuildMetadata, options, routes, siteConfig} = params;
66
69
 
67
70
  const defaultCreateSitemapItems: CreateSitemapItemsFn =
68
- createDefaultCreateSitemapItems({head, options});
71
+ createDefaultCreateSitemapItems({routesBuildMetadata, options});
69
72
 
70
73
  const sitemapItems = params.options.createSitemapItems
71
74
  ? await params.options.createSitemapItems({
package/src/head.ts CHANGED
@@ -5,43 +5,21 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {ReactElement} from 'react';
9
- import type {HelmetServerState} from 'react-helmet-async';
8
+ import type {RouteBuildMetadata} from '@docusaurus/types';
10
9
 
11
10
  // Maybe we want to add a routeConfig.metadata.noIndex instead?
12
11
  // But using Helmet is more reliable for third-party plugins...
13
12
  export function isNoIndexMetaRoute({
14
- head,
13
+ routesBuildMetadata,
15
14
  route,
16
15
  }: {
17
- head: {[location: string]: HelmetServerState};
16
+ routesBuildMetadata: {[location: string]: RouteBuildMetadata};
18
17
  route: string;
19
18
  }): boolean {
20
- const isNoIndexMetaTag = ({
21
- name,
22
- content,
23
- }: {
24
- name?: string;
25
- content?: string;
26
- }): boolean => {
27
- if (!name || !content) {
28
- return false;
29
- }
30
- return (
31
- // meta name is not case-sensitive
32
- name.toLowerCase() === 'robots' &&
33
- // Robots directives are not case-sensitive
34
- content.toLowerCase().includes('noindex')
35
- );
36
- };
19
+ const routeBuildMetadata = routesBuildMetadata[route];
37
20
 
38
- // https://github.com/staylor/react-helmet-async/pull/167
39
- const meta = head[route]?.meta.toComponent() as unknown as
40
- | ReactElement<{name?: string; content?: string}>[]
41
- | undefined;
42
- return (
43
- meta?.some((tag) =>
44
- isNoIndexMetaTag({name: tag.props.name, content: tag.props.content}),
45
- ) ?? false
46
- );
21
+ if (routeBuildMetadata) {
22
+ return routeBuildMetadata.noIndex;
23
+ }
24
+ return false;
47
25
  }
package/src/index.ts CHANGED
@@ -28,7 +28,7 @@ export default function pluginSitemap(
28
28
  return {
29
29
  name: PluginName,
30
30
 
31
- async postBuild({siteConfig, routes, outDir, head}) {
31
+ async postBuild({siteConfig, routes, outDir, routesBuildMetadata}) {
32
32
  if (siteConfig.noIndex) {
33
33
  return;
34
34
  }
@@ -36,7 +36,7 @@ export default function pluginSitemap(
36
36
  const generatedSitemap = await createSitemap({
37
37
  siteConfig,
38
38
  routes,
39
- head,
39
+ routesBuildMetadata,
40
40
  options,
41
41
  });
42
42
  if (!generatedSitemap) {