@docusaurus/plugin-sitemap 4.0.0-canary-6935 → 4.0.0-canary-6937
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/createSitemapItem.js +23 -5
- package/lib/options.d.ts +1 -11
- package/lib/options.js +18 -22
- package/lib/types.d.ts +2 -1
- package/package.json +10 -9
- package/src/createSitemapItem.ts +28 -7
- package/src/options.ts +25 -39
- package/src/types.ts +1 -1
package/lib/createSitemapItem.js
CHANGED
|
@@ -7,8 +7,29 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createSitemapItem = createSitemapItem;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
10
13
|
const utils_common_1 = require("@docusaurus/utils-common");
|
|
11
14
|
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
// Warn only once: the VCS read error is usually the same for all files
|
|
16
|
+
const warnVcsReadErrorOnce = lodash_1.default.once((sourceFilePath, error) => {
|
|
17
|
+
logger_1.default.warn `Sitemap: unable to read the last update date of file path=${sourceFilePath} (and possibly other files), their code=${'<lastmod>'} tag will be omitted. Use the sitemap option code=${'lastmod: null'} to disable code=${'<lastmod>'} tags.
|
|
18
|
+
Cause: ${error.message}`;
|
|
19
|
+
});
|
|
20
|
+
// The sitemap <lastmod> tag is optional SEO metadata, enabled by default
|
|
21
|
+
// We don't want to fail the build when the VCS can't be read
|
|
22
|
+
// This happens notably for sites outside a Git repository
|
|
23
|
+
async function readVcsLastUpdatedAt(sourceFilePath, vcs) {
|
|
24
|
+
try {
|
|
25
|
+
const lastUpdateInfo = await vcs.getFileLastUpdateInfo(sourceFilePath);
|
|
26
|
+
return lastUpdateInfo?.timestamp ?? null;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
warnVcsReadErrorOnce(sourceFilePath, error);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
12
33
|
async function getRouteLastUpdatedAt(route, vcs) {
|
|
13
34
|
// Important to bail-out early here
|
|
14
35
|
// This can lead to duplicated VCS calls and performance problems
|
|
@@ -20,8 +41,7 @@ async function getRouteLastUpdatedAt(route, vcs) {
|
|
|
20
41
|
return route.metadata?.lastUpdatedAt;
|
|
21
42
|
}
|
|
22
43
|
if (route.metadata?.sourceFilePath) {
|
|
23
|
-
|
|
24
|
-
return lastUpdateInfo?.timestamp ?? null;
|
|
44
|
+
return readVcsLastUpdatedAt(route.metadata.sourceFilePath, vcs);
|
|
25
45
|
}
|
|
26
46
|
return undefined;
|
|
27
47
|
}
|
|
@@ -41,7 +61,7 @@ async function getRouteLastmod({ route, lastmod, vcs, }) {
|
|
|
41
61
|
return lastUpdatedAt != null ? formatLastmod(lastUpdatedAt, lastmod) : null;
|
|
42
62
|
}
|
|
43
63
|
async function createSitemapItem({ route, siteConfig, options, }) {
|
|
44
|
-
const {
|
|
64
|
+
const { lastmod } = options;
|
|
45
65
|
return {
|
|
46
66
|
url: (0, utils_1.normalizeUrl)([
|
|
47
67
|
siteConfig.url,
|
|
@@ -50,8 +70,6 @@ async function createSitemapItem({ route, siteConfig, options, }) {
|
|
|
50
70
|
baseUrl: siteConfig.baseUrl,
|
|
51
71
|
}),
|
|
52
72
|
]),
|
|
53
|
-
changefreq,
|
|
54
|
-
priority,
|
|
55
73
|
lastmod: await getRouteLastmod({
|
|
56
74
|
route,
|
|
57
75
|
lastmod,
|
package/lib/options.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { OptionValidationContext } from '@docusaurus/types';
|
|
8
|
-
import type {
|
|
8
|
+
import type { LastModOption, SitemapItem, CreateSitemapItemsFn, CreateSitemapItemsParams } from './types';
|
|
9
9
|
export type PluginOptions = {
|
|
10
10
|
/**
|
|
11
11
|
* The path to the created sitemap file, relative to the output directory.
|
|
@@ -26,16 +26,6 @@ export type PluginOptions = {
|
|
|
26
26
|
* @see https://www.w3.org/TR/NOTE-datetime
|
|
27
27
|
*/
|
|
28
28
|
lastmod: LastModOption | null;
|
|
29
|
-
/**
|
|
30
|
-
* TODO Docusaurus v4 breaking change: remove useless option
|
|
31
|
-
* @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions
|
|
32
|
-
*/
|
|
33
|
-
changefreq: ChangeFreq | null;
|
|
34
|
-
/**
|
|
35
|
-
* TODO Docusaurus v4 breaking change: remove useless option
|
|
36
|
-
* @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions
|
|
37
|
-
*/
|
|
38
|
-
priority: number | null;
|
|
39
29
|
/** Allow control over the construction of SitemapItems */
|
|
40
30
|
createSitemapItems?: CreateSitemapItemsOption;
|
|
41
31
|
};
|
package/lib/options.js
CHANGED
|
@@ -8,39 +8,35 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.DEFAULT_OPTIONS = void 0;
|
|
10
10
|
exports.validateOptions = validateOptions;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
11
13
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
14
|
const types_1 = require("./types");
|
|
13
15
|
exports.DEFAULT_OPTIONS = {
|
|
14
16
|
filename: 'sitemap.xml',
|
|
15
17
|
ignorePatterns: [],
|
|
16
|
-
|
|
17
|
-
// change default to "date" if no bug or perf issue reported
|
|
18
|
-
lastmod: null,
|
|
19
|
-
// TODO Docusaurus v4 breaking change
|
|
20
|
-
// those options are useless and should be removed
|
|
21
|
-
changefreq: 'weekly',
|
|
22
|
-
priority: 0.5,
|
|
18
|
+
lastmod: 'date',
|
|
23
19
|
};
|
|
20
|
+
// TODO Docusaurus v5: remove these migration errors
|
|
21
|
+
// Removed in Docusaurus v4: Google ignores <changefreq> and <priority>,
|
|
22
|
+
// and the same value for all routes does not make sense anyway
|
|
23
|
+
// Users can still emit them per-route with createSitemapItems()
|
|
24
|
+
// See also https://github.com/facebook/docusaurus/issues/2604
|
|
25
|
+
function removedOptionSchema(option) {
|
|
26
|
+
return utils_validation_1.Joi.any()
|
|
27
|
+
.forbidden()
|
|
28
|
+
.messages({
|
|
29
|
+
'any.unknown': `The sitemap plugin ${logger_1.default.code(option)} option has been removed in Docusaurus v4. Please remove it from your config.
|
|
30
|
+
If you still want to emit this sitemap tag, use the ${logger_1.default.code('createSitemapItems')} option instead: ${logger_1.default.url('https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-sitemap#changefreq-priority')}`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
24
33
|
const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
25
34
|
// @ts-expect-error: forbidden
|
|
26
35
|
cacheTime: utils_validation_1.Joi.forbidden().messages({
|
|
27
36
|
'any.unknown': 'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
|
|
28
37
|
}),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// See also https://github.com/facebook/docusaurus/issues/2604
|
|
32
|
-
changefreq: utils_validation_1.Joi.string()
|
|
33
|
-
.valid(null, ...types_1.ChangeFreqList)
|
|
34
|
-
.default(exports.DEFAULT_OPTIONS.changefreq),
|
|
35
|
-
// TODO remove for Docusaurus v4 breaking changes?
|
|
36
|
-
// This is not even used by Google crawlers
|
|
37
|
-
// The priority is "relative", and using the same priority for all routes
|
|
38
|
-
// does not make sense according to the spec
|
|
39
|
-
// See also https://github.com/facebook/docusaurus/issues/2604
|
|
40
|
-
// See also https://www.sitemaps.org/protocol.html
|
|
41
|
-
priority: utils_validation_1.Joi.alternatives()
|
|
42
|
-
.try(utils_validation_1.Joi.valid(null), utils_validation_1.Joi.number().min(0).max(1))
|
|
43
|
-
.default(exports.DEFAULT_OPTIONS.priority),
|
|
38
|
+
changefreq: removedOptionSchema('changefreq'),
|
|
39
|
+
priority: removedOptionSchema('priority'),
|
|
44
40
|
lastmod: utils_validation_1.Joi.string()
|
|
45
41
|
.valid(null, ...types_1.LastModOptionList)
|
|
46
42
|
.default(exports.DEFAULT_OPTIONS.lastmod),
|
package/lib/types.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { DocusaurusConfig, RouteConfig } from '@docusaurus/types';
|
|
|
8
8
|
export declare const LastModOptionList: readonly ['date', 'datetime'];
|
|
9
9
|
export type LastModOption = (typeof LastModOptionList)[number];
|
|
10
10
|
export declare const ChangeFreqList: readonly ['hourly', 'daily', 'weekly', 'monthly', 'yearly', 'always', 'never'];
|
|
11
|
-
|
|
11
|
+
type ChangeFreq = (typeof ChangeFreqList)[number];
|
|
12
12
|
export type SitemapItem = {
|
|
13
13
|
/**
|
|
14
14
|
* URL of the page.
|
|
@@ -51,3 +51,4 @@ export type CreateSitemapItemsParams = {
|
|
|
51
51
|
routes: RouteConfig[];
|
|
52
52
|
};
|
|
53
53
|
export type CreateSitemapItemsFn = (params: CreateSitemapItemsParams) => Promise<SitemapItem[]>;
|
|
54
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-sitemap",
|
|
3
|
-
"version": "4.0.0-canary-
|
|
3
|
+
"version": "4.0.0-canary-6937",
|
|
4
4
|
"description": "Simple sitemap generation plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -14,14 +14,15 @@
|
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@docusaurus/core": "4.0.0-canary-
|
|
18
|
-
"@docusaurus/fs": "4.0.0-canary-
|
|
19
|
-
"@docusaurus/glob": "4.0.0-canary-
|
|
20
|
-
"@docusaurus/logger": "4.0.0-canary-
|
|
21
|
-
"@docusaurus/types": "4.0.0-canary-
|
|
22
|
-
"@docusaurus/utils": "4.0.0-canary-
|
|
23
|
-
"@docusaurus/utils-common": "4.0.0-canary-
|
|
24
|
-
"@docusaurus/utils-validation": "4.0.0-canary-
|
|
17
|
+
"@docusaurus/core": "4.0.0-canary-6937",
|
|
18
|
+
"@docusaurus/fs": "4.0.0-canary-6937",
|
|
19
|
+
"@docusaurus/glob": "4.0.0-canary-6937",
|
|
20
|
+
"@docusaurus/logger": "4.0.0-canary-6937",
|
|
21
|
+
"@docusaurus/types": "4.0.0-canary-6937",
|
|
22
|
+
"@docusaurus/utils": "4.0.0-canary-6937",
|
|
23
|
+
"@docusaurus/utils-common": "4.0.0-canary-6937",
|
|
24
|
+
"@docusaurus/utils-validation": "4.0.0-canary-6937",
|
|
25
|
+
"lodash": "^4.18.1",
|
|
25
26
|
"sitemap": "^9.0.1",
|
|
26
27
|
"tslib": "^2.8.1"
|
|
27
28
|
},
|
package/src/createSitemapItem.ts
CHANGED
|
@@ -5,12 +5,38 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import _ from 'lodash';
|
|
9
|
+
import logger from '@docusaurus/logger';
|
|
8
10
|
import {applyTrailingSlash} from '@docusaurus/utils-common';
|
|
9
11
|
import {normalizeUrl} from '@docusaurus/utils';
|
|
10
12
|
import type {LastModOption, SitemapItem} from './types';
|
|
11
13
|
import type {DocusaurusConfig, RouteConfig, VcsConfig} from '@docusaurus/types';
|
|
12
14
|
import type {PluginOptions} from './options';
|
|
13
15
|
|
|
16
|
+
// Warn only once: the VCS read error is usually the same for all files
|
|
17
|
+
const warnVcsReadErrorOnce = _.once(
|
|
18
|
+
(sourceFilePath: string, error: unknown) => {
|
|
19
|
+
logger.warn`Sitemap: unable to read the last update date of file path=${sourceFilePath} (and possibly other files), their code=${'<lastmod>'} tag will be omitted. Use the sitemap option code=${'lastmod: null'} to disable code=${'<lastmod>'} tags.
|
|
20
|
+
Cause: ${(error as Error).message}`;
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// The sitemap <lastmod> tag is optional SEO metadata, enabled by default
|
|
25
|
+
// We don't want to fail the build when the VCS can't be read
|
|
26
|
+
// This happens notably for sites outside a Git repository
|
|
27
|
+
async function readVcsLastUpdatedAt(
|
|
28
|
+
sourceFilePath: string,
|
|
29
|
+
vcs: Pick<VcsConfig, 'getFileLastUpdateInfo'>,
|
|
30
|
+
): Promise<number | null> {
|
|
31
|
+
try {
|
|
32
|
+
const lastUpdateInfo = await vcs.getFileLastUpdateInfo(sourceFilePath);
|
|
33
|
+
return lastUpdateInfo?.timestamp ?? null;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
warnVcsReadErrorOnce(sourceFilePath, error);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
14
40
|
async function getRouteLastUpdatedAt(
|
|
15
41
|
route: RouteConfig,
|
|
16
42
|
vcs: Pick<VcsConfig, 'getFileLastUpdateInfo'>,
|
|
@@ -25,10 +51,7 @@ async function getRouteLastUpdatedAt(
|
|
|
25
51
|
return route.metadata?.lastUpdatedAt;
|
|
26
52
|
}
|
|
27
53
|
if (route.metadata?.sourceFilePath) {
|
|
28
|
-
|
|
29
|
-
route.metadata?.sourceFilePath,
|
|
30
|
-
);
|
|
31
|
-
return lastUpdateInfo?.timestamp ?? null;
|
|
54
|
+
return readVcsLastUpdatedAt(route.metadata.sourceFilePath, vcs);
|
|
32
55
|
}
|
|
33
56
|
|
|
34
57
|
return undefined;
|
|
@@ -71,7 +94,7 @@ export async function createSitemapItem({
|
|
|
71
94
|
siteConfig: DocusaurusConfig;
|
|
72
95
|
options: PluginOptions;
|
|
73
96
|
}): Promise<SitemapItem> {
|
|
74
|
-
const {
|
|
97
|
+
const {lastmod} = options;
|
|
75
98
|
return {
|
|
76
99
|
url: normalizeUrl([
|
|
77
100
|
siteConfig.url,
|
|
@@ -80,8 +103,6 @@ export async function createSitemapItem({
|
|
|
80
103
|
baseUrl: siteConfig.baseUrl,
|
|
81
104
|
}),
|
|
82
105
|
]),
|
|
83
|
-
changefreq,
|
|
84
|
-
priority,
|
|
85
106
|
lastmod: await getRouteLastmod({
|
|
86
107
|
route,
|
|
87
108
|
lastmod,
|
package/src/options.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import logger from '@docusaurus/logger';
|
|
8
9
|
import {Joi} from '@docusaurus/utils-validation';
|
|
9
|
-
import {
|
|
10
|
+
import {LastModOptionList} from './types';
|
|
10
11
|
import type {OptionValidationContext} from '@docusaurus/types';
|
|
11
12
|
import type {
|
|
12
|
-
ChangeFreq,
|
|
13
13
|
LastModOption,
|
|
14
14
|
SitemapItem,
|
|
15
15
|
CreateSitemapItemsFn,
|
|
@@ -39,18 +39,6 @@ export type PluginOptions = {
|
|
|
39
39
|
*/
|
|
40
40
|
lastmod: LastModOption | null;
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* TODO Docusaurus v4 breaking change: remove useless option
|
|
44
|
-
* @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions
|
|
45
|
-
*/
|
|
46
|
-
changefreq: ChangeFreq | null;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* TODO Docusaurus v4 breaking change: remove useless option
|
|
50
|
-
* @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions
|
|
51
|
-
*/
|
|
52
|
-
priority: number | null;
|
|
53
|
-
|
|
54
42
|
/** Allow control over the construction of SitemapItems */
|
|
55
43
|
createSitemapItems?: CreateSitemapItemsOption;
|
|
56
44
|
};
|
|
@@ -66,17 +54,29 @@ export type Options = Partial<PluginOptions>;
|
|
|
66
54
|
export const DEFAULT_OPTIONS: PluginOptions = {
|
|
67
55
|
filename: 'sitemap.xml',
|
|
68
56
|
ignorePatterns: [],
|
|
69
|
-
|
|
70
|
-
// TODO Docusaurus v4 breaking change
|
|
71
|
-
// change default to "date" if no bug or perf issue reported
|
|
72
|
-
lastmod: null,
|
|
73
|
-
|
|
74
|
-
// TODO Docusaurus v4 breaking change
|
|
75
|
-
// those options are useless and should be removed
|
|
76
|
-
changefreq: 'weekly',
|
|
77
|
-
priority: 0.5,
|
|
57
|
+
lastmod: 'date',
|
|
78
58
|
};
|
|
79
59
|
|
|
60
|
+
// TODO Docusaurus v5: remove these migration errors
|
|
61
|
+
// Removed in Docusaurus v4: Google ignores <changefreq> and <priority>,
|
|
62
|
+
// and the same value for all routes does not make sense anyway
|
|
63
|
+
// Users can still emit them per-route with createSitemapItems()
|
|
64
|
+
// See also https://github.com/facebook/docusaurus/issues/2604
|
|
65
|
+
function removedOptionSchema(option: 'changefreq' | 'priority') {
|
|
66
|
+
return Joi.any()
|
|
67
|
+
.forbidden()
|
|
68
|
+
.messages({
|
|
69
|
+
'any.unknown': `The sitemap plugin ${logger.code(
|
|
70
|
+
option,
|
|
71
|
+
)} option has been removed in Docusaurus v4. Please remove it from your config.
|
|
72
|
+
If you still want to emit this sitemap tag, use the ${logger.code(
|
|
73
|
+
'createSitemapItems',
|
|
74
|
+
)} option instead: ${logger.url(
|
|
75
|
+
'https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-sitemap#changefreq-priority',
|
|
76
|
+
)}`,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
80
|
const PluginOptionSchema = Joi.object<PluginOptions>({
|
|
81
81
|
// @ts-expect-error: forbidden
|
|
82
82
|
cacheTime: Joi.forbidden().messages({
|
|
@@ -84,22 +84,8 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
|
|
|
84
84
|
'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
|
|
85
85
|
}),
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// See also https://github.com/facebook/docusaurus/issues/2604
|
|
90
|
-
changefreq: Joi.string()
|
|
91
|
-
.valid(null, ...ChangeFreqList)
|
|
92
|
-
.default(DEFAULT_OPTIONS.changefreq),
|
|
93
|
-
|
|
94
|
-
// TODO remove for Docusaurus v4 breaking changes?
|
|
95
|
-
// This is not even used by Google crawlers
|
|
96
|
-
// The priority is "relative", and using the same priority for all routes
|
|
97
|
-
// does not make sense according to the spec
|
|
98
|
-
// See also https://github.com/facebook/docusaurus/issues/2604
|
|
99
|
-
// See also https://www.sitemaps.org/protocol.html
|
|
100
|
-
priority: Joi.alternatives()
|
|
101
|
-
.try(Joi.valid(null), Joi.number().min(0).max(1))
|
|
102
|
-
.default(DEFAULT_OPTIONS.priority),
|
|
87
|
+
changefreq: removedOptionSchema('changefreq'),
|
|
88
|
+
priority: removedOptionSchema('priority'),
|
|
103
89
|
|
|
104
90
|
lastmod: Joi.string()
|
|
105
91
|
.valid(null, ...LastModOptionList)
|
package/src/types.ts
CHANGED
|
@@ -24,7 +24,7 @@ export const ChangeFreqList = [
|
|
|
24
24
|
'never',
|
|
25
25
|
] as const;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
type ChangeFreq = (typeof ChangeFreqList)[number];
|
|
28
28
|
|
|
29
29
|
// We re-recreate our own type because the "sitemap" lib types are not good
|
|
30
30
|
export type SitemapItem = {
|