@docusaurus/plugin-client-redirects 0.0.0-4608 → 0.0.0-4614
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/collectRedirects.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
10
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
11
11
|
const extensionRedirects_1 = require("./extensionRedirects");
|
|
12
12
|
const redirectValidation_1 = require("./redirectValidation");
|
|
13
13
|
const utils_common_1 = require("@docusaurus/utils-common");
|
|
@@ -54,7 +54,7 @@ function validateCollectedRedirects(redirects, pluginContext) {
|
|
|
54
54
|
}
|
|
55
55
|
const allowedToPaths = pluginContext.relativeRoutesPaths;
|
|
56
56
|
const toPaths = redirects.map((redirect) => redirect.to);
|
|
57
|
-
const illegalToPaths =
|
|
57
|
+
const illegalToPaths = lodash_1.default.difference(toPaths, allowedToPaths);
|
|
58
58
|
if (illegalToPaths.length > 0) {
|
|
59
59
|
throw new Error(`You are trying to create client-side redirections to paths that do not exist:
|
|
60
60
|
- ${illegalToPaths.join('\n- ')}
|
|
@@ -67,13 +67,13 @@ Valid paths you can redirect to:
|
|
|
67
67
|
function filterUnwantedRedirects(redirects, pluginContext) {
|
|
68
68
|
// we don't want to create twice the same redirect
|
|
69
69
|
// that would lead to writing twice the same html redirection file
|
|
70
|
-
Object.entries(
|
|
70
|
+
Object.entries(lodash_1.default.groupBy(redirects, (redirect) => redirect.from)).forEach(([from, groupedFromRedirects]) => {
|
|
71
71
|
if (groupedFromRedirects.length > 1) {
|
|
72
72
|
logger_1.default.error `name=${'@docusaurus/plugin-client-redirects'}: multiple redirects are created with the same "from" pathname: path=${from}
|
|
73
73
|
It is not possible to redirect the same pathname to multiple destinations: ${groupedFromRedirects.map((r) => JSON.stringify(r))}`;
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
|
-
const collectedRedirects =
|
|
76
|
+
const collectedRedirects = lodash_1.default.uniqBy(redirects, (redirect) => redirect.from);
|
|
77
77
|
// We don't want to override an already existing route with a redirect file!
|
|
78
78
|
const redirectsOverridingExistingPath = collectedRedirects.filter((redirect) => pluginContext.relativeRoutesPaths.includes(redirect.from));
|
|
79
79
|
if (redirectsOverridingExistingPath.length > 0) {
|
|
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const eta = (0, tslib_1.__importStar)(require("eta"));
|
|
11
11
|
const redirectPage_template_html_1 = (0, tslib_1.__importDefault)(require("./templates/redirectPage.template.html"));
|
|
12
|
-
const lodash_1 = require("lodash");
|
|
13
|
-
const getCompiledRedirectPageTemplate =
|
|
12
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
13
|
+
const getCompiledRedirectPageTemplate = lodash_1.default.memoize(() => eta.compile(redirectPage_template_html_1.default.trim()));
|
|
14
14
|
function renderRedirectPageTemplate(data) {
|
|
15
15
|
const compiled = getCompiledRedirectPageTemplate();
|
|
16
16
|
return compiled(data, eta.defaultConfig);
|
|
@@ -10,7 +10,7 @@ exports.writeRedirectFile = exports.toRedirectFilesMetadata = exports.createToUr
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
12
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
13
|
-
const lodash_1 = require("lodash");
|
|
13
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
14
14
|
const createRedirectPageContent_1 = (0, tslib_1.__importDefault)(require("./createRedirectPageContent"));
|
|
15
15
|
const utils_1 = require("@docusaurus/utils");
|
|
16
16
|
function createToUrl(baseUrl, to) {
|
|
@@ -48,7 +48,7 @@ function toRedirectFilesMetadata(redirects, pluginContext, trailingSlash) {
|
|
|
48
48
|
// Perf: avoid rendering the template twice with the exact same "props"
|
|
49
49
|
// We might create multiple redirect pages for the same destination url
|
|
50
50
|
// note: the first fn arg is the cache key!
|
|
51
|
-
const createPageContentMemoized =
|
|
51
|
+
const createPageContentMemoized = lodash_1.default.memoize((toUrl) => (0, createRedirectPageContent_1.default)({ toUrl }));
|
|
52
52
|
const createFileMetadata = (redirect) => {
|
|
53
53
|
const fileRelativePath = getRedirectFilePath(redirect.from, trailingSlash);
|
|
54
54
|
const fileAbsolutePath = path_1.default.join(pluginContext.outDir, fileRelativePath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-client-redirects",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4614",
|
|
4
4
|
"description": "Client redirects plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-client-redirects.d.ts",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/core": "0.0.0-
|
|
22
|
-
"@docusaurus/logger": "0.0.0-
|
|
23
|
-
"@docusaurus/utils": "0.0.0-
|
|
24
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
25
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
21
|
+
"@docusaurus/core": "0.0.0-4614",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4614",
|
|
23
|
+
"@docusaurus/utils": "0.0.0-4614",
|
|
24
|
+
"@docusaurus/utils-common": "0.0.0-4614",
|
|
25
|
+
"@docusaurus/utils-validation": "0.0.0-4614",
|
|
26
26
|
"eta": "^1.12.3",
|
|
27
27
|
"fs-extra": "^10.0.0",
|
|
28
28
|
"lodash": "^4.17.21",
|
|
29
29
|
"tslib": "^2.3.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@docusaurus/types": "0.0.0-
|
|
32
|
+
"@docusaurus/types": "0.0.0-4614"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "^16.8.4 || ^17.0.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=14"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "0fa2e52fbc24ea9aa80a5da40149036009bcf21c"
|
|
42
42
|
}
|
package/src/collectRedirects.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import _ from 'lodash';
|
|
9
9
|
import type {
|
|
10
10
|
PluginOptions,
|
|
11
11
|
RedirectOption,
|
|
@@ -79,7 +79,7 @@ function validateCollectedRedirects(
|
|
|
79
79
|
|
|
80
80
|
const allowedToPaths = pluginContext.relativeRoutesPaths;
|
|
81
81
|
const toPaths = redirects.map((redirect) => redirect.to);
|
|
82
|
-
const illegalToPaths = difference(toPaths, allowedToPaths);
|
|
82
|
+
const illegalToPaths = _.difference(toPaths, allowedToPaths);
|
|
83
83
|
if (illegalToPaths.length > 0) {
|
|
84
84
|
throw new Error(
|
|
85
85
|
`You are trying to create client-side redirections to paths that do not exist:
|
|
@@ -98,7 +98,7 @@ function filterUnwantedRedirects(
|
|
|
98
98
|
): RedirectMetadata[] {
|
|
99
99
|
// we don't want to create twice the same redirect
|
|
100
100
|
// that would lead to writing twice the same html redirection file
|
|
101
|
-
Object.entries(groupBy(redirects, (redirect) => redirect.from)).forEach(
|
|
101
|
+
Object.entries(_.groupBy(redirects, (redirect) => redirect.from)).forEach(
|
|
102
102
|
([from, groupedFromRedirects]) => {
|
|
103
103
|
if (groupedFromRedirects.length > 1) {
|
|
104
104
|
logger.error`name=${'@docusaurus/plugin-client-redirects'}: multiple redirects are created with the same "from" pathname: path=${from}
|
|
@@ -108,7 +108,7 @@ It is not possible to redirect the same pathname to multiple destinations: ${gro
|
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
);
|
|
111
|
-
const collectedRedirects = uniqBy(redirects, (redirect) => redirect.from);
|
|
111
|
+
const collectedRedirects = _.uniqBy(redirects, (redirect) => redirect.from);
|
|
112
112
|
|
|
113
113
|
// We don't want to override an already existing route with a redirect file!
|
|
114
114
|
const redirectsOverridingExistingPath = collectedRedirects.filter(
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
import * as eta from 'eta';
|
|
9
9
|
import redirectPageTemplate from './templates/redirectPage.template.html';
|
|
10
|
-
import
|
|
10
|
+
import _ from 'lodash';
|
|
11
11
|
|
|
12
12
|
type CreateRedirectPageOptions = {
|
|
13
13
|
toUrl: string;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const getCompiledRedirectPageTemplate = memoize(() =>
|
|
16
|
+
const getCompiledRedirectPageTemplate = _.memoize(() =>
|
|
17
17
|
eta.compile(redirectPageTemplate.trim()),
|
|
18
18
|
);
|
|
19
19
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import fs from 'fs-extra';
|
|
9
9
|
import path from 'path';
|
|
10
|
-
import
|
|
10
|
+
import _ from 'lodash';
|
|
11
11
|
|
|
12
12
|
import type {PluginContext, RedirectMetadata} from './types';
|
|
13
13
|
import createRedirectPageContent from './createRedirectPageContent';
|
|
@@ -63,7 +63,7 @@ export function toRedirectFilesMetadata(
|
|
|
63
63
|
// Perf: avoid rendering the template twice with the exact same "props"
|
|
64
64
|
// We might create multiple redirect pages for the same destination url
|
|
65
65
|
// note: the first fn arg is the cache key!
|
|
66
|
-
const createPageContentMemoized = memoize((toUrl: string) =>
|
|
66
|
+
const createPageContentMemoized = _.memoize((toUrl: string) =>
|
|
67
67
|
createRedirectPageContent({toUrl}),
|
|
68
68
|
);
|
|
69
69
|
|