@docusaurus/plugin-content-pages 2.0.0-beta.16 → 2.0.0-beta.19

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.
@@ -5,4 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { FrontMatter } from '@docusaurus/plugin-content-pages';
8
- export declare function validatePageFrontMatter(frontMatter: Record<string, unknown>): FrontMatter;
8
+ export declare function validatePageFrontMatter(frontMatter: {
9
+ [key: string]: unknown;
10
+ }): FrontMatter;
File without changes
package/lib/index.d.ts CHANGED
@@ -4,9 +4,9 @@
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 type { LoadContext, Plugin, OptionValidationContext, ValidationResult } from '@docusaurus/types';
8
- import type { LoadedContent, PagesContentPaths } from './types';
9
- import type { PluginOptions } from '@docusaurus/plugin-content-pages';
7
+ import type { LoadContext, Plugin } from '@docusaurus/types';
8
+ import type { PagesContentPaths } from './types';
9
+ import type { PluginOptions, LoadedContent } from '@docusaurus/plugin-content-pages';
10
10
  export declare function getContentPathList(contentPaths: PagesContentPaths): string[];
11
11
  export default function pluginContentPages(context: LoadContext, options: PluginOptions): Promise<Plugin<LoadedContent | null>>;
12
- export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions>;
12
+ export { validateOptions } from './options';
package/lib/index.js CHANGED
@@ -8,22 +8,20 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateOptions = exports.getContentPathList = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
- const remark_admonitions_1 = (0, tslib_1.__importDefault)(require("remark-admonitions"));
15
- const pluginOptionSchema_1 = require("./pluginOptionSchema");
16
- const pageFrontMatter_1 = require("./pageFrontMatter");
14
+ const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
15
+ const frontMatter_1 = require("./frontMatter");
17
16
  function getContentPathList(contentPaths) {
18
17
  return [contentPaths.contentPathLocalized, contentPaths.contentPath];
19
18
  }
20
19
  exports.getContentPathList = getContentPathList;
21
20
  const isMarkdownSource = (source) => source.endsWith('.md') || source.endsWith('.mdx');
22
21
  async function pluginContentPages(context, options) {
23
- var _a;
24
22
  if (options.admonitions) {
25
23
  options.remarkPlugins = options.remarkPlugins.concat([
26
- [remark_admonitions_1.default, options.admonitions || {}],
24
+ [remark_admonitions_1.default, options.admonitions],
27
25
  ]);
28
26
  }
29
27
  const { siteConfig, siteDir, generatedFilesDir, i18n: { currentLocale }, } = context;
@@ -37,11 +35,11 @@ async function pluginContentPages(context, options) {
37
35
  }),
38
36
  };
39
37
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-pages');
40
- const dataDir = path_1.default.join(pluginDataDirRoot, (_a = options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID);
38
+ const dataDir = path_1.default.join(pluginDataDirRoot, options.id ?? utils_1.DEFAULT_PLUGIN_ID);
41
39
  return {
42
40
  name: 'docusaurus-plugin-content-pages',
43
41
  getPathsToWatch() {
44
- const { include = [] } = options;
42
+ const { include } = options;
45
43
  return getContentPathList(contentPaths).flatMap((contentPath) => include.map((pattern) => `${contentPath}/${pattern}`));
46
44
  },
47
45
  async loadContent() {
@@ -55,7 +53,6 @@ async function pluginContentPages(context, options) {
55
53
  ignore: options.exclude,
56
54
  });
57
55
  async function toMetadata(relativeSource) {
58
- var _a, _b;
59
56
  // Lookup in localized folder in priority
60
57
  const contentPath = await (0, utils_1.getFolderContainingFile)(getContentPathList(contentPaths), relativeSource);
61
58
  const source = path_1.default.join(contentPath, relativeSource);
@@ -74,13 +71,13 @@ async function pluginContentPages(context, options) {
74
71
  }
75
72
  const content = await fs_extra_1.default.readFile(source, 'utf-8');
76
73
  const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = (0, utils_1.parseMarkdownString)(content);
77
- const frontMatter = (0, pageFrontMatter_1.validatePageFrontMatter)(unsafeFrontMatter);
74
+ const frontMatter = (0, frontMatter_1.validatePageFrontMatter)(unsafeFrontMatter);
78
75
  return {
79
76
  type: 'mdx',
80
77
  permalink,
81
78
  source: aliasedSourcePath,
82
- title: (_a = frontMatter.title) !== null && _a !== void 0 ? _a : contentTitle,
83
- description: (_b = frontMatter.description) !== null && _b !== void 0 ? _b : excerpt,
79
+ title: frontMatter.title ?? contentTitle,
80
+ description: frontMatter.description ?? excerpt,
84
81
  frontMatter,
85
82
  };
86
83
  }
@@ -119,7 +116,7 @@ async function pluginContentPages(context, options) {
119
116
  }
120
117
  }));
121
118
  },
122
- configureWebpack(_config, isServer, { getJSLoader }) {
119
+ configureWebpack(config, isServer, { getJSLoader }) {
123
120
  const { rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
124
121
  const contentDirs = getContentPathList(contentPaths);
125
122
  return {
@@ -171,8 +168,5 @@ async function pluginContentPages(context, options) {
171
168
  };
172
169
  }
173
170
  exports.default = pluginContentPages;
174
- function validateOptions({ validate, options, }) {
175
- const validatedOptions = validate(pluginOptionSchema_1.PluginOptionSchema, options);
176
- return validatedOptions;
177
- }
178
- exports.validateOptions = validateOptions;
171
+ var options_1 = require("./options");
172
+ Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
@@ -11,6 +11,6 @@ function markdownLoader(fileString) {
11
11
  // const options = this.getOptions();
12
12
  // TODO provide additional md processing here? like interlinking pages?
13
13
  // fileString = linkify(fileString)
14
- return callback && callback(null, fileString);
14
+ return callback?.(null, fileString);
15
15
  }
16
16
  exports.default = markdownLoader;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { PluginOptions, Options } from '@docusaurus/plugin-content-pages';
8
+ import type { OptionValidationContext } from '@docusaurus/types';
9
+ export declare const DEFAULT_OPTIONS: PluginOptions;
10
+ export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
@@ -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.PluginOptionSchema = exports.DEFAULT_OPTIONS = void 0;
9
+ exports.validateOptions = exports.DEFAULT_OPTIONS = void 0;
10
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
11
  const utils_1 = require("@docusaurus/utils");
12
12
  exports.DEFAULT_OPTIONS = {
@@ -21,7 +21,7 @@ exports.DEFAULT_OPTIONS = {
21
21
  beforeDefaultRemarkPlugins: [],
22
22
  admonitions: {},
23
23
  };
24
- exports.PluginOptionSchema = utils_validation_1.Joi.object({
24
+ const PluginOptionSchema = utils_validation_1.Joi.object({
25
25
  path: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.path),
26
26
  routeBasePath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.routeBasePath),
27
27
  include: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.include),
@@ -33,3 +33,8 @@ exports.PluginOptionSchema = utils_validation_1.Joi.object({
33
33
  beforeDefaultRemarkPlugins: utils_validation_1.RemarkPluginsSchema.default(exports.DEFAULT_OPTIONS.beforeDefaultRemarkPlugins),
34
34
  admonitions: utils_validation_1.AdmonitionsSchema.default(exports.DEFAULT_OPTIONS.admonitions),
35
35
  });
36
+ function validateOptions({ validate, options, }) {
37
+ const validatedOptions = validate(PluginOptionSchema, options);
38
+ return validatedOptions;
39
+ }
40
+ exports.validateOptions = validateOptions;
package/lib/types.d.ts CHANGED
@@ -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
- import type { Metadata } from '@docusaurus/plugin-content-pages';
8
- export declare type LoadedContent = Metadata[];
9
7
  export declare type PagesContentPaths = {
10
8
  contentPath: string;
11
9
  contentPathLocalized: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-pages",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.19",
4
4
  "description": "Pages plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-pages.d.ts",
@@ -18,17 +18,17 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "2.0.0-beta.16",
22
- "@docusaurus/mdx-loader": "2.0.0-beta.16",
23
- "@docusaurus/utils": "2.0.0-beta.16",
24
- "@docusaurus/utils-validation": "2.0.0-beta.16",
25
- "fs-extra": "^10.0.1",
21
+ "@docusaurus/core": "2.0.0-beta.19",
22
+ "@docusaurus/mdx-loader": "2.0.0-beta.19",
23
+ "@docusaurus/utils": "2.0.0-beta.19",
24
+ "@docusaurus/utils-validation": "2.0.0-beta.19",
25
+ "fs-extra": "^10.1.0",
26
26
  "remark-admonitions": "^1.2.1",
27
- "tslib": "^2.3.1",
28
- "webpack": "^5.69.1"
27
+ "tslib": "^2.4.0",
28
+ "webpack": "^5.72.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@docusaurus/types": "2.0.0-beta.16"
31
+ "@docusaurus/types": "2.0.0-beta.19"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": "^16.8.4 || ^17.0.0",
@@ -37,5 +37,5 @@
37
37
  "engines": {
38
38
  "node": ">=14"
39
39
  },
40
- "gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
40
+ "gitHead": "a71e60a49cce93c1006ef10c41ac03187f057102"
41
41
  }
package/src/deps.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  declare module 'remark-admonitions' {
9
- type Options = Record<string, unknown>;
9
+ type Options = {[key: string]: unknown};
10
10
 
11
11
  const plugin: (options?: Options) => void;
12
12
  export = plugin;
@@ -20,8 +20,8 @@ const PageFrontMatterSchema = Joi.object<FrontMatter>({
20
20
  ...FrontMatterTOCHeadingLevels,
21
21
  });
22
22
 
23
- export function validatePageFrontMatter(
24
- frontMatter: Record<string, unknown>,
25
- ): FrontMatter {
23
+ export function validatePageFrontMatter(frontMatter: {
24
+ [key: string]: unknown;
25
+ }): FrontMatter {
26
26
  return validateFrontMatter(frontMatter, PageFrontMatterSchema);
27
27
  }
package/src/index.ts CHANGED
@@ -21,18 +21,16 @@ import {
21
21
  DEFAULT_PLUGIN_ID,
22
22
  parseMarkdownString,
23
23
  } from '@docusaurus/utils';
24
- import type {
25
- LoadContext,
26
- Plugin,
27
- OptionValidationContext,
28
- ValidationResult,
29
- } from '@docusaurus/types';
24
+ import type {LoadContext, Plugin} from '@docusaurus/types';
30
25
  import admonitions from 'remark-admonitions';
31
- import {PluginOptionSchema} from './pluginOptionSchema';
32
- import {validatePageFrontMatter} from './pageFrontMatter';
26
+ import {validatePageFrontMatter} from './frontMatter';
33
27
 
34
- import type {LoadedContent, PagesContentPaths} from './types';
35
- import type {PluginOptions, Metadata} from '@docusaurus/plugin-content-pages';
28
+ import type {PagesContentPaths} from './types';
29
+ import type {
30
+ PluginOptions,
31
+ Metadata,
32
+ LoadedContent,
33
+ } from '@docusaurus/plugin-content-pages';
36
34
 
37
35
  export function getContentPathList(contentPaths: PagesContentPaths): string[] {
38
36
  return [contentPaths.contentPathLocalized, contentPaths.contentPath];
@@ -47,7 +45,7 @@ export default async function pluginContentPages(
47
45
  ): Promise<Plugin<LoadedContent | null>> {
48
46
  if (options.admonitions) {
49
47
  options.remarkPlugins = options.remarkPlugins.concat([
50
- [admonitions, options.admonitions || {}],
48
+ [admonitions, options.admonitions],
51
49
  ]);
52
50
  }
53
51
  const {
@@ -77,7 +75,7 @@ export default async function pluginContentPages(
77
75
  name: 'docusaurus-plugin-content-pages',
78
76
 
79
77
  getPathsToWatch() {
80
- const {include = []} = options;
78
+ const {include} = options;
81
79
  return getContentPathList(contentPaths).flatMap((contentPath) =>
82
80
  include.map((pattern) => `${contentPath}/${pattern}`),
83
81
  );
@@ -176,7 +174,7 @@ export default async function pluginContentPages(
176
174
  );
177
175
  },
178
176
 
179
- configureWebpack(_config, isServer, {getJSLoader}) {
177
+ configureWebpack(config, isServer, {getJSLoader}) {
180
178
  const {
181
179
  rehypePlugins,
182
180
  remarkPlugins,
@@ -241,10 +239,4 @@ export default async function pluginContentPages(
241
239
  };
242
240
  }
243
241
 
244
- export function validateOptions({
245
- validate,
246
- options,
247
- }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
248
- const validatedOptions = validate(PluginOptionSchema, options);
249
- return validatedOptions;
250
- }
242
+ export {validateOptions} from './options';
@@ -18,5 +18,5 @@ export default function markdownLoader(
18
18
  // TODO provide additional md processing here? like interlinking pages?
19
19
  // fileString = linkify(fileString)
20
20
 
21
- return callback && callback(null, fileString);
21
+ return callback?.(null, fileString);
22
22
  }
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {PluginOptions} from '@docusaurus/plugin-content-pages';
8
+ import type {PluginOptions, Options} from '@docusaurus/plugin-content-pages';
9
9
  import {
10
10
  Joi,
11
11
  RemarkPluginsSchema,
@@ -13,6 +13,7 @@ import {
13
13
  AdmonitionsSchema,
14
14
  } from '@docusaurus/utils-validation';
15
15
  import {GlobExcludeDefault} from '@docusaurus/utils';
16
+ import type {OptionValidationContext} from '@docusaurus/types';
16
17
 
17
18
  export const DEFAULT_OPTIONS: PluginOptions = {
18
19
  path: 'src/pages', // Path to data on filesystem, relative to site dir.
@@ -27,7 +28,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
27
28
  admonitions: {},
28
29
  };
29
30
 
30
- export const PluginOptionSchema = Joi.object({
31
+ const PluginOptionSchema = Joi.object({
31
32
  path: Joi.string().default(DEFAULT_OPTIONS.path),
32
33
  routeBasePath: Joi.string().default(DEFAULT_OPTIONS.routeBasePath),
33
34
  include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
@@ -43,3 +44,11 @@ export const PluginOptionSchema = Joi.object({
43
44
  ),
44
45
  admonitions: AdmonitionsSchema.default(DEFAULT_OPTIONS.admonitions),
45
46
  });
47
+
48
+ export function validateOptions({
49
+ validate,
50
+ options,
51
+ }: OptionValidationContext<Options, PluginOptions>): PluginOptions {
52
+ const validatedOptions = validate(PluginOptionSchema, options);
53
+ return validatedOptions;
54
+ }
@@ -6,16 +6,17 @@
6
6
  */
7
7
 
8
8
  declare module '@docusaurus/plugin-content-pages' {
9
- import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
9
+ import type {MDXOptions} from '@docusaurus/mdx-loader';
10
+ import type {LoadContext, Plugin} from '@docusaurus/types';
10
11
 
11
- export type PluginOptions = RemarkAndRehypePluginOptions & {
12
+ export type PluginOptions = MDXOptions & {
12
13
  id?: string;
13
14
  path: string;
14
15
  routeBasePath: string;
15
16
  include: string[];
16
17
  exclude: string[];
17
18
  mdxPageComponent: string;
18
- admonitions: Record<string, unknown>;
19
+ admonitions: {[key: string]: unknown};
19
20
  };
20
21
 
21
22
  export type Options = Partial<PluginOptions>;
@@ -39,28 +40,30 @@ declare module '@docusaurus/plugin-content-pages' {
39
40
  type: 'mdx';
40
41
  permalink: string;
41
42
  source: string;
42
- frontMatter: FrontMatter & Record<string, unknown>;
43
+ frontMatter: FrontMatter & {[key: string]: unknown};
43
44
  title?: string;
44
45
  description?: string;
45
46
  };
46
47
 
47
48
  export type Metadata = JSXPageMetadata | MDXPageMetadata;
49
+
50
+ export type LoadedContent = Metadata[];
51
+
52
+ export default function pluginContentPages(
53
+ context: LoadContext,
54
+ options: PluginOptions,
55
+ ): Promise<Plugin<LoadedContent | null>>;
48
56
  }
49
57
 
50
58
  declare module '@theme/MDXPage' {
51
- import type {TOCItem} from '@docusaurus/types';
59
+ import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
52
60
  import type {
53
61
  MDXPageMetadata,
54
62
  FrontMatter,
55
63
  } from '@docusaurus/plugin-content-pages';
56
64
 
57
65
  export interface Props {
58
- readonly content: {
59
- readonly frontMatter: FrontMatter;
60
- readonly metadata: MDXPageMetadata;
61
- readonly toc: readonly TOCItem[];
62
- (): JSX.Element;
63
- };
66
+ readonly content: LoadedMDXContent<FrontMatter, MDXPageMetadata>;
64
67
  }
65
68
 
66
69
  export default function MDXPage(props: Props): JSX.Element;
package/src/types.ts CHANGED
@@ -5,10 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {Metadata} from '@docusaurus/plugin-content-pages';
9
-
10
- export type LoadedContent = Metadata[];
11
-
12
8
  export type PagesContentPaths = {
13
9
  contentPath: string;
14
10
  contentPathLocalized: string;
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
- import type { PluginOptions } from '@docusaurus/plugin-content-pages';
8
- import { Joi } from '@docusaurus/utils-validation';
9
- export declare const DEFAULT_OPTIONS: PluginOptions;
10
- export declare const PluginOptionSchema: Joi.ObjectSchema<any>;