@docusaurus/plugin-sitemap 2.0.0-beta.15d451942 → 2.0.0-beta.18
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 +3 -3
- package/lib/createSitemap.js +10 -9
- package/lib/index.d.ts +4 -4
- package/lib/index.js +8 -9
- package/lib/options.d.ts +10 -0
- package/lib/{pluginOptionSchema.js → options.js} +10 -5
- package/package.json +14 -10
- package/src/createSitemap.ts +13 -14
- package/src/index.ts +10 -20
- package/src/{pluginOptionSchema.ts → options.ts} +16 -6
- package/src/{types.ts → plugin-sitemap.d.ts} +6 -4
- package/lib/.tsbuildinfo +0 -4159
- package/lib/pluginOptionSchema.d.ts +0 -10
- package/lib/types.d.ts +0 -12
- package/lib/types.js +0 -8
- package/src/__tests__/createSitemap.test.ts +0 -66
- package/src/__tests__/pluginOptionSchema.test.ts +0 -56
- package/tsconfig.json +0 -9
package/lib/createSitemap.d.ts
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
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 {
|
|
8
|
-
import { DocusaurusConfig } from '@docusaurus/types';
|
|
9
|
-
export default function createSitemap(siteConfig: DocusaurusConfig, routesPaths: string[], options:
|
|
7
|
+
import type { Options } from '@docusaurus/plugin-sitemap';
|
|
8
|
+
import type { DocusaurusConfig } from '@docusaurus/types';
|
|
9
|
+
export default function createSitemap(siteConfig: DocusaurusConfig, routesPaths: string[], options: Options): Promise<string>;
|
package/lib/createSitemap.js
CHANGED
|
@@ -7,25 +7,26 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const sitemap_1 = require("sitemap");
|
|
10
|
-
const
|
|
10
|
+
const utils_common_1 = require("@docusaurus/utils-common");
|
|
11
11
|
async function createSitemap(siteConfig, routesPaths, options) {
|
|
12
12
|
const { url: hostname } = siteConfig;
|
|
13
13
|
if (!hostname) {
|
|
14
|
-
throw new Error('
|
|
14
|
+
throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
|
|
15
15
|
}
|
|
16
|
-
const { changefreq, priority
|
|
17
|
-
const sitemapStream = new sitemap_1.SitemapStream({
|
|
18
|
-
hostname,
|
|
19
|
-
});
|
|
16
|
+
const { changefreq, priority } = options;
|
|
17
|
+
const sitemapStream = new sitemap_1.SitemapStream({ hostname });
|
|
20
18
|
routesPaths
|
|
21
19
|
.filter((route) => !route.endsWith('404.html'))
|
|
22
|
-
.
|
|
23
|
-
url:
|
|
20
|
+
.forEach((routePath) => sitemapStream.write({
|
|
21
|
+
url: (0, utils_common_1.applyTrailingSlash)(routePath, {
|
|
22
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
23
|
+
baseUrl: siteConfig.baseUrl,
|
|
24
|
+
}),
|
|
24
25
|
changefreq,
|
|
25
26
|
priority,
|
|
26
27
|
}));
|
|
27
28
|
sitemapStream.end();
|
|
28
|
-
const generatedSitemap = await sitemap_1.streamToPromise(sitemapStream)
|
|
29
|
+
const generatedSitemap = (await (0, sitemap_1.streamToPromise)(sitemapStream)).toString();
|
|
29
30
|
return generatedSitemap;
|
|
30
31
|
}
|
|
31
32
|
exports.default = createSitemap;
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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 {
|
|
8
|
-
import { LoadContext,
|
|
9
|
-
export default function pluginSitemap(
|
|
10
|
-
export
|
|
7
|
+
import type { Options } from '@docusaurus/plugin-sitemap';
|
|
8
|
+
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
9
|
+
export default function pluginSitemap(context: LoadContext, options: Options): Plugin<void>;
|
|
10
|
+
export { validateOptions } from './options';
|
package/lib/index.js
CHANGED
|
@@ -11,27 +11,26 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
13
|
const createSitemap_1 = tslib_1.__importDefault(require("./createSitemap"));
|
|
14
|
-
|
|
15
|
-
function pluginSitemap(_context, options) {
|
|
14
|
+
function pluginSitemap(context, options) {
|
|
16
15
|
return {
|
|
17
16
|
name: 'docusaurus-plugin-sitemap',
|
|
18
17
|
async postBuild({ siteConfig, routesPaths, outDir }) {
|
|
18
|
+
if (siteConfig.noIndex) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
19
21
|
// Generate sitemap.
|
|
20
|
-
const generatedSitemap = await createSitemap_1.default(siteConfig, routesPaths, options);
|
|
22
|
+
const generatedSitemap = await (0, createSitemap_1.default)(siteConfig, routesPaths, options);
|
|
21
23
|
// Write sitemap file.
|
|
22
24
|
const sitemapPath = path_1.default.join(outDir, 'sitemap.xml');
|
|
23
25
|
try {
|
|
24
26
|
await fs_extra_1.default.outputFile(sitemapPath, generatedSitemap);
|
|
25
27
|
}
|
|
26
28
|
catch (err) {
|
|
27
|
-
throw new Error(`
|
|
29
|
+
throw new Error(`Writing sitemap failed: ${err}`);
|
|
28
30
|
}
|
|
29
31
|
},
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
exports.default = pluginSitemap;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return validatedOptions;
|
|
36
|
-
}
|
|
37
|
-
exports.validateOptions = validateOptions;
|
|
35
|
+
var options_1 = require("./options");
|
|
36
|
+
Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
|
package/lib/options.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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 type { Options } from '@docusaurus/plugin-sitemap';
|
|
8
|
+
import type { OptionValidationContext } from '@docusaurus/types';
|
|
9
|
+
export declare const DEFAULT_OPTIONS: Options;
|
|
10
|
+
export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, Options>): Options;
|
|
@@ -6,16 +6,14 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
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
|
-
trailingSlash: false,
|
|
16
15
|
};
|
|
17
|
-
|
|
18
|
-
// TODO temporary (@alpha-71)
|
|
16
|
+
const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
19
17
|
cacheTime: utils_validation_1.Joi.forbidden().messages({
|
|
20
18
|
'any.unknown': 'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
|
|
21
19
|
}),
|
|
@@ -23,5 +21,12 @@ exports.PluginOptionSchema = utils_validation_1.Joi.object({
|
|
|
23
21
|
.valid(...Object.values(sitemap_1.EnumChangefreq))
|
|
24
22
|
.default(exports.DEFAULT_OPTIONS.changefreq),
|
|
25
23
|
priority: utils_validation_1.Joi.number().min(0).max(1).default(exports.DEFAULT_OPTIONS.priority),
|
|
26
|
-
trailingSlash: utils_validation_1.Joi.
|
|
24
|
+
trailingSlash: utils_validation_1.Joi.forbidden().messages({
|
|
25
|
+
'any.unknown': 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
|
|
26
|
+
}),
|
|
27
27
|
});
|
|
28
|
+
function validateOptions({ validate, options, }) {
|
|
29
|
+
const validatedOptions = validate(PluginOptionSchema, options);
|
|
30
|
+
return validatedOptions;
|
|
31
|
+
}
|
|
32
|
+
exports.validateOptions = validateOptions;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-sitemap",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.18",
|
|
4
4
|
"description": "Simple sitemap generation plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
+
"types": "src/plugin-sitemap.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"build": "tsc",
|
|
8
9
|
"watch": "tsc --watch"
|
|
@@ -17,20 +18,23 @@
|
|
|
17
18
|
},
|
|
18
19
|
"license": "MIT",
|
|
19
20
|
"dependencies": {
|
|
20
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
21
|
-
"@docusaurus/
|
|
22
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
23
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
24
|
-
"fs-extra": "^10.0.
|
|
25
|
-
"sitemap": "^7.
|
|
26
|
-
"tslib": "^2.
|
|
21
|
+
"@docusaurus/core": "2.0.0-beta.18",
|
|
22
|
+
"@docusaurus/utils": "2.0.0-beta.18",
|
|
23
|
+
"@docusaurus/utils-common": "2.0.0-beta.18",
|
|
24
|
+
"@docusaurus/utils-validation": "2.0.0-beta.18",
|
|
25
|
+
"fs-extra": "^10.0.1",
|
|
26
|
+
"sitemap": "^7.1.1",
|
|
27
|
+
"tslib": "^2.3.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@docusaurus/types": "2.0.0-beta.18"
|
|
27
31
|
},
|
|
28
32
|
"peerDependencies": {
|
|
29
33
|
"react": "^16.8.4 || ^17.0.0",
|
|
30
34
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
31
35
|
},
|
|
32
36
|
"engines": {
|
|
33
|
-
"node": ">=
|
|
37
|
+
"node": ">=14"
|
|
34
38
|
},
|
|
35
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "1a945d06993d53376e61bed2c942799fe07dc336"
|
|
36
40
|
}
|
package/src/createSitemap.ts
CHANGED
|
@@ -6,30 +6,31 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {SitemapStream, streamToPromise} from 'sitemap';
|
|
9
|
-
import {
|
|
10
|
-
import {DocusaurusConfig} from '@docusaurus/types';
|
|
11
|
-
import {
|
|
9
|
+
import type {Options} from '@docusaurus/plugin-sitemap';
|
|
10
|
+
import type {DocusaurusConfig} from '@docusaurus/types';
|
|
11
|
+
import {applyTrailingSlash} from '@docusaurus/utils-common';
|
|
12
12
|
|
|
13
13
|
export default async function createSitemap(
|
|
14
14
|
siteConfig: DocusaurusConfig,
|
|
15
15
|
routesPaths: string[],
|
|
16
|
-
options:
|
|
16
|
+
options: Options,
|
|
17
17
|
): Promise<string> {
|
|
18
18
|
const {url: hostname} = siteConfig;
|
|
19
19
|
if (!hostname) {
|
|
20
|
-
throw new Error('
|
|
20
|
+
throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
|
|
21
21
|
}
|
|
22
|
-
const {changefreq, priority
|
|
22
|
+
const {changefreq, priority} = options;
|
|
23
23
|
|
|
24
|
-
const sitemapStream = new SitemapStream({
|
|
25
|
-
hostname,
|
|
26
|
-
});
|
|
24
|
+
const sitemapStream = new SitemapStream({hostname});
|
|
27
25
|
|
|
28
26
|
routesPaths
|
|
29
27
|
.filter((route) => !route.endsWith('404.html'))
|
|
30
|
-
.
|
|
28
|
+
.forEach((routePath) =>
|
|
31
29
|
sitemapStream.write({
|
|
32
|
-
url:
|
|
30
|
+
url: applyTrailingSlash(routePath, {
|
|
31
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
32
|
+
baseUrl: siteConfig.baseUrl,
|
|
33
|
+
}),
|
|
33
34
|
changefreq,
|
|
34
35
|
priority,
|
|
35
36
|
}),
|
|
@@ -37,9 +38,7 @@ export default async function createSitemap(
|
|
|
37
38
|
|
|
38
39
|
sitemapStream.end();
|
|
39
40
|
|
|
40
|
-
const generatedSitemap = await streamToPromise(sitemapStream).
|
|
41
|
-
sm.toString(),
|
|
42
|
-
);
|
|
41
|
+
const generatedSitemap = (await streamToPromise(sitemapStream)).toString();
|
|
43
42
|
|
|
44
43
|
return generatedSitemap;
|
|
45
44
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,25 +7,21 @@
|
|
|
7
7
|
|
|
8
8
|
import fs from 'fs-extra';
|
|
9
9
|
import path from 'path';
|
|
10
|
-
import {
|
|
10
|
+
import type {Options} from '@docusaurus/plugin-sitemap';
|
|
11
11
|
import createSitemap from './createSitemap';
|
|
12
|
-
import {
|
|
13
|
-
LoadContext,
|
|
14
|
-
Props,
|
|
15
|
-
OptionValidationContext,
|
|
16
|
-
ValidationResult,
|
|
17
|
-
Plugin,
|
|
18
|
-
} from '@docusaurus/types';
|
|
19
|
-
import {PluginOptionSchema} from './pluginOptionSchema';
|
|
12
|
+
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
20
13
|
|
|
21
14
|
export default function pluginSitemap(
|
|
22
|
-
|
|
23
|
-
options:
|
|
15
|
+
context: LoadContext,
|
|
16
|
+
options: Options,
|
|
24
17
|
): Plugin<void> {
|
|
25
18
|
return {
|
|
26
19
|
name: 'docusaurus-plugin-sitemap',
|
|
27
20
|
|
|
28
|
-
async postBuild({siteConfig, routesPaths, outDir}
|
|
21
|
+
async postBuild({siteConfig, routesPaths, outDir}) {
|
|
22
|
+
if (siteConfig.noIndex) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
29
25
|
// Generate sitemap.
|
|
30
26
|
const generatedSitemap = await createSitemap(
|
|
31
27
|
siteConfig,
|
|
@@ -38,16 +34,10 @@ export default function pluginSitemap(
|
|
|
38
34
|
try {
|
|
39
35
|
await fs.outputFile(sitemapPath, generatedSitemap);
|
|
40
36
|
} catch (err) {
|
|
41
|
-
throw new Error(`
|
|
37
|
+
throw new Error(`Writing sitemap failed: ${err}`);
|
|
42
38
|
}
|
|
43
39
|
},
|
|
44
40
|
};
|
|
45
41
|
}
|
|
46
42
|
|
|
47
|
-
export
|
|
48
|
-
validate,
|
|
49
|
-
options,
|
|
50
|
-
}: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
|
|
51
|
-
const validatedOptions = validate(PluginOptionSchema, options);
|
|
52
|
-
return validatedOptions;
|
|
53
|
-
}
|
|
43
|
+
export {validateOptions} from './options';
|
|
@@ -7,16 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
import {Joi} from '@docusaurus/utils-validation';
|
|
9
9
|
import {EnumChangefreq} from 'sitemap';
|
|
10
|
-
import {
|
|
10
|
+
import type {Options} from '@docusaurus/plugin-sitemap';
|
|
11
|
+
import type {OptionValidationContext} from '@docusaurus/types';
|
|
11
12
|
|
|
12
|
-
export const DEFAULT_OPTIONS:
|
|
13
|
+
export const DEFAULT_OPTIONS: Options = {
|
|
13
14
|
changefreq: EnumChangefreq.WEEKLY,
|
|
14
15
|
priority: 0.5,
|
|
15
|
-
trailingSlash: false,
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
// TODO temporary (@alpha-71)
|
|
18
|
+
const PluginOptionSchema = Joi.object({
|
|
20
19
|
cacheTime: Joi.forbidden().messages({
|
|
21
20
|
'any.unknown':
|
|
22
21
|
'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
|
|
@@ -25,5 +24,16 @@ 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.
|
|
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
|
+
}),
|
|
29
31
|
});
|
|
32
|
+
|
|
33
|
+
export function validateOptions({
|
|
34
|
+
validate,
|
|
35
|
+
options,
|
|
36
|
+
}: OptionValidationContext<Options, Options>): Options {
|
|
37
|
+
const validatedOptions = validate(PluginOptionSchema, options);
|
|
38
|
+
return validatedOptions;
|
|
39
|
+
}
|
|
@@ -5,10 +5,12 @@
|
|
|
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
|
-
export
|
|
10
|
+
export type Options = {
|
|
11
|
+
id?: string;
|
|
12
|
+
/** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
|
|
11
13
|
changefreq?: EnumChangefreq;
|
|
14
|
+
/** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
|
|
12
15
|
priority?: number;
|
|
13
|
-
|
|
14
|
-
}
|
|
16
|
+
};
|