@docusaurus/plugin-sitemap 2.0.0-beta.16 → 2.0.0-beta.19

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.
@@ -4,6 +4,9 @@
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 { Options } from '@docusaurus/plugin-sitemap';
8
7
  import type { DocusaurusConfig } from '@docusaurus/types';
9
- export default function createSitemap(siteConfig: DocusaurusConfig, routesPaths: string[], options: Options): Promise<string>;
8
+ import type { HelmetServerState } from 'react-helmet-async';
9
+ import type { PluginOptions } from './options';
10
+ export default function createSitemap(siteConfig: DocusaurusConfig, routesPaths: string[], head: {
11
+ [location: string]: HelmetServerState;
12
+ }, options: PluginOptions): Promise<string>;
@@ -8,16 +8,24 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const sitemap_1 = require("sitemap");
10
10
  const utils_common_1 = require("@docusaurus/utils-common");
11
- async function createSitemap(siteConfig, routesPaths, options) {
11
+ const utils_1 = require("@docusaurus/utils");
12
+ async function createSitemap(siteConfig, routesPaths, head, options) {
12
13
  const { url: hostname } = siteConfig;
13
14
  if (!hostname) {
14
15
  throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
15
16
  }
16
- const { changefreq, priority } = options;
17
+ const { changefreq, priority, ignorePatterns } = options;
18
+ const ignoreMatcher = (0, utils_1.createMatcher)(ignorePatterns);
17
19
  const sitemapStream = new sitemap_1.SitemapStream({ hostname });
18
- routesPaths
19
- .filter((route) => !route.endsWith('404.html'))
20
- .forEach((routePath) => sitemapStream.write({
20
+ function routeShouldBeIncluded(route) {
21
+ if (route.endsWith('404.html') || ignoreMatcher(route)) {
22
+ return false;
23
+ }
24
+ // https://github.com/staylor/react-helmet-async/pull/167
25
+ const meta = head[route]?.meta.toComponent();
26
+ return !meta?.some((tag) => tag.props.name === 'robots' && tag.props.content === 'noindex');
27
+ }
28
+ routesPaths.filter(routeShouldBeIncluded).forEach((routePath) => sitemapStream.write({
21
29
  url: (0, utils_common_1.applyTrailingSlash)(routePath, {
22
30
  trailingSlash: siteConfig.trailingSlash,
23
31
  baseUrl: siteConfig.baseUrl,
package/lib/index.d.ts CHANGED
@@ -4,7 +4,8 @@
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 { Options } from '@docusaurus/plugin-sitemap';
8
- import type { LoadContext, OptionValidationContext, ValidationResult, Plugin } from '@docusaurus/types';
9
- export default function pluginSitemap(_context: LoadContext, options: Options): Plugin<void>;
10
- export declare function validateOptions({ validate, options, }: OptionValidationContext<Options>): ValidationResult<Options>;
7
+ import type { PluginOptions, Options } from './options';
8
+ import type { LoadContext, Plugin } from '@docusaurus/types';
9
+ export default function pluginSitemap(context: LoadContext, options: PluginOptions): Plugin<void>;
10
+ export { validateOptions } from './options';
11
+ export type { PluginOptions, Options };
package/lib/index.js CHANGED
@@ -8,19 +8,18 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateOptions = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
- const createSitemap_1 = (0, tslib_1.__importDefault)(require("./createSitemap"));
14
- const pluginOptionSchema_1 = require("./pluginOptionSchema");
15
- function pluginSitemap(_context, options) {
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const createSitemap_1 = tslib_1.__importDefault(require("./createSitemap"));
14
+ function pluginSitemap(context, options) {
16
15
  return {
17
16
  name: 'docusaurus-plugin-sitemap',
18
- async postBuild({ siteConfig, routesPaths, outDir }) {
17
+ async postBuild({ siteConfig, routesPaths, outDir, head }) {
19
18
  if (siteConfig.noIndex) {
20
19
  return;
21
20
  }
22
21
  // Generate sitemap.
23
- const generatedSitemap = await (0, createSitemap_1.default)(siteConfig, routesPaths, options);
22
+ const generatedSitemap = await (0, createSitemap_1.default)(siteConfig, routesPaths, head, options);
24
23
  // Write sitemap file.
25
24
  const sitemapPath = path_1.default.join(outDir, 'sitemap.xml');
26
25
  try {
@@ -33,8 +32,5 @@ function pluginSitemap(_context, options) {
33
32
  };
34
33
  }
35
34
  exports.default = pluginSitemap;
36
- function validateOptions({ validate, options, }) {
37
- const validatedOptions = validate(pluginOptionSchema_1.PluginOptionSchema, options);
38
- return validatedOptions;
39
- }
40
- exports.validateOptions = validateOptions;
35
+ var options_1 = require("./options");
36
+ Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { EnumChangefreq } from 'sitemap';
8
+ import type { OptionValidationContext } from '@docusaurus/types';
9
+ export declare type PluginOptions = {
10
+ /** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
11
+ changefreq: EnumChangefreq;
12
+ /** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
13
+ priority: number;
14
+ /**
15
+ * A list of glob patterns; matching route paths will be filtered from the
16
+ * sitemap. Note that you may need to include the base URL in here.
17
+ */
18
+ ignorePatterns: string[];
19
+ };
20
+ export declare type Options = Partial<PluginOptions>;
21
+ export declare const DEFAULT_OPTIONS: PluginOptions;
22
+ export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
@@ -6,15 +6,15 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.PluginOptionSchema = exports.DEFAULT_OPTIONS = void 0;
9
+ exports.validateOptions = exports.DEFAULT_OPTIONS = void 0;
10
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
11
  const sitemap_1 = require("sitemap");
12
12
  exports.DEFAULT_OPTIONS = {
13
13
  changefreq: sitemap_1.EnumChangefreq.WEEKLY,
14
14
  priority: 0.5,
15
+ ignorePatterns: [],
15
16
  };
16
- exports.PluginOptionSchema = utils_validation_1.Joi.object({
17
- // TODO temporary (@alpha-71)
17
+ const PluginOptionSchema = utils_validation_1.Joi.object({
18
18
  cacheTime: utils_validation_1.Joi.forbidden().messages({
19
19
  'any.unknown': 'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
20
20
  }),
@@ -22,7 +22,15 @@ exports.PluginOptionSchema = utils_validation_1.Joi.object({
22
22
  .valid(...Object.values(sitemap_1.EnumChangefreq))
23
23
  .default(exports.DEFAULT_OPTIONS.changefreq),
24
24
  priority: utils_validation_1.Joi.number().min(0).max(1).default(exports.DEFAULT_OPTIONS.priority),
25
+ ignorePatterns: utils_validation_1.Joi.array()
26
+ .items(utils_validation_1.Joi.string())
27
+ .default(exports.DEFAULT_OPTIONS.ignorePatterns),
25
28
  trailingSlash: utils_validation_1.Joi.forbidden().messages({
26
29
  'any.unknown': 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
27
30
  }),
28
31
  });
32
+ function validateOptions({ validate, options, }) {
33
+ const validatedOptions = validate(PluginOptionSchema, options);
34
+ return validatedOptions;
35
+ }
36
+ exports.validateOptions = validateOptions;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-sitemap",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.19",
4
4
  "description": "Simple sitemap generation plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
- "types": "src/plugin-sitemap.d.ts",
6
+ "types": "lib/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
9
  "watch": "tsc --watch"
@@ -18,16 +18,16 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "2.0.0-beta.16",
22
- "@docusaurus/utils": "2.0.0-beta.16",
23
- "@docusaurus/utils-common": "2.0.0-beta.16",
24
- "@docusaurus/utils-validation": "2.0.0-beta.16",
25
- "fs-extra": "^10.0.1",
21
+ "@docusaurus/core": "2.0.0-beta.19",
22
+ "@docusaurus/utils": "2.0.0-beta.19",
23
+ "@docusaurus/utils-common": "2.0.0-beta.19",
24
+ "@docusaurus/utils-validation": "2.0.0-beta.19",
25
+ "fs-extra": "^10.1.0",
26
26
  "sitemap": "^7.1.1",
27
- "tslib": "^2.3.1"
27
+ "tslib": "^2.4.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@docusaurus/types": "2.0.0-beta.16"
30
+ "@docusaurus/types": "2.0.0-beta.19"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": "^16.8.4 || ^17.0.0",
@@ -36,5 +36,5 @@
36
36
  "engines": {
37
37
  "node": ">=14"
38
38
  },
39
- "gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
39
+ "gitHead": "a71e60a49cce93c1006ef10c41ac03187f057102"
40
40
  }
@@ -6,35 +6,52 @@
6
6
  */
7
7
 
8
8
  import {SitemapStream, streamToPromise} from 'sitemap';
9
- import type {Options} from '@docusaurus/plugin-sitemap';
10
- import type {DocusaurusConfig} from '@docusaurus/types';
11
9
  import {applyTrailingSlash} from '@docusaurus/utils-common';
10
+ import {createMatcher} from '@docusaurus/utils';
11
+ import type {DocusaurusConfig} from '@docusaurus/types';
12
+ import type {HelmetServerState} from 'react-helmet-async';
13
+ import type {PluginOptions} from './options';
14
+ import type {ReactElement} from 'react';
12
15
 
13
16
  export default async function createSitemap(
14
17
  siteConfig: DocusaurusConfig,
15
18
  routesPaths: string[],
16
- options: Options,
19
+ head: {[location: string]: HelmetServerState},
20
+ options: PluginOptions,
17
21
  ): Promise<string> {
18
22
  const {url: hostname} = siteConfig;
19
23
  if (!hostname) {
20
24
  throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
21
25
  }
22
- const {changefreq, priority} = options;
26
+ const {changefreq, priority, ignorePatterns} = options;
27
+
28
+ const ignoreMatcher = createMatcher(ignorePatterns);
23
29
 
24
30
  const sitemapStream = new SitemapStream({hostname});
25
31
 
26
- routesPaths
27
- .filter((route) => !route.endsWith('404.html'))
28
- .forEach((routePath) =>
29
- sitemapStream.write({
30
- url: applyTrailingSlash(routePath, {
31
- trailingSlash: siteConfig.trailingSlash,
32
- baseUrl: siteConfig.baseUrl,
33
- }),
34
- changefreq,
35
- priority,
36
- }),
32
+ function routeShouldBeIncluded(route: string) {
33
+ if (route.endsWith('404.html') || ignoreMatcher(route)) {
34
+ return false;
35
+ }
36
+ // https://github.com/staylor/react-helmet-async/pull/167
37
+ const meta = head[route]?.meta.toComponent() as unknown as
38
+ | ReactElement[]
39
+ | undefined;
40
+ return !meta?.some(
41
+ (tag) => tag.props.name === 'robots' && tag.props.content === 'noindex',
37
42
  );
43
+ }
44
+
45
+ routesPaths.filter(routeShouldBeIncluded).forEach((routePath) =>
46
+ sitemapStream.write({
47
+ url: applyTrailingSlash(routePath, {
48
+ trailingSlash: siteConfig.trailingSlash,
49
+ baseUrl: siteConfig.baseUrl,
50
+ }),
51
+ changefreq,
52
+ priority,
53
+ }),
54
+ );
38
55
 
39
56
  sitemapStream.end();
40
57
 
package/src/index.ts CHANGED
@@ -7,25 +7,18 @@
7
7
 
8
8
  import fs from 'fs-extra';
9
9
  import path from 'path';
10
- import type {Options} from '@docusaurus/plugin-sitemap';
11
10
  import createSitemap from './createSitemap';
12
- import type {
13
- LoadContext,
14
- Props,
15
- OptionValidationContext,
16
- ValidationResult,
17
- Plugin,
18
- } from '@docusaurus/types';
19
- import {PluginOptionSchema} from './pluginOptionSchema';
11
+ import type {PluginOptions, Options} from './options';
12
+ import type {LoadContext, Plugin} from '@docusaurus/types';
20
13
 
21
14
  export default function pluginSitemap(
22
- _context: LoadContext,
23
- options: Options,
15
+ context: LoadContext,
16
+ options: PluginOptions,
24
17
  ): Plugin<void> {
25
18
  return {
26
19
  name: 'docusaurus-plugin-sitemap',
27
20
 
28
- async postBuild({siteConfig, routesPaths, outDir}: Props) {
21
+ async postBuild({siteConfig, routesPaths, outDir, head}) {
29
22
  if (siteConfig.noIndex) {
30
23
  return;
31
24
  }
@@ -33,6 +26,7 @@ export default function pluginSitemap(
33
26
  const generatedSitemap = await createSitemap(
34
27
  siteConfig,
35
28
  routesPaths,
29
+ head,
36
30
  options,
37
31
  );
38
32
 
@@ -47,10 +41,5 @@ export default function pluginSitemap(
47
41
  };
48
42
  }
49
43
 
50
- export function validateOptions({
51
- validate,
52
- options,
53
- }: OptionValidationContext<Options>): ValidationResult<Options> {
54
- const validatedOptions = validate(PluginOptionSchema, options);
55
- return validatedOptions;
56
- }
44
+ export {validateOptions} from './options';
45
+ export type {PluginOptions, Options};
package/src/options.ts ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {Joi} from '@docusaurus/utils-validation';
9
+ import {EnumChangefreq} from 'sitemap';
10
+ import type {OptionValidationContext} from '@docusaurus/types';
11
+
12
+ export type PluginOptions = {
13
+ /** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
14
+ changefreq: EnumChangefreq;
15
+ /** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
16
+ priority: number;
17
+ /**
18
+ * A list of glob patterns; matching route paths will be filtered from the
19
+ * sitemap. Note that you may need to include the base URL in here.
20
+ */
21
+ ignorePatterns: string[];
22
+ };
23
+
24
+ export type Options = Partial<PluginOptions>;
25
+
26
+ export const DEFAULT_OPTIONS: PluginOptions = {
27
+ changefreq: EnumChangefreq.WEEKLY,
28
+ priority: 0.5,
29
+ ignorePatterns: [],
30
+ };
31
+
32
+ const PluginOptionSchema = Joi.object({
33
+ cacheTime: Joi.forbidden().messages({
34
+ 'any.unknown':
35
+ 'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
36
+ }),
37
+ changefreq: Joi.string()
38
+ .valid(...Object.values(EnumChangefreq))
39
+ .default(DEFAULT_OPTIONS.changefreq),
40
+ priority: Joi.number().min(0).max(1).default(DEFAULT_OPTIONS.priority),
41
+ ignorePatterns: Joi.array()
42
+ .items(Joi.string())
43
+ .default(DEFAULT_OPTIONS.ignorePatterns),
44
+ trailingSlash: Joi.forbidden().messages({
45
+ 'any.unknown':
46
+ 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
47
+ }),
48
+ });
49
+
50
+ export function validateOptions({
51
+ validate,
52
+ options,
53
+ }: OptionValidationContext<Options, PluginOptions>): PluginOptions {
54
+ const validatedOptions = validate(PluginOptionSchema, options);
55
+ return validatedOptions;
56
+ }
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
- import { Joi } from '@docusaurus/utils-validation';
8
- import type { Options } from '@docusaurus/plugin-sitemap';
9
- export declare const DEFAULT_OPTIONS: Required<Options>;
10
- export declare const PluginOptionSchema: Joi.ObjectSchema<any>;
@@ -1,13 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import type {EnumChangefreq} from 'sitemap';
9
-
10
- export type Options = {
11
- changefreq?: EnumChangefreq;
12
- priority?: number;
13
- };
@@ -1,31 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import {Joi} from '@docusaurus/utils-validation';
9
- import {EnumChangefreq} from 'sitemap';
10
- import type {Options} from '@docusaurus/plugin-sitemap';
11
-
12
- export const DEFAULT_OPTIONS: Required<Options> = {
13
- changefreq: EnumChangefreq.WEEKLY,
14
- priority: 0.5,
15
- };
16
-
17
- export const PluginOptionSchema = Joi.object({
18
- // TODO temporary (@alpha-71)
19
- cacheTime: Joi.forbidden().messages({
20
- 'any.unknown':
21
- 'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
22
- }),
23
- changefreq: Joi.string()
24
- .valid(...Object.values(EnumChangefreq))
25
- .default(DEFAULT_OPTIONS.changefreq),
26
- priority: Joi.number().min(0).max(1).default(DEFAULT_OPTIONS.priority),
27
- trailingSlash: Joi.forbidden().messages({
28
- 'any.unknown':
29
- 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
30
- }),
31
- });