@docusaurus/plugin-content-pages 0.0.0-4435 → 0.0.0-4440

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/index.js CHANGED
@@ -13,6 +13,7 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
14
  const remark_admonitions_1 = (0, tslib_1.__importDefault)(require("remark-admonitions"));
15
15
  const pluginOptionSchema_1 = require("./pluginOptionSchema");
16
+ const pageFrontMatter_1 = require("./pageFrontMatter");
16
17
  function getContentPathList(contentPaths) {
17
18
  return [contentPaths.contentPathLocalized, contentPaths.contentPath];
18
19
  }
@@ -54,6 +55,7 @@ async function pluginContentPages(context, options) {
54
55
  ignore: options.exclude,
55
56
  });
56
57
  async function toMetadata(relativeSource) {
58
+ var _a, _b;
57
59
  // Lookup in localized folder in priority
58
60
  const contentPath = await (0, utils_1.getFolderContainingFile)(getContentPathList(contentPaths), relativeSource);
59
61
  const source = path_1.default.join(contentPath, relativeSource);
@@ -64,11 +66,16 @@ async function pluginContentPages(context, options) {
64
66
  (0, utils_1.encodePath)((0, utils_1.fileToPath)(relativeSource)),
65
67
  ]);
66
68
  if (isMarkdownSource(relativeSource)) {
67
- // TODO: missing frontmatter validation/normalization here
69
+ const content = await fs_extra_1.default.readFile(source, 'utf-8');
70
+ const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = (0, utils_1.parseMarkdownString)(content);
71
+ const frontMatter = (0, pageFrontMatter_1.validatePageFrontMatter)(unsafeFrontMatter);
68
72
  return {
69
73
  type: 'mdx',
70
74
  permalink,
71
75
  source: aliasedSourcePath,
76
+ title: (_a = frontMatter.title) !== null && _a !== void 0 ? _a : contentTitle,
77
+ description: (_b = frontMatter.description) !== null && _b !== void 0 ? _b : excerpt,
78
+ frontMatter,
72
79
  };
73
80
  }
74
81
  else {
@@ -0,0 +1,8 @@
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 { FrontMatter } from '@docusaurus/plugin-content-pages';
8
+ export declare function validatePageFrontMatter(frontMatter: Record<string, unknown>): FrontMatter;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validatePageFrontMatter = void 0;
10
+ const utils_validation_1 = require("@docusaurus/utils-validation");
11
+ const PageFrontMatterSchema = utils_validation_1.Joi.object({
12
+ title: utils_validation_1.Joi.string(),
13
+ description: utils_validation_1.Joi.string(),
14
+ wrapperClassName: utils_validation_1.Joi.string(),
15
+ hide_table_of_contents: utils_validation_1.Joi.string(),
16
+ ...utils_validation_1.FrontMatterTOCHeadingLevels,
17
+ });
18
+ function validatePageFrontMatter(frontMatter) {
19
+ return (0, utils_validation_1.validateFrontMatter)(frontMatter, PageFrontMatterSchema);
20
+ }
21
+ exports.validatePageFrontMatter = validatePageFrontMatter;
package/lib/types.d.ts CHANGED
@@ -4,17 +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
- export declare type JSXPageMetadata = {
8
- type: 'jsx';
9
- permalink: string;
10
- source: string;
11
- };
12
- export declare type MDXPageMetadata = {
13
- type: 'mdx';
14
- permalink: string;
15
- source: string;
16
- };
17
- export declare type Metadata = JSXPageMetadata | MDXPageMetadata;
7
+ import type { Metadata } from '@docusaurus/plugin-content-pages';
18
8
  export declare type LoadedContent = Metadata[];
19
9
  export declare type PagesContentPaths = {
20
10
  contentPath: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-pages",
3
- "version": "0.0.0-4435",
3
+ "version": "0.0.0-4440",
4
4
  "description": "Pages plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-pages.d.ts",
@@ -18,10 +18,10 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "0.0.0-4435",
22
- "@docusaurus/mdx-loader": "0.0.0-4435",
23
- "@docusaurus/utils": "0.0.0-4435",
24
- "@docusaurus/utils-validation": "0.0.0-4435",
21
+ "@docusaurus/core": "0.0.0-4440",
22
+ "@docusaurus/mdx-loader": "0.0.0-4440",
23
+ "@docusaurus/utils": "0.0.0-4440",
24
+ "@docusaurus/utils-validation": "0.0.0-4440",
25
25
  "fs-extra": "^10.0.0",
26
26
  "globby": "^11.0.2",
27
27
  "remark-admonitions": "^1.2.1",
@@ -29,7 +29,7 @@
29
29
  "webpack": "^5.61.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@docusaurus/types": "0.0.0-4435"
32
+ "@docusaurus/types": "0.0.0-4440"
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": "41656dfd8207e4a9d80de20fa5d9591f197a12b6"
41
+ "gitHead": "d13aa3d3a63285610086e000cfb556fa66073368"
42
42
  }
package/src/index.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  createAbsoluteFilePathMatcher,
20
20
  normalizeUrl,
21
21
  DEFAULT_PLUGIN_ID,
22
+ parseMarkdownString,
22
23
  } from '@docusaurus/utils';
23
24
  import type {
24
25
  LoadContext,
@@ -30,9 +31,10 @@ import type {
30
31
  import type {Configuration} from 'webpack';
31
32
  import admonitions from 'remark-admonitions';
32
33
  import {PluginOptionSchema} from './pluginOptionSchema';
34
+ import {validatePageFrontMatter} from './pageFrontMatter';
33
35
 
34
- import type {LoadedContent, Metadata, PagesContentPaths} from './types';
35
- import type {PluginOptions} from '@docusaurus/plugin-content-pages';
36
+ import type {LoadedContent, PagesContentPaths} from './types';
37
+ import type {PluginOptions, Metadata} from '@docusaurus/plugin-content-pages';
36
38
 
37
39
  export function getContentPathList(contentPaths: PagesContentPaths): string[] {
38
40
  return [contentPaths.contentPathLocalized, contentPaths.contentPath];
@@ -111,11 +113,20 @@ export default async function pluginContentPages(
111
113
  encodePath(fileToPath(relativeSource)),
112
114
  ]);
113
115
  if (isMarkdownSource(relativeSource)) {
114
- // TODO: missing frontmatter validation/normalization here
116
+ const content = await fs.readFile(source, 'utf-8');
117
+ const {
118
+ frontMatter: unsafeFrontMatter,
119
+ contentTitle,
120
+ excerpt,
121
+ } = parseMarkdownString(content);
122
+ const frontMatter = validatePageFrontMatter(unsafeFrontMatter);
115
123
  return {
116
124
  type: 'mdx',
117
125
  permalink,
118
126
  source: aliasedSourcePath,
127
+ title: frontMatter.title ?? contentTitle,
128
+ description: frontMatter.description ?? excerpt,
129
+ frontMatter,
119
130
  };
120
131
  } else {
121
132
  return {
@@ -0,0 +1,27 @@
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
+
8
+ import {
9
+ Joi,
10
+ validateFrontMatter,
11
+ FrontMatterTOCHeadingLevels,
12
+ } from '@docusaurus/utils-validation';
13
+ import type {FrontMatter} from '@docusaurus/plugin-content-pages';
14
+
15
+ const PageFrontMatterSchema = Joi.object<FrontMatter>({
16
+ title: Joi.string(),
17
+ description: Joi.string(),
18
+ wrapperClassName: Joi.string(),
19
+ hide_table_of_contents: Joi.string(),
20
+ ...FrontMatterTOCHeadingLevels,
21
+ });
22
+
23
+ export function validatePageFrontMatter(
24
+ frontMatter: Record<string, unknown>,
25
+ ): FrontMatter {
26
+ return validateFrontMatter(frontMatter, PageFrontMatterSchema);
27
+ }
@@ -19,22 +19,45 @@ declare module '@docusaurus/plugin-content-pages' {
19
19
  };
20
20
 
21
21
  export type Options = Partial<PluginOptions>;
22
+
23
+ export type FrontMatter = {
24
+ readonly title?: string;
25
+ readonly description?: string;
26
+ readonly wrapperClassName?: string;
27
+ readonly hide_table_of_contents?: string;
28
+ readonly toc_min_heading_level?: number;
29
+ readonly toc_max_heading_level?: number;
30
+ };
31
+
32
+ export type JSXPageMetadata = {
33
+ type: 'jsx';
34
+ permalink: string;
35
+ source: string;
36
+ };
37
+
38
+ export type MDXPageMetadata = {
39
+ type: 'mdx';
40
+ permalink: string;
41
+ source: string;
42
+ frontMatter: FrontMatter & Record<string, unknown>;
43
+ title?: string;
44
+ description?: string;
45
+ };
46
+
47
+ export type Metadata = JSXPageMetadata | MDXPageMetadata;
22
48
  }
23
49
 
24
50
  declare module '@theme/MDXPage' {
25
51
  import type {TOCItem} from '@docusaurus/types';
52
+ import type {
53
+ MDXPageMetadata,
54
+ FrontMatter,
55
+ } from '@docusaurus/plugin-content-pages';
26
56
 
27
57
  export interface Props {
28
58
  readonly content: {
29
- readonly frontMatter: {
30
- readonly title: string;
31
- readonly description: string;
32
- readonly wrapperClassName?: string;
33
- readonly hide_table_of_contents?: string;
34
- readonly toc_min_heading_level?: number;
35
- readonly toc_max_heading_level?: number;
36
- };
37
- readonly metadata: {readonly permalink: string};
59
+ readonly frontMatter: FrontMatter;
60
+ readonly metadata: MDXPageMetadata;
38
61
  readonly toc: readonly TOCItem[];
39
62
  (): JSX.Element;
40
63
  };
package/src/types.ts CHANGED
@@ -5,19 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- export type JSXPageMetadata = {
9
- type: 'jsx';
10
- permalink: string;
11
- source: string;
12
- };
13
-
14
- export type MDXPageMetadata = {
15
- type: 'mdx';
16
- permalink: string;
17
- source: string;
18
- };
19
-
20
- export type Metadata = JSXPageMetadata | MDXPageMetadata;
8
+ import type {Metadata} from '@docusaurus/plugin-content-pages';
21
9
 
22
10
  export type LoadedContent = Metadata[];
23
11