@docusaurus/plugin-sitemap 2.0.0-beta.14 → 2.0.0-beta.15
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.
- package/lib/createSitemap.d.ts +1 -1
- package/lib/createSitemap.js +7 -20
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -0
- package/lib/pluginOptionSchema.js +2 -5
- package/package.json +7 -7
- package/src/createSitemap.ts +8 -23
- package/src/index.ts +4 -1
- package/src/plugin-sitemap.d.ts +1 -2
- package/src/pluginOptionSchema.ts +3 -6
package/lib/createSitemap.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Options } from '@docusaurus/plugin-sitemap';
|
|
8
|
-
import { DocusaurusConfig } from '@docusaurus/types';
|
|
8
|
+
import type { DocusaurusConfig } from '@docusaurus/types';
|
|
9
9
|
export default function createSitemap(siteConfig: DocusaurusConfig, routesPaths: string[], options: Options): Promise<string>;
|
package/lib/createSitemap.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const sitemap_1 = require("sitemap");
|
|
10
|
-
const utils_1 = require("@docusaurus/utils");
|
|
11
10
|
const utils_common_1 = require("@docusaurus/utils-common");
|
|
12
11
|
async function createSitemap(siteConfig, routesPaths, options) {
|
|
13
12
|
const { url: hostname } = siteConfig;
|
|
@@ -15,31 +14,19 @@ async function createSitemap(siteConfig, routesPaths, options) {
|
|
|
15
14
|
throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
|
|
16
15
|
}
|
|
17
16
|
const { changefreq, priority } = options;
|
|
18
|
-
const sitemapStream = new sitemap_1.SitemapStream({
|
|
19
|
-
hostname,
|
|
20
|
-
});
|
|
21
|
-
function applySitemapTrailingSlash(routePath) {
|
|
22
|
-
// kept for retrocompatibility
|
|
23
|
-
// TODO remove deprecated trailingSlash option before 2022
|
|
24
|
-
if (options.trailingSlash) {
|
|
25
|
-
return (0, utils_1.addTrailingSlash)(routePath);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return (0, utils_common_1.applyTrailingSlash)(routePath, {
|
|
29
|
-
trailingSlash: siteConfig.trailingSlash,
|
|
30
|
-
baseUrl: siteConfig.baseUrl,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
17
|
+
const sitemapStream = new sitemap_1.SitemapStream({ hostname });
|
|
34
18
|
routesPaths
|
|
35
19
|
.filter((route) => !route.endsWith('404.html'))
|
|
36
|
-
.
|
|
37
|
-
url:
|
|
20
|
+
.forEach((routePath) => sitemapStream.write({
|
|
21
|
+
url: (0, utils_common_1.applyTrailingSlash)(routePath, {
|
|
22
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
23
|
+
baseUrl: siteConfig.baseUrl,
|
|
24
|
+
}),
|
|
38
25
|
changefreq,
|
|
39
26
|
priority,
|
|
40
27
|
}));
|
|
41
28
|
sitemapStream.end();
|
|
42
|
-
const generatedSitemap = await (0, sitemap_1.streamToPromise)(sitemapStream)
|
|
29
|
+
const generatedSitemap = (await (0, sitemap_1.streamToPromise)(sitemapStream)).toString();
|
|
43
30
|
return generatedSitemap;
|
|
44
31
|
}
|
|
45
32
|
exports.default = createSitemap;
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Options } from '@docusaurus/plugin-sitemap';
|
|
8
|
-
import { LoadContext, OptionValidationContext, ValidationResult, Plugin } from '@docusaurus/types';
|
|
8
|
+
import type { LoadContext, OptionValidationContext, ValidationResult, Plugin } from '@docusaurus/types';
|
|
9
9
|
export default function pluginSitemap(_context: LoadContext, options: Options): Plugin<void>;
|
|
10
10
|
export declare function validateOptions({ validate, options, }: OptionValidationContext<Options>): ValidationResult<Options>;
|
package/lib/index.js
CHANGED
|
@@ -16,6 +16,9 @@ function pluginSitemap(_context, options) {
|
|
|
16
16
|
return {
|
|
17
17
|
name: 'docusaurus-plugin-sitemap',
|
|
18
18
|
async postBuild({ siteConfig, routesPaths, outDir }) {
|
|
19
|
+
if (siteConfig.noIndex) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
19
22
|
// Generate sitemap.
|
|
20
23
|
const generatedSitemap = await (0, createSitemap_1.default)(siteConfig, routesPaths, options);
|
|
21
24
|
// Write sitemap file.
|
|
@@ -12,7 +12,6 @@ const sitemap_1 = require("sitemap");
|
|
|
12
12
|
exports.DEFAULT_OPTIONS = {
|
|
13
13
|
changefreq: sitemap_1.EnumChangefreq.WEEKLY,
|
|
14
14
|
priority: 0.5,
|
|
15
|
-
trailingSlash: false,
|
|
16
15
|
};
|
|
17
16
|
exports.PluginOptionSchema = utils_validation_1.Joi.object({
|
|
18
17
|
// TODO temporary (@alpha-71)
|
|
@@ -23,9 +22,7 @@ exports.PluginOptionSchema = utils_validation_1.Joi.object({
|
|
|
23
22
|
.valid(...Object.values(sitemap_1.EnumChangefreq))
|
|
24
23
|
.default(exports.DEFAULT_OPTIONS.changefreq),
|
|
25
24
|
priority: utils_validation_1.Joi.number().min(0).max(1).default(exports.DEFAULT_OPTIONS.priority),
|
|
26
|
-
trailingSlash: utils_validation_1.Joi.
|
|
27
|
-
|
|
25
|
+
trailingSlash: utils_validation_1.Joi.forbidden().messages({
|
|
26
|
+
'any.unknown': 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
|
|
28
27
|
}),
|
|
29
|
-
}).messages({
|
|
30
|
-
'deprecate.error': 'Option {#label} of the sitemap plugin is deprecated: {#msg}',
|
|
31
28
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-sitemap",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.15",
|
|
4
4
|
"description": "Simple sitemap generation plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-sitemap.d.ts",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
22
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
23
|
-
"@docusaurus/utils-common": "2.0.0-beta.
|
|
24
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
21
|
+
"@docusaurus/core": "2.0.0-beta.15",
|
|
22
|
+
"@docusaurus/utils": "2.0.0-beta.15",
|
|
23
|
+
"@docusaurus/utils-common": "2.0.0-beta.15",
|
|
24
|
+
"@docusaurus/utils-validation": "2.0.0-beta.15",
|
|
25
25
|
"fs-extra": "^10.0.0",
|
|
26
26
|
"sitemap": "^7.0.0",
|
|
27
27
|
"tslib": "^2.3.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
30
|
+
"@docusaurus/types": "2.0.0-beta.15"
|
|
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": "
|
|
39
|
+
"gitHead": "6cfad16436c07d8d11e5c2e1486dc59afd483e33"
|
|
40
40
|
}
|
package/src/createSitemap.ts
CHANGED
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {SitemapStream, streamToPromise} from 'sitemap';
|
|
9
9
|
import type {Options} from '@docusaurus/plugin-sitemap';
|
|
10
|
-
import {DocusaurusConfig} from '@docusaurus/types';
|
|
11
|
-
import {addTrailingSlash} from '@docusaurus/utils';
|
|
10
|
+
import type {DocusaurusConfig} from '@docusaurus/types';
|
|
12
11
|
import {applyTrailingSlash} from '@docusaurus/utils-common';
|
|
13
12
|
|
|
14
13
|
export default async function createSitemap(
|
|
@@ -22,28 +21,16 @@ export default async function createSitemap(
|
|
|
22
21
|
}
|
|
23
22
|
const {changefreq, priority} = options;
|
|
24
23
|
|
|
25
|
-
const sitemapStream = new SitemapStream({
|
|
26
|
-
hostname,
|
|
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, {
|
|
36
|
-
trailingSlash: siteConfig.trailingSlash,
|
|
37
|
-
baseUrl: siteConfig.baseUrl,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
24
|
+
const sitemapStream = new SitemapStream({hostname});
|
|
41
25
|
|
|
42
26
|
routesPaths
|
|
43
27
|
.filter((route) => !route.endsWith('404.html'))
|
|
44
|
-
.
|
|
28
|
+
.forEach((routePath) =>
|
|
45
29
|
sitemapStream.write({
|
|
46
|
-
url:
|
|
30
|
+
url: applyTrailingSlash(routePath, {
|
|
31
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
32
|
+
baseUrl: siteConfig.baseUrl,
|
|
33
|
+
}),
|
|
47
34
|
changefreq,
|
|
48
35
|
priority,
|
|
49
36
|
}),
|
|
@@ -51,9 +38,7 @@ export default async function createSitemap(
|
|
|
51
38
|
|
|
52
39
|
sitemapStream.end();
|
|
53
40
|
|
|
54
|
-
const generatedSitemap = await streamToPromise(sitemapStream).
|
|
55
|
-
sm.toString(),
|
|
56
|
-
);
|
|
41
|
+
const generatedSitemap = (await streamToPromise(sitemapStream)).toString();
|
|
57
42
|
|
|
58
43
|
return generatedSitemap;
|
|
59
44
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import fs from 'fs-extra';
|
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import type {Options} from '@docusaurus/plugin-sitemap';
|
|
11
11
|
import createSitemap from './createSitemap';
|
|
12
|
-
import {
|
|
12
|
+
import type {
|
|
13
13
|
LoadContext,
|
|
14
14
|
Props,
|
|
15
15
|
OptionValidationContext,
|
|
@@ -26,6 +26,9 @@ export default function pluginSitemap(
|
|
|
26
26
|
name: 'docusaurus-plugin-sitemap',
|
|
27
27
|
|
|
28
28
|
async postBuild({siteConfig, routesPaths, outDir}: Props) {
|
|
29
|
+
if (siteConfig.noIndex) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
29
32
|
// Generate sitemap.
|
|
30
33
|
const generatedSitemap = await createSitemap(
|
|
31
34
|
siteConfig,
|
package/src/plugin-sitemap.d.ts
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {EnumChangefreq} from 'sitemap';
|
|
8
|
+
import type {EnumChangefreq} from 'sitemap';
|
|
9
9
|
|
|
10
10
|
export type Options = {
|
|
11
11
|
changefreq?: EnumChangefreq;
|
|
12
12
|
priority?: number;
|
|
13
|
-
trailingSlash?: boolean;
|
|
14
13
|
};
|
|
@@ -12,7 +12,6 @@ import type {Options} from '@docusaurus/plugin-sitemap';
|
|
|
12
12
|
export const DEFAULT_OPTIONS: Required<Options> = {
|
|
13
13
|
changefreq: EnumChangefreq.WEEKLY,
|
|
14
14
|
priority: 0.5,
|
|
15
|
-
trailingSlash: false,
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
export const PluginOptionSchema = Joi.object({
|
|
@@ -25,10 +24,8 @@ export const PluginOptionSchema = Joi.object({
|
|
|
25
24
|
.valid(...Object.values(EnumChangefreq))
|
|
26
25
|
.default(DEFAULT_OPTIONS.changefreq),
|
|
27
26
|
priority: Joi.number().min(0).max(1).default(DEFAULT_OPTIONS.priority),
|
|
28
|
-
trailingSlash: Joi.
|
|
29
|
-
|
|
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
30
|
}),
|
|
31
|
-
}).messages({
|
|
32
|
-
'deprecate.error':
|
|
33
|
-
'Option {#label} of the sitemap plugin is deprecated: {#msg}',
|
|
34
31
|
});
|