@docusaurus/plugin-content-pages 2.4.1 → 3.0.0-beta.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.
@@ -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 type { FrontMatter } from '@docusaurus/plugin-content-pages';
7
+ import type { PageFrontMatter } from '@docusaurus/plugin-content-pages';
8
8
  export declare function validatePageFrontMatter(frontMatter: {
9
9
  [key: string]: unknown;
10
- }): FrontMatter;
10
+ }): PageFrontMatter;
@@ -9,12 +9,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validatePageFrontMatter = void 0;
10
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
11
  const PageFrontMatterSchema = utils_validation_1.Joi.object({
12
- title: utils_validation_1.Joi.string(),
13
- description: utils_validation_1.Joi.string(),
12
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
13
+ title: utils_validation_1.Joi.string().allow(''),
14
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
15
+ description: utils_validation_1.Joi.string().allow(''),
16
+ keywords: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string().required()),
17
+ image: utils_validation_1.URISchema,
14
18
  wrapperClassName: utils_validation_1.Joi.string(),
15
19
  hide_table_of_contents: utils_validation_1.Joi.boolean(),
16
20
  ...utils_validation_1.FrontMatterTOCHeadingLevels,
17
- });
21
+ }).concat(utils_validation_1.ContentVisibilitySchema);
18
22
  function validatePageFrontMatter(frontMatter) {
19
23
  return (0, utils_validation_1.validateFrontMatter)(frontMatter, PageFrontMatterSchema);
20
24
  }
package/lib/index.js CHANGED
@@ -45,7 +45,7 @@ function pluginContentPages(context, options) {
45
45
  cwd: contentPaths.contentPath,
46
46
  ignore: options.exclude,
47
47
  });
48
- async function toMetadata(relativeSource) {
48
+ async function processPageSourceFile(relativeSource) {
49
49
  // Lookup in localized folder in priority
50
50
  const contentPath = await (0, utils_1.getFolderContainingFile)(getContentPathList(contentPaths), relativeSource);
51
51
  const source = path_1.default.join(contentPath, relativeSource);
@@ -65,6 +65,10 @@ function pluginContentPages(context, options) {
65
65
  const content = await fs_extra_1.default.readFile(source, 'utf-8');
66
66
  const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = (0, utils_1.parseMarkdownString)(content);
67
67
  const frontMatter = (0, frontMatter_1.validatePageFrontMatter)(unsafeFrontMatter);
68
+ if ((0, utils_1.isDraft)({ frontMatter })) {
69
+ return undefined;
70
+ }
71
+ const unlisted = (0, utils_1.isUnlisted)({ frontMatter });
68
72
  return {
69
73
  type: 'mdx',
70
74
  permalink,
@@ -72,9 +76,18 @@ function pluginContentPages(context, options) {
72
76
  title: frontMatter.title ?? contentTitle,
73
77
  description: frontMatter.description ?? excerpt,
74
78
  frontMatter,
79
+ unlisted,
75
80
  };
76
81
  }
77
- return Promise.all(pagesFiles.map(toMetadata));
82
+ async function doProcessPageSourceFile(relativeSource) {
83
+ try {
84
+ return await processPageSourceFile(relativeSource);
85
+ }
86
+ catch (err) {
87
+ throw new Error(`Processing of page source file path=${relativeSource} failed.`, { cause: err });
88
+ }
89
+ }
90
+ return (await Promise.all(pagesFiles.map(doProcessPageSourceFile))).filter(Boolean);
78
91
  },
79
92
  async contentLoaded({ content, actions }) {
80
93
  if (!content) {
@@ -109,7 +122,7 @@ function pluginContentPages(context, options) {
109
122
  }
110
123
  }));
111
124
  },
112
- configureWebpack(config, isServer, { getJSLoader }) {
125
+ configureWebpack() {
113
126
  const { admonitions, rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
114
127
  const contentDirs = getContentPathList(contentPaths);
115
128
  return {
@@ -126,7 +139,6 @@ function pluginContentPages(context, options) {
126
139
  // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
127
140
  .map(utils_1.addTrailingPathSeparator),
128
141
  use: [
129
- getJSLoader({ isServer }),
130
142
  {
131
143
  loader: require.resolve('@docusaurus/mdx-loader'),
132
144
  options: {
@@ -144,6 +156,11 @@ function pluginContentPages(context, options) {
144
156
  const aliasedSource = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
145
157
  return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedSource)}.json`);
146
158
  },
159
+ // Assets allow to convert some relative images paths to
160
+ // require(...) calls
161
+ createAssets: ({ frontMatter, }) => ({
162
+ image: frontMatter.image,
163
+ }),
147
164
  markdownConfig: siteConfig.markdown,
148
165
  },
149
166
  },
package/lib/options.js CHANGED
@@ -23,7 +23,7 @@ exports.DEFAULT_OPTIONS = {
23
23
  };
24
24
  const PluginOptionSchema = utils_validation_1.Joi.object({
25
25
  path: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.path),
26
- routeBasePath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.routeBasePath),
26
+ routeBasePath: utils_validation_1.RouteBasePathSchema.default(exports.DEFAULT_OPTIONS.routeBasePath),
27
27
  include: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.include),
28
28
  exclude: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.exclude),
29
29
  mdxPageComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.mdxPageComponent),
package/lib/types.d.ts CHANGED
@@ -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
- export declare type PagesContentPaths = {
7
+ export type PagesContentPaths = {
8
8
  contentPath: string;
9
9
  contentPathLocalized: string;
10
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-pages",
3
- "version": "2.4.1",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "Pages plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-pages.d.ts",
@@ -18,21 +18,21 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "2.4.1",
22
- "@docusaurus/mdx-loader": "2.4.1",
23
- "@docusaurus/types": "2.4.1",
24
- "@docusaurus/utils": "2.4.1",
25
- "@docusaurus/utils-validation": "2.4.1",
26
- "fs-extra": "^10.1.0",
27
- "tslib": "^2.4.0",
28
- "webpack": "^5.73.0"
21
+ "@docusaurus/core": "3.0.0-beta.0",
22
+ "@docusaurus/mdx-loader": "3.0.0-beta.0",
23
+ "@docusaurus/types": "3.0.0-beta.0",
24
+ "@docusaurus/utils": "3.0.0-beta.0",
25
+ "@docusaurus/utils-validation": "3.0.0-beta.0",
26
+ "fs-extra": "^11.1.1",
27
+ "tslib": "^2.6.0",
28
+ "webpack": "^5.88.1"
29
29
  },
30
30
  "peerDependencies": {
31
- "react": "^16.8.4 || ^17.0.0",
32
- "react-dom": "^16.8.4 || ^17.0.0"
31
+ "react": "^18.0.0",
32
+ "react-dom": "^18.0.0"
33
33
  },
34
34
  "engines": {
35
35
  "node": ">=16.14"
36
36
  },
37
- "gitHead": "60e657d8ae5a4a9ed1c2d777f9defd882cc12681"
37
+ "gitHead": "27a1e90d9fff88af90ecad35bea16d4d7230482a"
38
38
  }
@@ -9,19 +9,25 @@ import {
9
9
  Joi,
10
10
  validateFrontMatter,
11
11
  FrontMatterTOCHeadingLevels,
12
+ ContentVisibilitySchema,
13
+ URISchema,
12
14
  } from '@docusaurus/utils-validation';
13
- import type {FrontMatter} from '@docusaurus/plugin-content-pages';
15
+ import type {PageFrontMatter} from '@docusaurus/plugin-content-pages';
14
16
 
15
- const PageFrontMatterSchema = Joi.object<FrontMatter>({
16
- title: Joi.string(),
17
- description: Joi.string(),
17
+ const PageFrontMatterSchema = Joi.object<PageFrontMatter>({
18
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
19
+ title: Joi.string().allow(''),
20
+ // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
21
+ description: Joi.string().allow(''),
22
+ keywords: Joi.array().items(Joi.string().required()),
23
+ image: URISchema,
18
24
  wrapperClassName: Joi.string(),
19
25
  hide_table_of_contents: Joi.boolean(),
20
26
  ...FrontMatterTOCHeadingLevels,
21
- });
27
+ }).concat(ContentVisibilitySchema);
22
28
 
23
29
  export function validatePageFrontMatter(frontMatter: {
24
30
  [key: string]: unknown;
25
- }): FrontMatter {
31
+ }): PageFrontMatter {
26
32
  return validateFrontMatter(frontMatter, PageFrontMatterSchema);
27
33
  }
package/src/index.ts CHANGED
@@ -20,6 +20,8 @@ import {
20
20
  normalizeUrl,
21
21
  DEFAULT_PLUGIN_ID,
22
22
  parseMarkdownString,
23
+ isUnlisted,
24
+ isDraft,
23
25
  } from '@docusaurus/utils';
24
26
  import {validatePageFrontMatter} from './frontMatter';
25
27
 
@@ -29,6 +31,7 @@ import type {
29
31
  PluginOptions,
30
32
  Metadata,
31
33
  LoadedContent,
34
+ PageFrontMatter,
32
35
  } from '@docusaurus/plugin-content-pages';
33
36
 
34
37
  export function getContentPathList(contentPaths: PagesContentPaths): string[] {
@@ -82,7 +85,9 @@ export default function pluginContentPages(
82
85
  ignore: options.exclude,
83
86
  });
84
87
 
85
- async function toMetadata(relativeSource: string): Promise<Metadata> {
88
+ async function processPageSourceFile(
89
+ relativeSource: string,
90
+ ): Promise<Metadata | undefined> {
86
91
  // Lookup in localized folder in priority
87
92
  const contentPath = await getFolderContainingFile(
88
93
  getContentPathList(contentPaths),
@@ -110,6 +115,12 @@ export default function pluginContentPages(
110
115
  excerpt,
111
116
  } = parseMarkdownString(content);
112
117
  const frontMatter = validatePageFrontMatter(unsafeFrontMatter);
118
+
119
+ if (isDraft({frontMatter})) {
120
+ return undefined;
121
+ }
122
+ const unlisted = isUnlisted({frontMatter});
123
+
113
124
  return {
114
125
  type: 'mdx',
115
126
  permalink,
@@ -117,10 +128,24 @@ export default function pluginContentPages(
117
128
  title: frontMatter.title ?? contentTitle,
118
129
  description: frontMatter.description ?? excerpt,
119
130
  frontMatter,
131
+ unlisted,
120
132
  };
121
133
  }
122
134
 
123
- return Promise.all(pagesFiles.map(toMetadata));
135
+ async function doProcessPageSourceFile(relativeSource: string) {
136
+ try {
137
+ return await processPageSourceFile(relativeSource);
138
+ } catch (err) {
139
+ throw new Error(
140
+ `Processing of page source file path=${relativeSource} failed.`,
141
+ {cause: err as Error},
142
+ );
143
+ }
144
+ }
145
+
146
+ return (
147
+ await Promise.all(pagesFiles.map(doProcessPageSourceFile))
148
+ ).filter(Boolean) as Metadata[];
124
149
  },
125
150
 
126
151
  async contentLoaded({content, actions}) {
@@ -162,7 +187,7 @@ export default function pluginContentPages(
162
187
  );
163
188
  },
164
189
 
165
- configureWebpack(config, isServer, {getJSLoader}) {
190
+ configureWebpack() {
166
191
  const {
167
192
  admonitions,
168
193
  rehypePlugins,
@@ -185,7 +210,6 @@ export default function pluginContentPages(
185
210
  // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
186
211
  .map(addTrailingPathSeparator),
187
212
  use: [
188
- getJSLoader({isServer}),
189
213
  {
190
214
  loader: require.resolve('@docusaurus/mdx-loader'),
191
215
  options: {
@@ -211,6 +235,15 @@ export default function pluginContentPages(
211
235
  `${docuHash(aliasedSource)}.json`,
212
236
  );
213
237
  },
238
+ // Assets allow to convert some relative images paths to
239
+ // require(...) calls
240
+ createAssets: ({
241
+ frontMatter,
242
+ }: {
243
+ frontMatter: PageFrontMatter;
244
+ }) => ({
245
+ image: frontMatter.image,
246
+ }),
214
247
  markdownConfig: siteConfig.markdown,
215
248
  },
216
249
  },
package/src/options.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  RemarkPluginsSchema,
11
11
  RehypePluginsSchema,
12
12
  AdmonitionsSchema,
13
+ RouteBasePathSchema,
13
14
  } from '@docusaurus/utils-validation';
14
15
  import {GlobExcludeDefault} from '@docusaurus/utils';
15
16
  import type {OptionValidationContext} from '@docusaurus/types';
@@ -30,7 +31,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
30
31
 
31
32
  const PluginOptionSchema = Joi.object<PluginOptions>({
32
33
  path: Joi.string().default(DEFAULT_OPTIONS.path),
33
- routeBasePath: Joi.string().default(DEFAULT_OPTIONS.routeBasePath),
34
+ routeBasePath: RouteBasePathSchema.default(DEFAULT_OPTIONS.routeBasePath),
34
35
  include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
35
36
  exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
36
37
  mdxPageComponent: Joi.string().default(DEFAULT_OPTIONS.mdxPageComponent),
@@ -9,6 +9,10 @@ declare module '@docusaurus/plugin-content-pages' {
9
9
  import type {MDXOptions} from '@docusaurus/mdx-loader';
10
10
  import type {LoadContext, Plugin} from '@docusaurus/types';
11
11
 
12
+ export type Assets = {
13
+ image?: string;
14
+ };
15
+
12
16
  export type PluginOptions = MDXOptions & {
13
17
  id?: string;
14
18
  path: string;
@@ -20,13 +24,17 @@ declare module '@docusaurus/plugin-content-pages' {
20
24
 
21
25
  export type Options = Partial<PluginOptions>;
22
26
 
23
- export type FrontMatter = {
27
+ export type PageFrontMatter = {
24
28
  readonly title?: string;
25
29
  readonly description?: string;
30
+ readonly image?: string;
31
+ readonly keywords?: string[];
26
32
  readonly wrapperClassName?: string;
27
33
  readonly hide_table_of_contents?: string;
28
34
  readonly toc_min_heading_level?: number;
29
35
  readonly toc_max_heading_level?: number;
36
+ readonly draft?: boolean;
37
+ readonly unlisted?: boolean;
30
38
  };
31
39
 
32
40
  export type JSXPageMetadata = {
@@ -39,9 +47,10 @@ declare module '@docusaurus/plugin-content-pages' {
39
47
  type: 'mdx';
40
48
  permalink: string;
41
49
  source: string;
42
- frontMatter: FrontMatter & {[key: string]: unknown};
50
+ frontMatter: PageFrontMatter & {[key: string]: unknown};
43
51
  title?: string;
44
52
  description?: string;
53
+ unlisted: boolean;
45
54
  };
46
55
 
47
56
  export type Metadata = JSXPageMetadata | MDXPageMetadata;
@@ -58,11 +67,16 @@ declare module '@theme/MDXPage' {
58
67
  import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
59
68
  import type {
60
69
  MDXPageMetadata,
61
- FrontMatter,
70
+ PageFrontMatter,
71
+ Assets,
62
72
  } from '@docusaurus/plugin-content-pages';
63
73
 
64
74
  export interface Props {
65
- readonly content: LoadedMDXContent<FrontMatter, MDXPageMetadata>;
75
+ readonly content: LoadedMDXContent<
76
+ PageFrontMatter,
77
+ MDXPageMetadata,
78
+ Assets
79
+ >;
66
80
  }
67
81
 
68
82
  export default function MDXPage(props: Props): JSX.Element;