@docusaurus/plugin-sitemap 2.0.1 → 2.1.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.
@@ -9,6 +9,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const sitemap_1 = require("sitemap");
10
10
  const utils_common_1 = require("@docusaurus/utils-common");
11
11
  const utils_1 = require("@docusaurus/utils");
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 }));
26
+ }
12
27
  async function createSitemap(siteConfig, routesPaths, head, options) {
13
28
  const { url: hostname } = siteConfig;
14
29
  if (!hostname) {
@@ -16,14 +31,12 @@ async function createSitemap(siteConfig, routesPaths, head, options) {
16
31
  }
17
32
  const { changefreq, priority, ignorePatterns } = options;
18
33
  const ignoreMatcher = (0, utils_1.createMatcher)(ignorePatterns);
19
- const includedRoutes = routesPaths.filter((route) => {
20
- if (route.endsWith('404.html') || ignoreMatcher(route)) {
21
- return false;
22
- }
23
- // https://github.com/staylor/react-helmet-async/pull/167
24
- const meta = head[route]?.meta.toComponent();
25
- return !meta?.some((tag) => tag.props.name === 'robots' && tag.props.content === 'noindex');
26
- });
34
+ function isRouteExcluded(route) {
35
+ return (route.endsWith('404.html') ||
36
+ ignoreMatcher(route) ||
37
+ isNoIndexMetaRoute({ head, route }));
38
+ }
39
+ const includedRoutes = routesPaths.filter((route) => !isRouteExcluded(route));
27
40
  if (includedRoutes.length === 0) {
28
41
  return null;
29
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-sitemap",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Simple sitemap generation plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -18,19 +18,16 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "2.0.1",
22
- "@docusaurus/logger": "2.0.1",
23
- "@docusaurus/types": "2.0.1",
24
- "@docusaurus/utils": "2.0.1",
25
- "@docusaurus/utils-common": "2.0.1",
26
- "@docusaurus/utils-validation": "2.0.1",
21
+ "@docusaurus/core": "2.1.0",
22
+ "@docusaurus/logger": "2.1.0",
23
+ "@docusaurus/types": "2.1.0",
24
+ "@docusaurus/utils": "2.1.0",
25
+ "@docusaurus/utils-common": "2.1.0",
26
+ "@docusaurus/utils-validation": "2.1.0",
27
27
  "fs-extra": "^10.1.0",
28
28
  "sitemap": "^7.1.1",
29
29
  "tslib": "^2.4.0"
30
30
  },
31
- "devDependencies": {
32
- "@docusaurus/types": "2.0.0-beta.21"
33
- },
34
31
  "peerDependencies": {
35
32
  "react": "^16.8.4 || ^17.0.0",
36
33
  "react-dom": "^16.8.4 || ^17.0.0"
@@ -38,5 +35,5 @@
38
35
  "engines": {
39
36
  "node": ">=16.14"
40
37
  },
41
- "gitHead": "1ddee1c29cabf9bb52e4d78af6ebfaaabb1bc1f9"
38
+ "gitHead": "be9b0942641184213485eba7fd75ceb0b328d3f4"
42
39
  }
@@ -13,6 +13,40 @@ import type {DocusaurusConfig} from '@docusaurus/types';
13
13
  import type {HelmetServerState} from 'react-helmet-async';
14
14
  import type {PluginOptions} from './options';
15
15
 
16
+ function isNoIndexMetaRoute({
17
+ head,
18
+ route,
19
+ }: {
20
+ head: {[location: string]: HelmetServerState};
21
+ route: string;
22
+ }) {
23
+ const isNoIndexMetaTag = ({
24
+ name,
25
+ content,
26
+ }: {
27
+ name?: string;
28
+ content?: string;
29
+ }): boolean => {
30
+ if (!name || !content) {
31
+ return false;
32
+ }
33
+ return (
34
+ // meta name is not case-sensitive
35
+ name.toLowerCase() === 'robots' &&
36
+ // Robots directives are not case-sensitive
37
+ content.toLowerCase().includes('noindex')
38
+ );
39
+ };
40
+
41
+ // https://github.com/staylor/react-helmet-async/pull/167
42
+ const meta = head[route]?.meta.toComponent() as unknown as
43
+ | ReactElement<{name?: string; content?: string}>[]
44
+ | undefined;
45
+ return meta?.some((tag) =>
46
+ isNoIndexMetaTag({name: tag.props.name, content: tag.props.content}),
47
+ );
48
+ }
49
+
16
50
  export default async function createSitemap(
17
51
  siteConfig: DocusaurusConfig,
18
52
  routesPaths: string[],
@@ -27,18 +61,15 @@ export default async function createSitemap(
27
61
 
28
62
  const ignoreMatcher = createMatcher(ignorePatterns);
29
63
 
30
- const includedRoutes = routesPaths.filter((route) => {
31
- if (route.endsWith('404.html') || ignoreMatcher(route)) {
32
- return false;
33
- }
34
- // https://github.com/staylor/react-helmet-async/pull/167
35
- const meta = head[route]?.meta.toComponent() as unknown as
36
- | ReactElement<{name?: string; content?: string}>[]
37
- | undefined;
38
- return !meta?.some(
39
- (tag) => tag.props.name === 'robots' && tag.props.content === 'noindex',
64
+ function isRouteExcluded(route: string) {
65
+ return (
66
+ route.endsWith('404.html') ||
67
+ ignoreMatcher(route) ||
68
+ isNoIndexMetaRoute({head, route})
40
69
  );
41
- });
70
+ }
71
+
72
+ const includedRoutes = routesPaths.filter((route) => !isRouteExcluded(route));
42
73
 
43
74
  if (includedRoutes.length === 0) {
44
75
  return null;