@docusaurus/plugin-client-redirects 3.3.2 → 3.5.0
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 +1 -1
- package/lib/createRedirectPageContent.js +1 -1
- package/lib/extensionRedirects.js +2 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +9 -2
- package/lib/options.js +2 -2
- package/lib/redirectValidation.js +1 -2
- package/lib/writeRedirectFiles.js +4 -5
- package/package.json +8 -8
- package/src/index.ts +13 -2
package/lib/collectRedirects.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.default = collectRedirects;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
11
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
@@ -38,7 +39,6 @@ function collectRedirects(pluginContext, trailingSlash) {
|
|
|
38
39
|
validateCollectedRedirects(redirects, pluginContext);
|
|
39
40
|
return filterUnwantedRedirects(redirects, pluginContext);
|
|
40
41
|
}
|
|
41
|
-
exports.default = collectRedirects;
|
|
42
42
|
function validateCollectedRedirects(redirects, pluginContext) {
|
|
43
43
|
const redirectValidationErrors = redirects
|
|
44
44
|
.map((redirect) => {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.default = createRedirectPageContent;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
11
12
|
const eta = tslib_1.__importStar(require("eta"));
|
|
@@ -33,4 +34,3 @@ function createRedirectPageContent({ toUrl, }) {
|
|
|
33
34
|
searchAnchorForwarding: searchAnchorForwarding(toUrl),
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
|
-
exports.default = createRedirectPageContent;
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.createToExtensionsRedirects = createToExtensionsRedirects;
|
|
10
|
+
exports.createFromExtensionsRedirects = createFromExtensionsRedirects;
|
|
10
11
|
const utils_common_1 = require("@docusaurus/utils-common");
|
|
11
12
|
const ExtensionAdditionalMessage = 'If the redirect extension system is not good enough for your use case, you can create redirects yourself with the "createRedirects" plugin option.';
|
|
12
13
|
const validateExtension = (ext) => {
|
|
@@ -39,7 +40,6 @@ function createToExtensionsRedirects(paths, extensions) {
|
|
|
39
40
|
};
|
|
40
41
|
return paths.flatMap(createPathRedirects);
|
|
41
42
|
}
|
|
42
|
-
exports.createToExtensionsRedirects = createToExtensionsRedirects;
|
|
43
43
|
/**
|
|
44
44
|
* Create new `/path.html/index.html` that redirects to existing an `/path`
|
|
45
45
|
* The filename pattern might look weird but it's on purpose (see
|
|
@@ -64,4 +64,3 @@ function createFromExtensionsRedirects(paths, extensions) {
|
|
|
64
64
|
};
|
|
65
65
|
return paths.flatMap(createPathRedirects);
|
|
66
66
|
}
|
|
67
|
-
exports.createFromExtensionsRedirects = createFromExtensionsRedirects;
|
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
8
8
|
import type { PluginOptions, Options } from './options';
|
|
9
|
-
export default function pluginClientRedirectsPages(context: LoadContext, options: PluginOptions): Plugin<void
|
|
9
|
+
export default function pluginClientRedirectsPages(context: LoadContext, options: PluginOptions): Plugin<void> | null;
|
|
10
10
|
export { validateOptions } from './options';
|
|
11
11
|
export type { PluginOptions, Options };
|
package/lib/index.js
CHANGED
|
@@ -7,14 +7,22 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateOptions = void 0;
|
|
10
|
+
exports.default = pluginClientRedirectsPages;
|
|
10
11
|
const tslib_1 = require("tslib");
|
|
11
12
|
const utils_common_1 = require("@docusaurus/utils-common");
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
14
|
const collectRedirects_1 = tslib_1.__importDefault(require("./collectRedirects"));
|
|
13
15
|
const writeRedirectFiles_1 = tslib_1.__importStar(require("./writeRedirectFiles"));
|
|
16
|
+
const PluginName = 'docusaurus-plugin-client-redirects';
|
|
14
17
|
function pluginClientRedirectsPages(context, options) {
|
|
15
18
|
const { trailingSlash } = context.siteConfig;
|
|
19
|
+
const router = context.siteConfig.future.experimental_router;
|
|
20
|
+
if (router === 'hash') {
|
|
21
|
+
logger_1.default.warn(`${PluginName} does not support the Hash Router and will be disabled.`);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
16
24
|
return {
|
|
17
|
-
name:
|
|
25
|
+
name: PluginName,
|
|
18
26
|
async postBuild(props) {
|
|
19
27
|
const pluginContext = {
|
|
20
28
|
relativeRoutesPaths: props.routesPaths.map((path) => `${(0, utils_common_1.addLeadingSlash)((0, utils_common_1.removePrefix)(path, props.baseUrl))}`),
|
|
@@ -30,6 +38,5 @@ function pluginClientRedirectsPages(context, options) {
|
|
|
30
38
|
},
|
|
31
39
|
};
|
|
32
40
|
}
|
|
33
|
-
exports.default = pluginClientRedirectsPages;
|
|
34
41
|
var options_1 = require("./options");
|
|
35
42
|
Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
|
package/lib/options.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.DEFAULT_OPTIONS = void 0;
|
|
10
|
+
exports.validateOptions = validateOptions;
|
|
10
11
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
12
|
exports.DEFAULT_OPTIONS = {
|
|
12
13
|
fromExtensions: [],
|
|
@@ -33,4 +34,3 @@ const UserOptionsSchema = utils_validation_1.Joi.object({
|
|
|
33
34
|
function validateOptions({ validate, options: userOptions, }) {
|
|
34
35
|
return validate(UserOptionsSchema, userOptions);
|
|
35
36
|
}
|
|
36
|
-
exports.validateOptions = validateOptions;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.validateRedirect =
|
|
9
|
+
exports.validateRedirect = validateRedirect;
|
|
10
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
11
|
const RedirectSchema = utils_validation_1.Joi.object({
|
|
12
12
|
from: utils_validation_1.PathnameSchema.required(),
|
|
@@ -22,4 +22,3 @@ function validateRedirect(redirect) {
|
|
|
22
22
|
throw new Error(`${JSON.stringify(redirect)} => Validation error: ${error.message}`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
exports.validateRedirect = validateRedirect;
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.createToUrl = createToUrl;
|
|
10
|
+
exports.toRedirectFiles = toRedirectFiles;
|
|
11
|
+
exports.writeRedirectFile = writeRedirectFile;
|
|
12
|
+
exports.default = writeRedirectFiles;
|
|
10
13
|
const tslib_1 = require("tslib");
|
|
11
14
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
15
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -20,7 +23,6 @@ function createToUrl(baseUrl, to) {
|
|
|
20
23
|
}
|
|
21
24
|
return to;
|
|
22
25
|
}
|
|
23
|
-
exports.createToUrl = createToUrl;
|
|
24
26
|
// Create redirect file path
|
|
25
27
|
// Make sure this path has lower precedence over the original file path when
|
|
26
28
|
// served by host providers!
|
|
@@ -66,7 +68,6 @@ function toRedirectFiles(redirects, pluginContext, trailingSlash) {
|
|
|
66
68
|
};
|
|
67
69
|
return redirects.map(createFileMetadata);
|
|
68
70
|
}
|
|
69
|
-
exports.toRedirectFiles = toRedirectFiles;
|
|
70
71
|
async function writeRedirectFile(file) {
|
|
71
72
|
try {
|
|
72
73
|
// User-friendly security to prevent file overrides
|
|
@@ -83,8 +84,6 @@ async function writeRedirectFile(file) {
|
|
|
83
84
|
throw err;
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
|
-
exports.writeRedirectFile = writeRedirectFile;
|
|
87
87
|
async function writeRedirectFiles(redirectFiles) {
|
|
88
88
|
await Promise.all(redirectFiles.map(writeRedirectFile));
|
|
89
89
|
}
|
|
90
|
-
exports.default = writeRedirectFiles;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-client-redirects",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
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": "3.
|
|
22
|
-
"@docusaurus/logger": "3.
|
|
23
|
-
"@docusaurus/utils": "3.
|
|
24
|
-
"@docusaurus/utils-common": "3.
|
|
25
|
-
"@docusaurus/utils-validation": "3.
|
|
21
|
+
"@docusaurus/core": "3.5.0",
|
|
22
|
+
"@docusaurus/logger": "3.5.0",
|
|
23
|
+
"@docusaurus/utils": "3.5.0",
|
|
24
|
+
"@docusaurus/utils-common": "3.5.0",
|
|
25
|
+
"@docusaurus/utils-validation": "3.5.0",
|
|
26
26
|
"eta": "^2.2.0",
|
|
27
27
|
"fs-extra": "^11.1.1",
|
|
28
28
|
"lodash": "^4.17.21",
|
|
29
29
|
"tslib": "^2.6.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@docusaurus/types": "3.
|
|
32
|
+
"@docusaurus/types": "3.5.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "^18.0.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=18.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "cb5829f3c34b26d798b869e38ee25073488140bd"
|
|
42
42
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {addLeadingSlash, removePrefix} from '@docusaurus/utils-common';
|
|
9
|
+
import logger from '@docusaurus/logger';
|
|
9
10
|
import collectRedirects from './collectRedirects';
|
|
10
11
|
import writeRedirectFiles, {
|
|
11
12
|
toRedirectFiles,
|
|
@@ -15,14 +16,24 @@ import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
|
15
16
|
import type {PluginContext, RedirectItem} from './types';
|
|
16
17
|
import type {PluginOptions, Options} from './options';
|
|
17
18
|
|
|
19
|
+
const PluginName = 'docusaurus-plugin-client-redirects';
|
|
20
|
+
|
|
18
21
|
export default function pluginClientRedirectsPages(
|
|
19
22
|
context: LoadContext,
|
|
20
23
|
options: PluginOptions,
|
|
21
|
-
): Plugin<void> {
|
|
24
|
+
): Plugin<void> | null {
|
|
22
25
|
const {trailingSlash} = context.siteConfig;
|
|
26
|
+
const router = context.siteConfig.future.experimental_router;
|
|
27
|
+
|
|
28
|
+
if (router === 'hash') {
|
|
29
|
+
logger.warn(
|
|
30
|
+
`${PluginName} does not support the Hash Router and will be disabled.`,
|
|
31
|
+
);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
23
34
|
|
|
24
35
|
return {
|
|
25
|
-
name:
|
|
36
|
+
name: PluginName,
|
|
26
37
|
async postBuild(props) {
|
|
27
38
|
const pluginContext: PluginContext = {
|
|
28
39
|
relativeRoutesPaths: props.routesPaths.map(
|