@docusaurus/plugin-client-redirects 2.0.0-beta.14 → 2.0.0-beta.15
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.d.ts +1 -1
- package/lib/collectRedirects.js +1 -1
- package/lib/extensionRedirects.d.ts +1 -1
- package/lib/extensionRedirects.js +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/normalizePluginOptions.d.ts +1 -1
- package/lib/redirectValidation.d.ts +1 -1
- package/lib/types.d.ts +2 -14
- package/lib/writeRedirectFiles.d.ts +1 -1
- package/package.json +8 -9
- package/src/collectRedirects.ts +5 -6
- package/src/extensionRedirects.ts +2 -2
- package/src/index.ts +5 -4
- package/src/normalizePluginOptions.ts +5 -1
- package/src/plugin-client-redirects.d.ts +20 -1
- package/src/redirectValidation.ts +1 -1
- package/src/types.ts +2 -22
- package/src/writeRedirectFiles.ts +1 -1
|
@@ -4,5 +4,5 @@
|
|
|
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
|
-
import { PluginContext, RedirectMetadata } from './types';
|
|
7
|
+
import type { PluginContext, RedirectMetadata } from './types';
|
|
8
8
|
export default function collectRedirects(pluginContext: PluginContext, trailingSlash: boolean | undefined): RedirectMetadata[];
|
package/lib/collectRedirects.js
CHANGED
|
@@ -88,7 +88,7 @@ function doCollectRedirects(pluginContext) {
|
|
|
88
88
|
];
|
|
89
89
|
}
|
|
90
90
|
function createRedirectsOptionRedirects(redirectsOption) {
|
|
91
|
-
// For
|
|
91
|
+
// For convenience, user can use a string or a string[]
|
|
92
92
|
function optionToRedirects(option) {
|
|
93
93
|
if (typeof option.from === 'string') {
|
|
94
94
|
return [{ from: option.from, to: option.to }];
|
|
@@ -4,6 +4,6 @@
|
|
|
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
|
-
import { RedirectMetadata } from './types';
|
|
7
|
+
import type { RedirectMetadata } from './types';
|
|
8
8
|
export declare function createToExtensionsRedirects(paths: string[], extensions: string[]): RedirectMetadata[];
|
|
9
9
|
export declare function createFromExtensionsRedirects(paths: string[], extensions: string[]): RedirectMetadata[];
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createFromExtensionsRedirects = exports.createToExtensionsRedirects = void 0;
|
|
10
10
|
const utils_1 = require("@docusaurus/utils");
|
|
11
|
-
const ExtensionAdditionalMessage = 'If the redirect extension system is not good enough for your
|
|
11
|
+
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
12
|
const validateExtension = (ext) => {
|
|
13
13
|
if (!ext) {
|
|
14
14
|
throw new Error(`Extension "${ext}" is not allowed.\n${ExtensionAdditionalMessage}`);
|
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
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
|
-
import { LoadContext, Plugin } from '@docusaurus/types';
|
|
8
|
-
import {
|
|
9
|
-
export default function pluginClientRedirectsPages(context: LoadContext, opts:
|
|
7
|
+
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
8
|
+
import type { PluginOptions } from '@docusaurus/plugin-client-redirects';
|
|
9
|
+
export default function pluginClientRedirectsPages(context: LoadContext, opts: PluginOptions): Plugin<unknown>;
|
|
@@ -4,6 +4,6 @@
|
|
|
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
|
-
import { PluginOptions, UserPluginOptions } from '
|
|
7
|
+
import type { PluginOptions, Options as UserPluginOptions } from '@docusaurus/plugin-client-redirects';
|
|
8
8
|
export declare const DefaultPluginOptions: PluginOptions;
|
|
9
9
|
export default function normalizePluginOptions(userPluginOptions?: UserPluginOptions): PluginOptions;
|
|
@@ -4,5 +4,5 @@
|
|
|
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
|
-
import { RedirectMetadata } from './types';
|
|
7
|
+
import type { RedirectMetadata } from './types';
|
|
8
8
|
export declare function validateRedirect(redirect: RedirectMetadata): void;
|
package/lib/types.d.ts
CHANGED
|
@@ -4,20 +4,8 @@
|
|
|
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
|
-
import { Props } from '@docusaurus/types';
|
|
8
|
-
|
|
9
|
-
id: string;
|
|
10
|
-
fromExtensions: string[];
|
|
11
|
-
toExtensions: string[];
|
|
12
|
-
redirects: RedirectOption[];
|
|
13
|
-
createRedirects?: CreateRedirectsFnOption;
|
|
14
|
-
};
|
|
15
|
-
export declare type CreateRedirectsFnOption = (path: string) => string[] | string | null | undefined;
|
|
16
|
-
export declare type RedirectOption = {
|
|
17
|
-
to: string;
|
|
18
|
-
from: string | string[];
|
|
19
|
-
};
|
|
20
|
-
export declare type UserPluginOptions = Partial<PluginOptions>;
|
|
7
|
+
import type { Props } from '@docusaurus/types';
|
|
8
|
+
import type { PluginOptions } from '@docusaurus/plugin-client-redirects';
|
|
21
9
|
export declare type PluginContext = Pick<Props, 'outDir' | 'baseUrl'> & {
|
|
22
10
|
options: PluginOptions;
|
|
23
11
|
relativeRoutesPaths: string[];
|
|
@@ -4,7 +4,7 @@
|
|
|
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
|
-
import { PluginContext, RedirectMetadata } from './types';
|
|
7
|
+
import type { PluginContext, RedirectMetadata } from './types';
|
|
8
8
|
export declare type WriteFilesPluginContext = Pick<PluginContext, 'baseUrl' | 'outDir'>;
|
|
9
9
|
export declare type RedirectFileMetadata = {
|
|
10
10
|
fileAbsolutePath: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-client-redirects",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.15",
|
|
4
4
|
"description": "Client redirects plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-client-redirects.d.ts",
|
|
@@ -18,19 +18,18 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
22
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
23
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
24
|
-
"@docusaurus/utils-common": "2.0.0-beta.
|
|
25
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
26
|
-
"chalk": "^4.1.2",
|
|
21
|
+
"@docusaurus/core": "2.0.0-beta.15",
|
|
22
|
+
"@docusaurus/logger": "2.0.0-beta.15",
|
|
23
|
+
"@docusaurus/utils": "2.0.0-beta.15",
|
|
24
|
+
"@docusaurus/utils-common": "2.0.0-beta.15",
|
|
25
|
+
"@docusaurus/utils-validation": "2.0.0-beta.15",
|
|
27
26
|
"eta": "^1.12.3",
|
|
28
27
|
"fs-extra": "^10.0.0",
|
|
29
28
|
"lodash": "^4.17.20",
|
|
30
29
|
"tslib": "^2.3.1"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
32
|
+
"@docusaurus/types": "2.0.0-beta.15"
|
|
34
33
|
},
|
|
35
34
|
"peerDependencies": {
|
|
36
35
|
"react": "^16.8.4 || ^17.0.0",
|
|
@@ -39,5 +38,5 @@
|
|
|
39
38
|
"engines": {
|
|
40
39
|
"node": ">=14"
|
|
41
40
|
},
|
|
42
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "6cfad16436c07d8d11e5c2e1486dc59afd483e33"
|
|
43
42
|
}
|
package/src/collectRedirects.ts
CHANGED
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {uniqBy, difference, groupBy} from 'lodash';
|
|
9
|
-
import {
|
|
10
|
-
PluginContext,
|
|
11
|
-
RedirectMetadata,
|
|
9
|
+
import type {
|
|
12
10
|
PluginOptions,
|
|
13
11
|
RedirectOption,
|
|
14
|
-
} from '
|
|
12
|
+
} from '@docusaurus/plugin-client-redirects';
|
|
13
|
+
import type {PluginContext, RedirectMetadata} from './types';
|
|
15
14
|
import {
|
|
16
15
|
createFromExtensionsRedirects,
|
|
17
16
|
createToExtensionsRedirects,
|
|
@@ -19,7 +18,7 @@ import {
|
|
|
19
18
|
import {validateRedirect} from './redirectValidation';
|
|
20
19
|
import {
|
|
21
20
|
applyTrailingSlash,
|
|
22
|
-
ApplyTrailingSlashParams,
|
|
21
|
+
type ApplyTrailingSlashParams,
|
|
23
22
|
} from '@docusaurus/utils-common';
|
|
24
23
|
|
|
25
24
|
import logger from '@docusaurus/logger';
|
|
@@ -144,7 +143,7 @@ function doCollectRedirects(pluginContext: PluginContext): RedirectMetadata[] {
|
|
|
144
143
|
function createRedirectsOptionRedirects(
|
|
145
144
|
redirectsOption: PluginOptions['redirects'],
|
|
146
145
|
): RedirectMetadata[] {
|
|
147
|
-
// For
|
|
146
|
+
// For convenience, user can use a string or a string[]
|
|
148
147
|
function optionToRedirects(option: RedirectOption): RedirectMetadata[] {
|
|
149
148
|
if (typeof option.from === 'string') {
|
|
150
149
|
return [{from: option.from, to: option.to}];
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
removeSuffix,
|
|
11
11
|
removeTrailingSlash,
|
|
12
12
|
} from '@docusaurus/utils';
|
|
13
|
-
import {RedirectMetadata} from './types';
|
|
13
|
+
import type {RedirectMetadata} from './types';
|
|
14
14
|
|
|
15
15
|
const ExtensionAdditionalMessage =
|
|
16
|
-
'If the redirect extension system is not good enough for your
|
|
16
|
+
'If the redirect extension system is not good enough for your use case, you can create redirects yourself with the "createRedirects" plugin option.';
|
|
17
17
|
|
|
18
18
|
const validateExtension = (ext: string) => {
|
|
19
19
|
if (!ext) {
|
package/src/index.ts
CHANGED
|
@@ -5,20 +5,21 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {LoadContext, Plugin, Props} from '@docusaurus/types';
|
|
9
|
-
import {
|
|
8
|
+
import type {LoadContext, Plugin, Props} from '@docusaurus/types';
|
|
9
|
+
import type {PluginContext, RedirectMetadata} from './types';
|
|
10
|
+
import type {PluginOptions} from '@docusaurus/plugin-client-redirects';
|
|
10
11
|
|
|
11
12
|
import normalizePluginOptions from './normalizePluginOptions';
|
|
12
13
|
import collectRedirects from './collectRedirects';
|
|
13
14
|
import writeRedirectFiles, {
|
|
14
15
|
toRedirectFilesMetadata,
|
|
15
|
-
RedirectFileMetadata,
|
|
16
|
+
type RedirectFileMetadata,
|
|
16
17
|
} from './writeRedirectFiles';
|
|
17
18
|
import {removePrefix, addLeadingSlash} from '@docusaurus/utils';
|
|
18
19
|
|
|
19
20
|
export default function pluginClientRedirectsPages(
|
|
20
21
|
context: LoadContext,
|
|
21
|
-
opts:
|
|
22
|
+
opts: PluginOptions,
|
|
22
23
|
): Plugin<unknown> {
|
|
23
24
|
const {trailingSlash} = context.siteConfig;
|
|
24
25
|
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import type {
|
|
9
|
+
PluginOptions,
|
|
10
|
+
Options as UserPluginOptions,
|
|
11
|
+
RedirectOption,
|
|
12
|
+
} from '@docusaurus/plugin-client-redirects';
|
|
9
13
|
import {Joi, PathnameSchema} from '@docusaurus/utils-validation';
|
|
10
14
|
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
|
|
11
15
|
|
|
@@ -5,4 +5,23 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type RedirectOption = {
|
|
9
|
+
to: string;
|
|
10
|
+
from: string | string[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// For a given existing route path,
|
|
14
|
+
// return all the paths from which we should redirect from
|
|
15
|
+
export type CreateRedirectsFnOption = (
|
|
16
|
+
path: string,
|
|
17
|
+
) => string[] | string | null | undefined;
|
|
18
|
+
|
|
19
|
+
export type PluginOptions = {
|
|
20
|
+
id: string;
|
|
21
|
+
fromExtensions: string[];
|
|
22
|
+
toExtensions: string[];
|
|
23
|
+
redirects: RedirectOption[];
|
|
24
|
+
createRedirects?: CreateRedirectsFnOption;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type Options = Partial<PluginOptions>;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {RedirectMetadata} from './types';
|
|
8
|
+
import type {RedirectMetadata} from './types';
|
|
9
9
|
import {Joi, PathnameSchema} from '@docusaurus/utils-validation';
|
|
10
10
|
|
|
11
11
|
const RedirectSchema = Joi.object<RedirectMetadata>({
|
package/src/types.ts
CHANGED
|
@@ -5,28 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {Props} from '@docusaurus/types';
|
|
9
|
-
|
|
10
|
-
export type PluginOptions = {
|
|
11
|
-
id: string;
|
|
12
|
-
fromExtensions: string[];
|
|
13
|
-
toExtensions: string[];
|
|
14
|
-
redirects: RedirectOption[];
|
|
15
|
-
createRedirects?: CreateRedirectsFnOption;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// For a given existing route path,
|
|
19
|
-
// return all the paths from which we should redirect from
|
|
20
|
-
export type CreateRedirectsFnOption = (
|
|
21
|
-
path: string,
|
|
22
|
-
) => string[] | string | null | undefined;
|
|
23
|
-
|
|
24
|
-
export type RedirectOption = {
|
|
25
|
-
to: string;
|
|
26
|
-
from: string | string[];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type UserPluginOptions = Partial<PluginOptions>;
|
|
8
|
+
import type {Props} from '@docusaurus/types';
|
|
9
|
+
import type {PluginOptions} from '@docusaurus/plugin-client-redirects';
|
|
30
10
|
|
|
31
11
|
// The minimal infos the plugin needs to work
|
|
32
12
|
export type PluginContext = Pick<Props, 'outDir' | 'baseUrl'> & {
|
|
@@ -9,7 +9,7 @@ import fs from 'fs-extra';
|
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import {memoize} from 'lodash';
|
|
11
11
|
|
|
12
|
-
import {PluginContext, RedirectMetadata} from './types';
|
|
12
|
+
import type {PluginContext, RedirectMetadata} from './types';
|
|
13
13
|
import createRedirectPageContent from './createRedirectPageContent';
|
|
14
14
|
import {normalizeUrl} from '@docusaurus/utils';
|
|
15
15
|
|