@docusaurus/plugin-sitemap 0.0.0-4860 → 0.0.0-4865
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 +4 -1
- package/lib/createSitemap.js +10 -4
- package/lib/index.js +2 -2
- package/package.json +7 -7
- package/src/createSitemap.ts +25 -11
- package/src/index.ts +2 -1
package/lib/createSitemap.d.ts
CHANGED
|
@@ -6,4 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { PluginOptions } from '@docusaurus/plugin-sitemap';
|
|
8
8
|
import type { DocusaurusConfig } from '@docusaurus/types';
|
|
9
|
-
|
|
9
|
+
import type { HelmetServerState } from 'react-helmet-async';
|
|
10
|
+
export default function createSitemap(siteConfig: DocusaurusConfig, routesPaths: string[], head: {
|
|
11
|
+
[location: string]: HelmetServerState;
|
|
12
|
+
}, options: PluginOptions): Promise<string>;
|
package/lib/createSitemap.js
CHANGED
|
@@ -9,7 +9,7 @@ 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, options) {
|
|
12
|
+
async function createSitemap(siteConfig, routesPaths, head, options) {
|
|
13
13
|
const { url: hostname } = siteConfig;
|
|
14
14
|
if (!hostname) {
|
|
15
15
|
throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
|
|
@@ -17,9 +17,15 @@ async function createSitemap(siteConfig, routesPaths, options) {
|
|
|
17
17
|
const { changefreq, priority, ignorePatterns } = options;
|
|
18
18
|
const ignoreMatcher = (0, utils_1.createMatcher)(ignorePatterns);
|
|
19
19
|
const sitemapStream = new sitemap_1.SitemapStream({ hostname });
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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({
|
|
23
29
|
url: (0, utils_common_1.applyTrailingSlash)(routePath, {
|
|
24
30
|
trailingSlash: siteConfig.trailingSlash,
|
|
25
31
|
baseUrl: siteConfig.baseUrl,
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-sitemap",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4865",
|
|
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": "0.0.0-
|
|
22
|
-
"@docusaurus/utils": "0.0.0-
|
|
23
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
24
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
21
|
+
"@docusaurus/core": "0.0.0-4865",
|
|
22
|
+
"@docusaurus/utils": "0.0.0-4865",
|
|
23
|
+
"@docusaurus/utils-common": "0.0.0-4865",
|
|
24
|
+
"@docusaurus/utils-validation": "0.0.0-4865",
|
|
25
25
|
"fs-extra": "^10.0.1",
|
|
26
26
|
"sitemap": "^7.1.1",
|
|
27
27
|
"tslib": "^2.3.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@docusaurus/types": "0.0.0-
|
|
30
|
+
"@docusaurus/types": "0.0.0-4865"
|
|
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": "3bfec620587180f9e7dad2bf2a2713172be65fe7"
|
|
40
40
|
}
|
package/src/createSitemap.ts
CHANGED
|
@@ -10,10 +10,13 @@ import type {PluginOptions} from '@docusaurus/plugin-sitemap';
|
|
|
10
10
|
import type {DocusaurusConfig} from '@docusaurus/types';
|
|
11
11
|
import {applyTrailingSlash} from '@docusaurus/utils-common';
|
|
12
12
|
import {createMatcher} from '@docusaurus/utils';
|
|
13
|
+
import type {HelmetServerState} from 'react-helmet-async';
|
|
14
|
+
import type {ReactElement} from 'react';
|
|
13
15
|
|
|
14
16
|
export default async function createSitemap(
|
|
15
17
|
siteConfig: DocusaurusConfig,
|
|
16
18
|
routesPaths: string[],
|
|
19
|
+
head: {[location: string]: HelmetServerState},
|
|
17
20
|
options: PluginOptions,
|
|
18
21
|
): Promise<string> {
|
|
19
22
|
const {url: hostname} = siteConfig;
|
|
@@ -26,18 +29,29 @@ export default async function createSitemap(
|
|
|
26
29
|
|
|
27
30
|
const sitemapStream = new SitemapStream({hostname});
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}),
|
|
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',
|
|
40
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
|
+
);
|
|
41
55
|
|
|
42
56
|
sitemapStream.end();
|
|
43
57
|
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ export default function pluginSitemap(
|
|
|
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
|
|