@docusaurus/plugin-sitemap 2.0.0-beta.18 → 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.
- package/lib/createSitemap.d.ts +5 -2
- package/lib/createSitemap.js +13 -5
- package/lib/index.d.ts +3 -2
- package/lib/index.js +2 -2
- package/lib/options.d.ts +15 -3
- package/lib/options.js +4 -0
- package/package.json +10 -10
- package/src/createSitemap.ts +32 -15
- package/src/index.ts +5 -3
- package/src/options.ts +20 -3
- package/src/plugin-sitemap.d.ts +0 -16
package/lib/createSitemap.d.ts
CHANGED
|
@@ -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
|
-
|
|
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>;
|
package/lib/createSitemap.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 '
|
|
7
|
+
import type { PluginOptions, Options } from './options';
|
|
8
8
|
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
9
|
-
export default function pluginSitemap(context: LoadContext, options:
|
|
9
|
+
export default function pluginSitemap(context: LoadContext, options: PluginOptions): Plugin<void>;
|
|
10
10
|
export { validateOptions } from './options';
|
|
11
|
+
export type { PluginOptions, Options };
|
package/lib/index.js
CHANGED
|
@@ -14,12 +14,12 @@ const createSitemap_1 = tslib_1.__importDefault(require("./createSitemap"));
|
|
|
14
14
|
function pluginSitemap(context, options) {
|
|
15
15
|
return {
|
|
16
16
|
name: 'docusaurus-plugin-sitemap',
|
|
17
|
-
async postBuild({ siteConfig, routesPaths, outDir }) {
|
|
17
|
+
async postBuild({ siteConfig, routesPaths, outDir, head }) {
|
|
18
18
|
if (siteConfig.noIndex) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
// Generate sitemap.
|
|
22
|
-
const generatedSitemap = await (0, createSitemap_1.default)(siteConfig, routesPaths, options);
|
|
22
|
+
const generatedSitemap = await (0, createSitemap_1.default)(siteConfig, routesPaths, head, options);
|
|
23
23
|
// Write sitemap file.
|
|
24
24
|
const sitemapPath = path_1.default.join(outDir, 'sitemap.xml');
|
|
25
25
|
try {
|
package/lib/options.d.ts
CHANGED
|
@@ -4,7 +4,19 @@
|
|
|
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
|
|
7
|
+
import { EnumChangefreq } from 'sitemap';
|
|
8
8
|
import type { OptionValidationContext } from '@docusaurus/types';
|
|
9
|
-
export declare
|
|
10
|
-
|
|
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;
|
package/lib/options.js
CHANGED
|
@@ -12,6 +12,7 @@ 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
17
|
const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
17
18
|
cacheTime: utils_validation_1.Joi.forbidden().messages({
|
|
@@ -21,6 +22,9 @@ const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
|
21
22
|
.valid(...Object.values(sitemap_1.EnumChangefreq))
|
|
22
23
|
.default(exports.DEFAULT_OPTIONS.changefreq),
|
|
23
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),
|
|
24
28
|
trailingSlash: utils_validation_1.Joi.forbidden().messages({
|
|
25
29
|
'any.unknown': 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
|
|
26
30
|
}),
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-sitemap",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.19",
|
|
4
4
|
"description": "Simple sitemap generation plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
-
"types": "
|
|
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.
|
|
22
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
23
|
-
"@docusaurus/utils-common": "2.0.0-beta.
|
|
24
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
25
|
-
"fs-extra": "^10.0
|
|
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.
|
|
27
|
+
"tslib": "^2.4.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
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": "
|
|
39
|
+
"gitHead": "a71e60a49cce93c1006ef10c41ac03187f057102"
|
|
40
40
|
}
|
package/src/createSitemap.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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,18 +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';
|
|
11
|
+
import type {PluginOptions, Options} from './options';
|
|
12
12
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
13
13
|
|
|
14
14
|
export default function pluginSitemap(
|
|
15
15
|
context: LoadContext,
|
|
16
|
-
options:
|
|
16
|
+
options: PluginOptions,
|
|
17
17
|
): Plugin<void> {
|
|
18
18
|
return {
|
|
19
19
|
name: 'docusaurus-plugin-sitemap',
|
|
20
20
|
|
|
21
|
-
async postBuild({siteConfig, routesPaths, outDir}) {
|
|
21
|
+
async postBuild({siteConfig, routesPaths, outDir, head}) {
|
|
22
22
|
if (siteConfig.noIndex) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
@@ -26,6 +26,7 @@ export default function pluginSitemap(
|
|
|
26
26
|
const generatedSitemap = await createSitemap(
|
|
27
27
|
siteConfig,
|
|
28
28
|
routesPaths,
|
|
29
|
+
head,
|
|
29
30
|
options,
|
|
30
31
|
);
|
|
31
32
|
|
|
@@ -41,3 +42,4 @@ export default function pluginSitemap(
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
export {validateOptions} from './options';
|
|
45
|
+
export type {PluginOptions, Options};
|
package/src/options.ts
CHANGED
|
@@ -7,12 +7,26 @@
|
|
|
7
7
|
|
|
8
8
|
import {Joi} from '@docusaurus/utils-validation';
|
|
9
9
|
import {EnumChangefreq} from 'sitemap';
|
|
10
|
-
import type {Options} from '@docusaurus/plugin-sitemap';
|
|
11
10
|
import type {OptionValidationContext} from '@docusaurus/types';
|
|
12
11
|
|
|
13
|
-
export
|
|
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 = {
|
|
14
27
|
changefreq: EnumChangefreq.WEEKLY,
|
|
15
28
|
priority: 0.5,
|
|
29
|
+
ignorePatterns: [],
|
|
16
30
|
};
|
|
17
31
|
|
|
18
32
|
const PluginOptionSchema = Joi.object({
|
|
@@ -24,6 +38,9 @@ const PluginOptionSchema = Joi.object({
|
|
|
24
38
|
.valid(...Object.values(EnumChangefreq))
|
|
25
39
|
.default(DEFAULT_OPTIONS.changefreq),
|
|
26
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),
|
|
27
44
|
trailingSlash: Joi.forbidden().messages({
|
|
28
45
|
'any.unknown':
|
|
29
46
|
'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.',
|
|
@@ -33,7 +50,7 @@ const PluginOptionSchema = Joi.object({
|
|
|
33
50
|
export function validateOptions({
|
|
34
51
|
validate,
|
|
35
52
|
options,
|
|
36
|
-
}: OptionValidationContext<Options,
|
|
53
|
+
}: OptionValidationContext<Options, PluginOptions>): PluginOptions {
|
|
37
54
|
const validatedOptions = validate(PluginOptionSchema, options);
|
|
38
55
|
return validatedOptions;
|
|
39
56
|
}
|
package/src/plugin-sitemap.d.ts
DELETED
|
@@ -1,16 +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
|
-
id?: string;
|
|
12
|
-
/** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
|
|
13
|
-
changefreq?: EnumChangefreq;
|
|
14
|
-
/** @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions */
|
|
15
|
-
priority?: number;
|
|
16
|
-
};
|