@docusaurus/plugin-client-redirects 0.0.0-5136 → 0.0.0-5142

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.
@@ -73,17 +73,16 @@ function filterUnwantedRedirects(redirects, pluginContext) {
73
73
  // writing the same html redirection file twice.
74
74
  Object.entries(lodash_1.default.groupBy(redirects, (redirect) => redirect.from)).forEach(([from, groupedFromRedirects]) => {
75
75
  if (groupedFromRedirects.length > 1) {
76
- logger_1.default.error `name=${'@docusaurus/plugin-client-redirects'}: multiple redirects are created with the same "from" pathname: path=${from}
77
- It is not possible to redirect the same pathname to multiple destinations: ${groupedFromRedirects.map((r) => JSON.stringify(r))}`;
76
+ logger_1.default.report(pluginContext.siteConfig.onDuplicateRoutes) `name=${'@docusaurus/plugin-client-redirects'}: multiple redirects are created with the same "from" pathname: path=${from}
77
+ It is not possible to redirect the same pathname to multiple destinations:${groupedFromRedirects.map((r) => JSON.stringify(r))}`;
78
78
  }
79
79
  });
80
80
  const collectedRedirects = lodash_1.default.uniqBy(redirects, (redirect) => redirect.from);
81
- // We don't want to override an already existing route with a redirect file!
82
- const redirectsOverridingExistingPath = collectedRedirects.filter((redirect) => pluginContext.relativeRoutesPaths.includes(redirect.from));
81
+ const { false: newRedirects = [], true: redirectsOverridingExistingPath = [] } = lodash_1.default.groupBy(collectedRedirects, (redirect) => pluginContext.relativeRoutesPaths.includes(redirect.from));
83
82
  if (redirectsOverridingExistingPath.length > 0) {
84
- logger_1.default.error `name=${'@docusaurus/plugin-client-redirects'}: some redirects would override existing paths, and will be ignored: ${redirectsOverridingExistingPath.map((r) => JSON.stringify(r))}`;
83
+ logger_1.default.report(pluginContext.siteConfig.onDuplicateRoutes) `name=${'@docusaurus/plugin-client-redirects'}: some redirects would override existing paths, and will be ignored:${redirectsOverridingExistingPath.map((r) => JSON.stringify(r))}`;
85
84
  }
86
- return collectedRedirects.filter((redirect) => !pluginContext.relativeRoutesPaths.includes(redirect.from));
85
+ return newRedirects;
87
86
  }
88
87
  function createRedirectsOptionRedirects(redirectsOption) {
89
88
  // For convenience, user can use a string or a string[]
package/lib/index.js CHANGED
@@ -21,6 +21,7 @@ function pluginClientRedirectsPages(context, options) {
21
21
  baseUrl: props.baseUrl,
22
22
  outDir: props.outDir,
23
23
  options,
24
+ siteConfig: props.siteConfig,
24
25
  };
25
26
  const redirects = (0, collectRedirects_1.default)(pluginContext, trailingSlash);
26
27
  const redirectFiles = (0, writeRedirectFiles_1.toRedirectFiles)(redirects, pluginContext, trailingSlash);
package/lib/types.d.ts CHANGED
@@ -9,7 +9,7 @@ import type { PluginOptions } from './options';
9
9
  /**
10
10
  * The minimal infos the plugin needs to work
11
11
  */
12
- export declare type PluginContext = Pick<Props, 'outDir' | 'baseUrl'> & {
12
+ export declare type PluginContext = Pick<Props, 'outDir' | 'baseUrl' | 'siteConfig'> & {
13
13
  options: PluginOptions;
14
14
  relativeRoutesPaths: string[];
15
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-client-redirects",
3
- "version": "0.0.0-5136",
3
+ "version": "0.0.0-5142",
4
4
  "description": "Client redirects plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -18,18 +18,18 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "0.0.0-5136",
22
- "@docusaurus/logger": "0.0.0-5136",
23
- "@docusaurus/utils": "0.0.0-5136",
24
- "@docusaurus/utils-common": "0.0.0-5136",
25
- "@docusaurus/utils-validation": "0.0.0-5136",
21
+ "@docusaurus/core": "0.0.0-5142",
22
+ "@docusaurus/logger": "0.0.0-5142",
23
+ "@docusaurus/utils": "0.0.0-5142",
24
+ "@docusaurus/utils-common": "0.0.0-5142",
25
+ "@docusaurus/utils-validation": "0.0.0-5142",
26
26
  "eta": "^1.12.3",
27
27
  "fs-extra": "^10.1.0",
28
28
  "lodash": "^4.17.21",
29
29
  "tslib": "^2.4.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@docusaurus/types": "0.0.0-5136"
32
+ "@docusaurus/types": "0.0.0-5142"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": "^16.8.4 || ^17.0.0",
@@ -38,5 +38,5 @@
38
38
  "engines": {
39
39
  "node": ">=16.14"
40
40
  },
41
- "gitHead": "85095b9c1b8a7a935c7cce10cb78b2146c655f32"
41
+ "gitHead": "e791a64c45af1206bea392117ff42413f85d7bdb"
42
42
  }
@@ -102,8 +102,10 @@ function filterUnwantedRedirects(
102
102
  Object.entries(_.groupBy(redirects, (redirect) => redirect.from)).forEach(
103
103
  ([from, groupedFromRedirects]) => {
104
104
  if (groupedFromRedirects.length > 1) {
105
- logger.error`name=${'@docusaurus/plugin-client-redirects'}: multiple redirects are created with the same "from" pathname: path=${from}
106
- It is not possible to redirect the same pathname to multiple destinations: ${groupedFromRedirects.map(
105
+ logger.report(
106
+ pluginContext.siteConfig.onDuplicateRoutes,
107
+ )`name=${'@docusaurus/plugin-client-redirects'}: multiple redirects are created with the same "from" pathname: path=${from}
108
+ It is not possible to redirect the same pathname to multiple destinations:${groupedFromRedirects.map(
107
109
  (r) => JSON.stringify(r),
108
110
  )}`;
109
111
  }
@@ -111,18 +113,18 @@ It is not possible to redirect the same pathname to multiple destinations: ${gro
111
113
  );
112
114
  const collectedRedirects = _.uniqBy(redirects, (redirect) => redirect.from);
113
115
 
114
- // We don't want to override an already existing route with a redirect file!
115
- const redirectsOverridingExistingPath = collectedRedirects.filter(
116
- (redirect) => pluginContext.relativeRoutesPaths.includes(redirect.from),
117
- );
116
+ const {false: newRedirects = [], true: redirectsOverridingExistingPath = []} =
117
+ _.groupBy(collectedRedirects, (redirect) =>
118
+ pluginContext.relativeRoutesPaths.includes(redirect.from),
119
+ );
118
120
  if (redirectsOverridingExistingPath.length > 0) {
119
- logger.error`name=${'@docusaurus/plugin-client-redirects'}: some redirects would override existing paths, and will be ignored: ${redirectsOverridingExistingPath.map(
121
+ logger.report(
122
+ pluginContext.siteConfig.onDuplicateRoutes,
123
+ )`name=${'@docusaurus/plugin-client-redirects'}: some redirects would override existing paths, and will be ignored:${redirectsOverridingExistingPath.map(
120
124
  (r) => JSON.stringify(r),
121
125
  )}`;
122
126
  }
123
- return collectedRedirects.filter(
124
- (redirect) => !pluginContext.relativeRoutesPaths.includes(redirect.from),
125
- );
127
+ return newRedirects;
126
128
  }
127
129
 
128
130
  function createRedirectsOptionRedirects(
package/src/index.ts CHANGED
@@ -31,6 +31,7 @@ export default function pluginClientRedirectsPages(
31
31
  baseUrl: props.baseUrl,
32
32
  outDir: props.outDir,
33
33
  options,
34
+ siteConfig: props.siteConfig,
34
35
  };
35
36
 
36
37
  const redirects: RedirectItem[] = collectRedirects(
package/src/types.ts CHANGED
@@ -11,7 +11,7 @@ import type {PluginOptions} from './options';
11
11
  /**
12
12
  * The minimal infos the plugin needs to work
13
13
  */
14
- export type PluginContext = Pick<Props, 'outDir' | 'baseUrl'> & {
14
+ export type PluginContext = Pick<Props, 'outDir' | 'baseUrl' | 'siteConfig'> & {
15
15
  options: PluginOptions;
16
16
  relativeRoutesPaths: string[];
17
17
  };