@docusaurus/plugin-sitemap 2.0.0-beta.1ab8aa0af → 2.0.0-beta.2

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.
@@ -8,19 +8,30 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const sitemap_1 = require("sitemap");
10
10
  const utils_1 = require("@docusaurus/utils");
11
+ const utils_common_1 = require("@docusaurus/utils-common");
11
12
  async function createSitemap(siteConfig, routesPaths, options) {
12
13
  const { url: hostname } = siteConfig;
13
14
  if (!hostname) {
14
- throw new Error('url in docusaurus.config.js cannot be empty/undefined');
15
+ throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
15
16
  }
16
17
  const { changefreq, priority, trailingSlash } = options;
17
18
  const sitemapStream = new sitemap_1.SitemapStream({
18
19
  hostname,
19
20
  });
21
+ function applySitemapTrailingSlash(routePath) {
22
+ // kept for retrocompatibility
23
+ // TODO remove deprecated trailingSlash option before 2022
24
+ if (options.trailingSlash) {
25
+ return utils_1.addTrailingSlash(routePath);
26
+ }
27
+ else {
28
+ return utils_common_1.applyTrailingSlash(routePath, trailingSlash);
29
+ }
30
+ }
20
31
  routesPaths
21
32
  .filter((route) => !route.endsWith('404.html'))
22
33
  .map((routePath) => sitemapStream.write({
23
- url: trailingSlash ? utils_1.addTrailingSlash(routePath) : routePath,
34
+ url: applySitemapTrailingSlash(routePath),
24
35
  changefreq,
25
36
  priority,
26
37
  }));
package/lib/index.js CHANGED
@@ -24,7 +24,7 @@ function pluginSitemap(_context, options) {
24
24
  await fs_extra_1.default.outputFile(sitemapPath, generatedSitemap);
25
25
  }
26
26
  catch (err) {
27
- throw new Error(`Sitemap error: ${err}`);
27
+ throw new Error(`Writing sitemap failed: ${err}`);
28
28
  }
29
29
  },
30
30
  };
@@ -23,5 +23,9 @@ exports.PluginOptionSchema = utils_validation_1.Joi.object({
23
23
  .valid(...Object.values(sitemap_1.EnumChangefreq))
24
24
  .default(exports.DEFAULT_OPTIONS.changefreq),
25
25
  priority: utils_validation_1.Joi.number().min(0).max(1).default(exports.DEFAULT_OPTIONS.priority),
26
- trailingSlash: utils_validation_1.Joi.bool().default(false),
26
+ trailingSlash: utils_validation_1.Joi.bool().default(false).warning('deprecate.error', {
27
+ msg: 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
28
+ }),
29
+ }).messages({
30
+ 'deprecate.error': 'Option {#label} of the sitemap plugin is deprecated: {#msg}',
27
31
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-sitemap",
3
- "version": "2.0.0-beta.1ab8aa0af",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "Simple sitemap generation plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -17,13 +17,14 @@
17
17
  },
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@docusaurus/core": "2.0.0-beta.1ab8aa0af",
21
- "@docusaurus/types": "2.0.0-beta.1ab8aa0af",
22
- "@docusaurus/utils": "2.0.0-beta.1ab8aa0af",
23
- "@docusaurus/utils-validation": "2.0.0-beta.1ab8aa0af",
24
- "fs-extra": "^9.1.0",
25
- "sitemap": "^6.3.6",
26
- "tslib": "^2.1.0"
20
+ "@docusaurus/core": "2.0.0-beta.2",
21
+ "@docusaurus/types": "2.0.0-beta.2",
22
+ "@docusaurus/utils": "2.0.0-beta.2",
23
+ "@docusaurus/utils-common": "2.0.0-beta.2",
24
+ "@docusaurus/utils-validation": "2.0.0-beta.2",
25
+ "fs-extra": "^10.0.0",
26
+ "sitemap": "^7.0.0",
27
+ "tslib": "^2.2.0"
27
28
  },
28
29
  "peerDependencies": {
29
30
  "react": "^16.8.4 || ^17.0.0",
@@ -32,5 +33,5 @@
32
33
  "engines": {
33
34
  "node": ">=12.13.0"
34
35
  },
35
- "gitHead": "63c06baac39707a1a4c3cc4c0031cb2163f256c4"
36
+ "gitHead": "883f07fddffaf1657407c8e202e370cc436e25f7"
36
37
  }
@@ -29,7 +29,9 @@ describe('createSitemap', () => {
29
29
  test('empty site', () => {
30
30
  return expect(async () => {
31
31
  await createSitemap({} as DocusaurusConfig, [], {});
32
- }).rejects.toThrow('url in docusaurus.config.js cannot be empty/undefined');
32
+ }).rejects.toThrow(
33
+ 'URL in docusaurus.config.js cannot be empty/undefined.',
34
+ );
33
35
  });
34
36
 
35
37
  test('exclusion of 404 page', async () => {
@@ -30,8 +30,13 @@ describe('normalizeSitemapPluginOptions', () => {
30
30
  priority: 0.9,
31
31
  trailingSlash: false,
32
32
  };
33
- const {value} = await PluginOptionSchema.validate(userOptions);
33
+ const {value, warning} = await PluginOptionSchema.validate(userOptions);
34
34
  expect(value).toEqual(userOptions);
35
+
36
+ expect(warning?.details?.length).toEqual(1);
37
+ expect(warning?.details[0].message).toMatchInlineSnapshot(
38
+ `"Option \\"trailingSlash\\" of the sitemap plugin is deprecated: Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it."`,
39
+ );
35
40
  });
36
41
 
37
42
  test('should reject out-of-range priority inputs', () => {
@@ -9,6 +9,7 @@ import {SitemapStream, streamToPromise} from 'sitemap';
9
9
  import {PluginOptions} from './types';
10
10
  import {DocusaurusConfig} from '@docusaurus/types';
11
11
  import {addTrailingSlash} from '@docusaurus/utils';
12
+ import {applyTrailingSlash} from '@docusaurus/utils-common';
12
13
 
13
14
  export default async function createSitemap(
14
15
  siteConfig: DocusaurusConfig,
@@ -17,7 +18,7 @@ export default async function createSitemap(
17
18
  ): Promise<string> {
18
19
  const {url: hostname} = siteConfig;
19
20
  if (!hostname) {
20
- throw new Error('url in docusaurus.config.js cannot be empty/undefined');
21
+ throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
21
22
  }
22
23
  const {changefreq, priority, trailingSlash} = options;
23
24
 
@@ -25,11 +26,21 @@ export default async function createSitemap(
25
26
  hostname,
26
27
  });
27
28
 
29
+ function applySitemapTrailingSlash(routePath: string): string {
30
+ // kept for retrocompatibility
31
+ // TODO remove deprecated trailingSlash option before 2022
32
+ if (options.trailingSlash) {
33
+ return addTrailingSlash(routePath);
34
+ } else {
35
+ return applyTrailingSlash(routePath, trailingSlash);
36
+ }
37
+ }
38
+
28
39
  routesPaths
29
40
  .filter((route) => !route.endsWith('404.html'))
30
41
  .map((routePath) =>
31
42
  sitemapStream.write({
32
- url: trailingSlash ? addTrailingSlash(routePath) : routePath,
43
+ url: applySitemapTrailingSlash(routePath),
33
44
  changefreq,
34
45
  priority,
35
46
  }),
package/src/index.ts CHANGED
@@ -38,7 +38,7 @@ export default function pluginSitemap(
38
38
  try {
39
39
  await fs.outputFile(sitemapPath, generatedSitemap);
40
40
  } catch (err) {
41
- throw new Error(`Sitemap error: ${err}`);
41
+ throw new Error(`Writing sitemap failed: ${err}`);
42
42
  }
43
43
  },
44
44
  };
@@ -25,5 +25,11 @@ export const PluginOptionSchema = Joi.object({
25
25
  .valid(...Object.values(EnumChangefreq))
26
26
  .default(DEFAULT_OPTIONS.changefreq),
27
27
  priority: Joi.number().min(0).max(1).default(DEFAULT_OPTIONS.priority),
28
- trailingSlash: Joi.bool().default(false),
28
+ trailingSlash: Joi.bool().default(false).warning('deprecate.error', {
29
+ msg:
30
+ 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
31
+ }),
32
+ }).messages({
33
+ 'deprecate.error':
34
+ 'Option {#label} of the sitemap plugin is deprecated: {#msg}',
29
35
  });