@docusaurus/plugin-sitemap 4.0.0-canary-6935 → 4.0.0-canary-6936
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 +22 -2
- package/lib/options.js +1 -3
- package/package.json +10 -9
- package/src/createSitemapItem.ts +27 -4
- package/src/options.ts +1 -3
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
|
}
|
package/lib/options.js
CHANGED
|
@@ -13,9 +13,7 @@ const types_1 = require("./types");
|
|
|
13
13
|
exports.DEFAULT_OPTIONS = {
|
|
14
14
|
filename: 'sitemap.xml',
|
|
15
15
|
ignorePatterns: [],
|
|
16
|
-
|
|
17
|
-
// change default to "date" if no bug or perf issue reported
|
|
18
|
-
lastmod: null,
|
|
16
|
+
lastmod: 'date',
|
|
19
17
|
// TODO Docusaurus v4 breaking change
|
|
20
18
|
// those options are useless and should be removed
|
|
21
19
|
changefreq: 'weekly',
|
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-6936",
|
|
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-6936",
|
|
18
|
+
"@docusaurus/fs": "4.0.0-canary-6936",
|
|
19
|
+
"@docusaurus/glob": "4.0.0-canary-6936",
|
|
20
|
+
"@docusaurus/logger": "4.0.0-canary-6936",
|
|
21
|
+
"@docusaurus/types": "4.0.0-canary-6936",
|
|
22
|
+
"@docusaurus/utils": "4.0.0-canary-6936",
|
|
23
|
+
"@docusaurus/utils-common": "4.0.0-canary-6936",
|
|
24
|
+
"@docusaurus/utils-validation": "4.0.0-canary-6936",
|
|
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;
|
package/src/options.ts
CHANGED
|
@@ -67,9 +67,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
|
|
|
67
67
|
filename: 'sitemap.xml',
|
|
68
68
|
ignorePatterns: [],
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
// change default to "date" if no bug or perf issue reported
|
|
72
|
-
lastmod: null,
|
|
70
|
+
lastmod: 'date',
|
|
73
71
|
|
|
74
72
|
// TODO Docusaurus v4 breaking change
|
|
75
73
|
// those options are useless and should be removed
|