@docusaurus/plugin-client-redirects 0.0.0-4728 → 0.0.0-4732

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.
@@ -4,8 +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
- declare type CreateRedirectPageOptions = {
7
+ export default function createRedirectPageContent({ toUrl, }: {
8
8
  toUrl: string;
9
- };
10
- export default function createRedirectPageContent({ toUrl, }: CreateRedirectPageOptions): string;
11
- export {};
9
+ }): string;
package/lib/options.js CHANGED
@@ -28,7 +28,7 @@ const UserOptionsSchema = utils_validation_1.Joi.object({
28
28
  redirects: utils_validation_1.Joi.array()
29
29
  .items(RedirectPluginOptionValidation)
30
30
  .default(exports.DEFAULT_OPTIONS.redirects),
31
- createRedirects: utils_validation_1.Joi.function().arity(1),
31
+ createRedirects: utils_validation_1.Joi.function().maxArity(1),
32
32
  }).default(exports.DEFAULT_OPTIONS);
33
33
  function validateOptions({ validate, options: userOptions, }) {
34
34
  return validate(UserOptionsSchema, userOptions);
package/lib/types.d.ts CHANGED
@@ -6,11 +6,21 @@
6
6
  */
7
7
  import type { Props } from '@docusaurus/types';
8
8
  import type { PluginOptions } from '@docusaurus/plugin-client-redirects';
9
+ /**
10
+ * The minimal infos the plugin needs to work
11
+ */
9
12
  export declare type PluginContext = Pick<Props, 'outDir' | 'baseUrl'> & {
10
13
  options: PluginOptions;
11
14
  relativeRoutesPaths: string[];
12
15
  };
16
+ /**
17
+ * In-memory representation of redirects we want: easier to test
18
+ * /!\ easy to be confused: "from" is the new page we should create,
19
+ * that redirects to "to": the existing Docusaurus page
20
+ */
13
21
  export declare type RedirectMetadata = {
22
+ /** Pathname of the new page we should create */
14
23
  from: string;
24
+ /** Pathname of an existing Docusaurus page */
15
25
  to: string;
16
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-client-redirects",
3
- "version": "0.0.0-4728",
3
+ "version": "0.0.0-4732",
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-4728",
22
- "@docusaurus/logger": "0.0.0-4728",
23
- "@docusaurus/utils": "0.0.0-4728",
24
- "@docusaurus/utils-common": "0.0.0-4728",
25
- "@docusaurus/utils-validation": "0.0.0-4728",
21
+ "@docusaurus/core": "0.0.0-4732",
22
+ "@docusaurus/logger": "0.0.0-4732",
23
+ "@docusaurus/utils": "0.0.0-4732",
24
+ "@docusaurus/utils-common": "0.0.0-4732",
25
+ "@docusaurus/utils-validation": "0.0.0-4732",
26
26
  "eta": "^1.12.3",
27
27
  "fs-extra": "^10.0.1",
28
28
  "lodash": "^4.17.21",
29
29
  "tslib": "^2.3.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@docusaurus/types": "0.0.0-4728"
32
+ "@docusaurus/types": "0.0.0-4732"
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": "517f5b73eaacc1002a973074567a321b469868fe"
41
+ "gitHead": "da1dfdadc386a446278acd3922f327b291b7b7f1"
42
42
  }
@@ -9,10 +9,6 @@ import * as eta from 'eta';
9
9
  import redirectPageTemplate from './templates/redirectPage.template.html';
10
10
  import _ from 'lodash';
11
11
 
12
- type CreateRedirectPageOptions = {
13
- toUrl: string;
14
- };
15
-
16
12
  const getCompiledRedirectPageTemplate = _.memoize(() =>
17
13
  eta.compile(redirectPageTemplate.trim()),
18
14
  );
@@ -24,7 +20,9 @@ function renderRedirectPageTemplate(data: Record<string, unknown>) {
24
20
 
25
21
  export default function createRedirectPageContent({
26
22
  toUrl,
27
- }: CreateRedirectPageOptions): string {
23
+ }: {
24
+ toUrl: string;
25
+ }): string {
28
26
  return renderRedirectPageTemplate({
29
27
  toUrl: encodeURI(toUrl),
30
28
  });
package/src/options.ts CHANGED
@@ -41,7 +41,7 @@ const UserOptionsSchema = Joi.object<PluginOptions>({
41
41
  redirects: Joi.array()
42
42
  .items(RedirectPluginOptionValidation)
43
43
  .default(DEFAULT_OPTIONS.redirects),
44
- createRedirects: Joi.function().arity(1),
44
+ createRedirects: Joi.function().maxArity(1),
45
45
  }).default(DEFAULT_OPTIONS);
46
46
 
47
47
  export function validateOptions({
@@ -10,18 +10,23 @@ export type RedirectOption = {
10
10
  from: string | string[];
11
11
  };
12
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
13
  export type PluginOptions = {
14
+ /** Plugin ID. */
20
15
  id: string;
16
+ /** The extensions to be removed from the route after redirecting. */
21
17
  fromExtensions: string[];
18
+ /** The extensions to be appended to the route after redirecting. */
22
19
  toExtensions: string[];
20
+ /** The list of redirect rules, each one with multiple `from`s → one `to`. */
23
21
  redirects: RedirectOption[];
24
- createRedirects?: CreateRedirectsFnOption;
22
+ /**
23
+ * A callback to create a redirect rule.
24
+ * @returns All the paths from which we should redirect to `path`
25
+ */
26
+ createRedirects?: (
27
+ /** An existing Docusaurus route path */
28
+ path: string,
29
+ ) => string[] | string | null | undefined;
25
30
  };
26
31
 
27
32
  export type Options = Partial<PluginOptions>;
package/src/types.ts CHANGED
@@ -8,16 +8,22 @@
8
8
  import type {Props} from '@docusaurus/types';
9
9
  import type {PluginOptions} from '@docusaurus/plugin-client-redirects';
10
10
 
11
- // The minimal infos the plugin needs to work
11
+ /**
12
+ * The minimal infos the plugin needs to work
13
+ */
12
14
  export type PluginContext = Pick<Props, 'outDir' | 'baseUrl'> & {
13
15
  options: PluginOptions;
14
16
  relativeRoutesPaths: string[];
15
17
  };
16
18
 
17
- // In-memory representation of redirects we want: easier to test
18
- // /!\ easy to be confused: "from" is the new page we should create,
19
- // that redirects to "to": the existing Docusaurus page
19
+ /**
20
+ * In-memory representation of redirects we want: easier to test
21
+ * /!\ easy to be confused: "from" is the new page we should create,
22
+ * that redirects to "to": the existing Docusaurus page
23
+ */
20
24
  export type RedirectMetadata = {
21
- from: string; // pathname
22
- to: string; // pathname
25
+ /** Pathname of the new page we should create */
26
+ from: string;
27
+ /** Pathname of an existing Docusaurus page */
28
+ to: string;
23
29
  };