@docusaurus/plugin-client-redirects 3.10.1 → 4.0.0-canary-6808

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.
@@ -14,6 +14,14 @@ const utils_common_1 = require("@docusaurus/utils-common");
14
14
  const extensionRedirects_1 = require("./extensionRedirects");
15
15
  const redirectValidation_1 = require("./redirectValidation");
16
16
  function collectRedirects(pluginContext, trailingSlash) {
17
+ function normalizeRedirectTo(to) {
18
+ return to.startsWith('/')
19
+ ? (0, utils_common_1.applyTrailingSlash)(to, {
20
+ trailingSlash,
21
+ baseUrl: pluginContext.baseUrl,
22
+ })
23
+ : to;
24
+ }
17
25
  // For each plugin config option, create the appropriate redirects
18
26
  const redirects = [
19
27
  ...(0, extensionRedirects_1.createFromExtensionsRedirects)(pluginContext.relativeRoutesPaths, pluginContext.options.fromExtensions),
@@ -31,10 +39,7 @@ function collectRedirects(pluginContext, trailingSlash) {
31
39
  //
32
40
  // It should be easy to toggle `trailingSlash` option without having to
33
41
  // change other configs
34
- to: (0, utils_common_1.applyTrailingSlash)(redirect.to, {
35
- trailingSlash,
36
- baseUrl: pluginContext.baseUrl,
37
- }),
42
+ to: normalizeRedirectTo(redirect.to),
38
43
  }));
39
44
  validateCollectedRedirects(redirects, pluginContext);
40
45
  return filterUnwantedRedirects(redirects, pluginContext);
@@ -65,10 +70,10 @@ function validateCollectedRedirects(redirects, pluginContext) {
65
70
  // See https://github.com/facebook/docusaurus/issues/6845
66
71
  .map((to) => {
67
72
  if (to.startsWith('/')) {
68
- try {
69
- return decodeURI(new URL(to, 'https://example.com').pathname);
73
+ const url = URL.parse(to, 'https://example.com');
74
+ if (url) {
75
+ return decodeURI(url.pathname);
70
76
  }
71
- catch (e) { }
72
77
  }
73
78
  return undefined;
74
79
  })
@@ -9,24 +9,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.default = createRedirectPageContent;
10
10
  const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
- const eta = tslib_1.__importStar(require("eta"));
12
+ const eta_1 = require("eta");
13
13
  const redirectPage_template_html_1 = tslib_1.__importDefault(require("./templates/redirectPage.template.html"));
14
+ const eta = new eta_1.Eta();
14
15
  const getCompiledRedirectPageTemplate = lodash_1.default.memoize(() => eta.compile(redirectPage_template_html_1.default.trim()));
15
16
  function renderRedirectPageTemplate(data) {
16
17
  const compiled = getCompiledRedirectPageTemplate();
17
- return compiled(data, eta.defaultConfig);
18
+ return eta.render(compiled, data);
18
19
  }
19
20
  // if the target url does not include ?search#anchor,
20
21
  // we forward search/anchor that the redirect page receives
21
22
  function searchAnchorForwarding(toUrl) {
22
- try {
23
- const url = new URL(toUrl, 'https://example.com');
24
- const containsSearchOrAnchor = url.search || url.hash;
25
- return !containsSearchOrAnchor;
26
- }
27
- catch (e) {
23
+ const url = URL.parse(toUrl, 'https://example.com');
24
+ if (url === null) {
28
25
  return false;
29
26
  }
27
+ const containsSearchOrAnchor = url.search || url.hash;
28
+ return !containsSearchOrAnchor;
30
29
  }
31
30
  function createRedirectPageContent({ toUrl, }) {
32
31
  return renderRedirectPageTemplate({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-client-redirects",
3
- "version": "3.10.1",
3
+ "version": "4.0.0-canary-6808",
4
4
  "description": "Client redirects plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -18,25 +18,25 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "3.10.1",
22
- "@docusaurus/logger": "3.10.1",
23
- "@docusaurus/utils": "3.10.1",
24
- "@docusaurus/utils-common": "3.10.1",
25
- "@docusaurus/utils-validation": "3.10.1",
26
- "eta": "^2.2.0",
27
- "fs-extra": "^11.1.1",
28
- "lodash": "^4.17.21",
29
- "tslib": "^2.6.0"
21
+ "@docusaurus/core": "4.0.0-canary-6808",
22
+ "@docusaurus/logger": "4.0.0-canary-6808",
23
+ "@docusaurus/utils": "4.0.0-canary-6808",
24
+ "@docusaurus/utils-common": "4.0.0-canary-6808",
25
+ "@docusaurus/utils-validation": "4.0.0-canary-6808",
26
+ "eta": "^4.6.0",
27
+ "fs-extra": "^11.4.0",
28
+ "lodash": "^4.18.1",
29
+ "tslib": "^2.8.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@docusaurus/types": "3.10.1"
32
+ "@docusaurus/types": "4.0.0-canary-6808"
33
33
  },
34
34
  "peerDependencies": {
35
- "react": "^18.0.0 || ^19.0.0",
36
- "react-dom": "^18.0.0 || ^19.0.0"
35
+ "react": "^19.3.0",
36
+ "react-dom": "^19.3.0"
37
37
  },
38
38
  "engines": {
39
- "node": ">=20.0"
39
+ "node": ">=24.14"
40
40
  },
41
- "gitHead": "41c1a458ecb07d61b6df2761ea4bc1b13db49d12"
41
+ "gitHead": "91e445730a91fbe20dd5fefae560303a0c655aa7"
42
42
  }
@@ -24,6 +24,15 @@ export default function collectRedirects(
24
24
  pluginContext: PluginContext,
25
25
  trailingSlash: boolean | undefined,
26
26
  ): RedirectItem[] {
27
+ function normalizeRedirectTo(to: string) {
28
+ return to.startsWith('/')
29
+ ? applyTrailingSlash(to, {
30
+ trailingSlash,
31
+ baseUrl: pluginContext.baseUrl,
32
+ })
33
+ : to;
34
+ }
35
+
27
36
  // For each plugin config option, create the appropriate redirects
28
37
  const redirects = [
29
38
  ...createFromExtensionsRedirects(
@@ -50,10 +59,7 @@ export default function collectRedirects(
50
59
  //
51
60
  // It should be easy to toggle `trailingSlash` option without having to
52
61
  // change other configs
53
- to: applyTrailingSlash(redirect.to, {
54
- trailingSlash,
55
- baseUrl: pluginContext.baseUrl,
56
- }),
62
+ to: normalizeRedirectTo(redirect.to),
57
63
  }));
58
64
 
59
65
  validateCollectedRedirects(redirects, pluginContext);
@@ -93,9 +99,10 @@ function validateCollectedRedirects(
93
99
  // See https://github.com/facebook/docusaurus/issues/6845
94
100
  .map((to) => {
95
101
  if (to.startsWith('/')) {
96
- try {
97
- return decodeURI(new URL(to, 'https://example.com').pathname);
98
- } catch (e) {}
102
+ const url = URL.parse(to, 'https://example.com');
103
+ if (url) {
104
+ return decodeURI(url.pathname);
105
+ }
99
106
  }
100
107
  return undefined;
101
108
  })
@@ -6,9 +6,11 @@
6
6
  */
7
7
 
8
8
  import _ from 'lodash';
9
- import * as eta from 'eta';
9
+ import {Eta} from 'eta';
10
10
  import redirectPageTemplate from './templates/redirectPage.template.html';
11
11
 
12
+ const eta = new Eta();
13
+
12
14
  const getCompiledRedirectPageTemplate = _.memoize(() =>
13
15
  eta.compile(redirectPageTemplate.trim()),
14
16
  );
@@ -18,19 +20,18 @@ function renderRedirectPageTemplate(data: {
18
20
  searchAnchorForwarding: boolean;
19
21
  }) {
20
22
  const compiled = getCompiledRedirectPageTemplate();
21
- return compiled(data, eta.defaultConfig);
23
+ return eta.render(compiled, data);
22
24
  }
23
25
 
24
26
  // if the target url does not include ?search#anchor,
25
27
  // we forward search/anchor that the redirect page receives
26
28
  function searchAnchorForwarding(toUrl: string): boolean {
27
- try {
28
- const url = new URL(toUrl, 'https://example.com');
29
- const containsSearchOrAnchor = url.search || url.hash;
30
- return !containsSearchOrAnchor;
31
- } catch (e) {
29
+ const url = URL.parse(toUrl, 'https://example.com');
30
+ if (url === null) {
32
31
  return false;
33
32
  }
33
+ const containsSearchOrAnchor = url.search || url.hash;
34
+ return !containsSearchOrAnchor;
34
35
  }
35
36
 
36
37
  export default function createRedirectPageContent({
package/src/deps.d.ts CHANGED
@@ -4,13 +4,3 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
-
8
- // TODO incompatible declaration file
9
- declare module 'eta' {
10
- export const defaultConfig: object;
11
-
12
- export function compile(
13
- template: string,
14
- options?: object,
15
- ): (data: object, config: object) => string;
16
- }