@docusaurus/plugin-sitemap 0.0.0-5198 → 0.0.0-5202

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.
@@ -9,4 +9,4 @@ import type { HelmetServerState } from 'react-helmet-async';
9
9
  import type { PluginOptions } from './options';
10
10
  export default function createSitemap(siteConfig: DocusaurusConfig, routesPaths: string[], head: {
11
11
  [location: string]: HelmetServerState;
12
- }, options: PluginOptions): Promise<string>;
12
+ }, options: PluginOptions): Promise<string | null>;
@@ -16,16 +16,19 @@ async function createSitemap(siteConfig, routesPaths, head, options) {
16
16
  }
17
17
  const { changefreq, priority, ignorePatterns } = options;
18
18
  const ignoreMatcher = (0, utils_1.createMatcher)(ignorePatterns);
19
- const sitemapStream = new sitemap_1.SitemapStream({ hostname });
20
- function routeShouldBeIncluded(route) {
19
+ const includedRoutes = routesPaths.filter((route) => {
21
20
  if (route.endsWith('404.html') || ignoreMatcher(route)) {
22
21
  return false;
23
22
  }
24
23
  // https://github.com/staylor/react-helmet-async/pull/167
25
24
  const meta = head[route]?.meta.toComponent();
26
25
  return !meta?.some((tag) => tag.props.name === 'robots' && tag.props.content === 'noindex');
26
+ });
27
+ if (includedRoutes.length === 0) {
28
+ return null;
27
29
  }
28
- routesPaths.filter(routeShouldBeIncluded).forEach((routePath) => sitemapStream.write({
30
+ const sitemapStream = new sitemap_1.SitemapStream({ hostname });
31
+ includedRoutes.forEach((routePath) => sitemapStream.write({
29
32
  url: (0, utils_common_1.applyTrailingSlash)(routePath, {
30
33
  trailingSlash: siteConfig.trailingSlash,
31
34
  baseUrl: siteConfig.baseUrl,
package/lib/index.js CHANGED
@@ -21,6 +21,9 @@ function pluginSitemap(context, options) {
21
21
  }
22
22
  // Generate sitemap.
23
23
  const generatedSitemap = await (0, createSitemap_1.default)(siteConfig, routesPaths, head, options);
24
+ if (!generatedSitemap) {
25
+ return;
26
+ }
24
27
  // Write sitemap file.
25
28
  const sitemapPath = path_1.default.join(outDir, options.filename);
26
29
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-sitemap",
3
- "version": "0.0.0-5198",
3
+ "version": "0.0.0-5202",
4
4
  "description": "Simple sitemap generation plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -18,12 +18,12 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "0.0.0-5198",
22
- "@docusaurus/logger": "0.0.0-5198",
23
- "@docusaurus/types": "0.0.0-5198",
24
- "@docusaurus/utils": "0.0.0-5198",
25
- "@docusaurus/utils-common": "0.0.0-5198",
26
- "@docusaurus/utils-validation": "0.0.0-5198",
21
+ "@docusaurus/core": "0.0.0-5202",
22
+ "@docusaurus/logger": "0.0.0-5202",
23
+ "@docusaurus/types": "0.0.0-5202",
24
+ "@docusaurus/utils": "0.0.0-5202",
25
+ "@docusaurus/utils-common": "0.0.0-5202",
26
+ "@docusaurus/utils-validation": "0.0.0-5202",
27
27
  "fs-extra": "^10.1.0",
28
28
  "sitemap": "^7.1.1",
29
29
  "tslib": "^2.4.0"
@@ -38,5 +38,5 @@
38
38
  "engines": {
39
39
  "node": ">=16.14"
40
40
  },
41
- "gitHead": "fa05cb6f54018d631ea8fa546d7c9bb80716adb3"
41
+ "gitHead": "8fdf5bb62596a5c639458ef9adb13698ee632f43"
42
42
  }
@@ -18,7 +18,7 @@ export default async function createSitemap(
18
18
  routesPaths: string[],
19
19
  head: {[location: string]: HelmetServerState},
20
20
  options: PluginOptions,
21
- ): Promise<string> {
21
+ ): Promise<string | null> {
22
22
  const {url: hostname} = siteConfig;
23
23
  if (!hostname) {
24
24
  throw new Error('URL in docusaurus.config.js cannot be empty/undefined.');
@@ -27,9 +27,7 @@ export default async function createSitemap(
27
27
 
28
28
  const ignoreMatcher = createMatcher(ignorePatterns);
29
29
 
30
- const sitemapStream = new SitemapStream({hostname});
31
-
32
- function routeShouldBeIncluded(route: string) {
30
+ const includedRoutes = routesPaths.filter((route) => {
33
31
  if (route.endsWith('404.html') || ignoreMatcher(route)) {
34
32
  return false;
35
33
  }
@@ -40,9 +38,15 @@ export default async function createSitemap(
40
38
  return !meta?.some(
41
39
  (tag) => tag.props.name === 'robots' && tag.props.content === 'noindex',
42
40
  );
41
+ });
42
+
43
+ if (includedRoutes.length === 0) {
44
+ return null;
43
45
  }
44
46
 
45
- routesPaths.filter(routeShouldBeIncluded).forEach((routePath) =>
47
+ const sitemapStream = new SitemapStream({hostname});
48
+
49
+ includedRoutes.forEach((routePath) =>
46
50
  sitemapStream.write({
47
51
  url: applyTrailingSlash(routePath, {
48
52
  trailingSlash: siteConfig.trailingSlash,
package/src/index.ts CHANGED
@@ -30,6 +30,9 @@ export default function pluginSitemap(
30
30
  head,
31
31
  options,
32
32
  );
33
+ if (!generatedSitemap) {
34
+ return;
35
+ }
33
36
 
34
37
  // Write sitemap file.
35
38
  const sitemapPath = path.join(outDir, options.filename);