@docusaurus/plugin-content-pages 2.0.0-beta.fc64c12e4 → 2.0.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.
Files changed (37) hide show
  1. package/{src/__tests__/__fixtures__/website/i18n/fr/docusaurus-plugin-content-pages/hello/translatedJs.js → lib/frontMatter.d.ts} +4 -8
  2. package/lib/frontMatter.js +21 -0
  3. package/lib/index.d.ts +4 -3
  4. package/lib/index.js +38 -47
  5. package/lib/markdownLoader.d.ts +2 -6
  6. package/lib/markdownLoader.js +4 -4
  7. package/lib/options.d.ts +10 -0
  8. package/lib/{pluginOptionSchema.js → options.js} +14 -3
  9. package/lib/types.d.ts +0 -22
  10. package/package.json +14 -13
  11. package/src/frontMatter.ts +27 -0
  12. package/src/index.ts +40 -60
  13. package/src/markdownLoader.ts +8 -11
  14. package/src/{pluginOptionSchema.ts → options.ts} +13 -3
  15. package/src/plugin-content-pages.d.ts +59 -18
  16. package/src/types.ts +0 -28
  17. package/lib/.tsbuildinfo +0 -1
  18. package/lib/pluginOptionSchema.d.ts +0 -10
  19. package/src/__tests__/__fixtures__/website/docusaurus.config.js +0 -14
  20. package/src/__tests__/__fixtures__/website/i18n/fr/docusaurus-plugin-content-pages/hello/translatedMd.md +0 -1
  21. package/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.js +0 -1
  22. package/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.md +0 -1
  23. package/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.mdx +0 -1
  24. package/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.tsx +0 -1
  25. package/src/__tests__/__fixtures__/website/src/pages/hello/_partials/partial.mdx +0 -1
  26. package/src/__tests__/__fixtures__/website/src/pages/hello/_partials/subfolder/partial.mdx +0 -1
  27. package/src/__tests__/__fixtures__/website/src/pages/hello/index.md +0 -2
  28. package/src/__tests__/__fixtures__/website/src/pages/hello/mdxPage.mdx +0 -5
  29. package/src/__tests__/__fixtures__/website/src/pages/hello/translatedJs.js +0 -14
  30. package/src/__tests__/__fixtures__/website/src/pages/hello/translatedMd.md +0 -1
  31. package/src/__tests__/__fixtures__/website/src/pages/hello/world.js +0 -22
  32. package/src/__tests__/__fixtures__/website/src/pages/index.js +0 -23
  33. package/src/__tests__/__fixtures__/website/src/pages/typescript.tsx +0 -22
  34. package/src/__tests__/index.test.ts +0 -139
  35. package/src/__tests__/pluginOptionSchema.test.ts +0 -54
  36. package/tsconfig.json +0 -9
  37. package/types.d.ts +0 -13
@@ -4,11 +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
-
8
- import React from 'react';
9
-
10
- export default class TranslatedJs extends React.Component {
11
- render() {
12
- return <div>TranslatedJsPage (fr)</div>;
13
- }
14
- }
7
+ import type { FrontMatter } from '@docusaurus/plugin-content-pages';
8
+ export declare function validatePageFrontMatter(frontMatter: {
9
+ [key: string]: unknown;
10
+ }): 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.boolean(),
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/index.d.ts CHANGED
@@ -4,8 +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 { LoadContext, Plugin, OptionValidationContext, ValidationResult } from '@docusaurus/types';
8
- import { PluginOptions, LoadedContent, PagesContentPaths } from './types';
7
+ import type { LoadContext, Plugin } from '@docusaurus/types';
8
+ import type { PagesContentPaths } from './types';
9
+ import type { PluginOptions, LoadedContent } from '@docusaurus/plugin-content-pages';
9
10
  export declare function getContentPathList(contentPaths: PagesContentPaths): string[];
10
11
  export default function pluginContentPages(context: LoadContext, options: PluginOptions): Plugin<LoadedContent | null>;
11
- export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions>;
12
+ export { validateOptions } from './options';
package/lib/index.js CHANGED
@@ -8,79 +8,71 @@
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_1 = tslib_1.__importDefault(require("fs"));
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
- const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
15
- const pluginOptionSchema_1 = require("./pluginOptionSchema");
16
- const constants_1 = require("@docusaurus/core/lib/constants");
17
- const lodash_1 = require("lodash");
14
+ const frontMatter_1 = require("./frontMatter");
18
15
  function getContentPathList(contentPaths) {
19
16
  return [contentPaths.contentPathLocalized, contentPaths.contentPath];
20
17
  }
21
18
  exports.getContentPathList = getContentPathList;
22
19
  const isMarkdownSource = (source) => source.endsWith('.md') || source.endsWith('.mdx');
23
20
  function pluginContentPages(context, options) {
24
- var _a;
25
- if (options.admonitions) {
26
- options.remarkPlugins = options.remarkPlugins.concat([
27
- [remark_admonitions_1.default, options.admonitions || {}],
28
- ]);
29
- }
30
- const { siteConfig, siteDir, generatedFilesDir, i18n: { currentLocale }, } = context;
21
+ const { siteConfig, siteDir, generatedFilesDir, localizationDir } = context;
31
22
  const contentPaths = {
32
23
  contentPath: path_1.default.resolve(siteDir, options.path),
33
- contentPathLocalized: utils_1.getPluginI18nPath({
34
- siteDir,
35
- locale: currentLocale,
24
+ contentPathLocalized: (0, utils_1.getPluginI18nPath)({
25
+ localizationDir,
36
26
  pluginName: 'docusaurus-plugin-content-pages',
37
27
  pluginId: options.id,
38
28
  }),
39
29
  };
40
30
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-pages');
41
- const dataDir = path_1.default.join(pluginDataDirRoot, (_a = options.id) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PLUGIN_ID);
31
+ const dataDir = path_1.default.join(pluginDataDirRoot, options.id ?? utils_1.DEFAULT_PLUGIN_ID);
42
32
  return {
43
33
  name: 'docusaurus-plugin-content-pages',
44
34
  getPathsToWatch() {
45
- const { include = [] } = options;
46
- return lodash_1.flatten(getContentPathList(contentPaths).map((contentPath) => {
47
- return include.map((pattern) => `${contentPath}/${pattern}`);
48
- }));
35
+ const { include } = options;
36
+ return getContentPathList(contentPaths).flatMap((contentPath) => include.map((pattern) => `${contentPath}/${pattern}`));
49
37
  },
50
38
  async loadContent() {
51
39
  const { include } = options;
52
- if (!fs_1.default.existsSync(contentPaths.contentPath)) {
40
+ if (!(await fs_extra_1.default.pathExists(contentPaths.contentPath))) {
53
41
  return null;
54
42
  }
55
43
  const { baseUrl } = siteConfig;
56
- const pagesFiles = await utils_1.Globby(include, {
44
+ const pagesFiles = await (0, utils_1.Globby)(include, {
57
45
  cwd: contentPaths.contentPath,
58
46
  ignore: options.exclude,
59
47
  });
60
48
  async function toMetadata(relativeSource) {
61
49
  // Lookup in localized folder in priority
62
- const contentPath = await utils_1.getFolderContainingFile(getContentPathList(contentPaths), relativeSource);
50
+ const contentPath = await (0, utils_1.getFolderContainingFile)(getContentPathList(contentPaths), relativeSource);
63
51
  const source = path_1.default.join(contentPath, relativeSource);
64
- const aliasedSourcePath = utils_1.aliasedSitePath(source, siteDir);
65
- const permalink = utils_1.normalizeUrl([
52
+ const aliasedSourcePath = (0, utils_1.aliasedSitePath)(source, siteDir);
53
+ const permalink = (0, utils_1.normalizeUrl)([
66
54
  baseUrl,
67
55
  options.routeBasePath,
68
- utils_1.encodePath(utils_1.fileToPath(relativeSource)),
56
+ (0, utils_1.encodePath)((0, utils_1.fileToPath)(relativeSource)),
69
57
  ]);
70
- if (isMarkdownSource(relativeSource)) {
71
- return {
72
- type: 'mdx',
73
- permalink,
74
- source: aliasedSourcePath,
75
- };
76
- }
77
- else {
58
+ if (!isMarkdownSource(relativeSource)) {
78
59
  return {
79
60
  type: 'jsx',
80
61
  permalink,
81
62
  source: aliasedSourcePath,
82
63
  };
83
64
  }
65
+ const content = await fs_extra_1.default.readFile(source, 'utf-8');
66
+ const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = (0, utils_1.parseMarkdownString)(content);
67
+ const frontMatter = (0, frontMatter_1.validatePageFrontMatter)(unsafeFrontMatter);
68
+ return {
69
+ type: 'mdx',
70
+ permalink,
71
+ source: aliasedSourcePath,
72
+ title: frontMatter.title ?? contentTitle,
73
+ description: frontMatter.description ?? excerpt,
74
+ frontMatter,
75
+ };
84
76
  }
85
77
  return Promise.all(pagesFiles.map(toMetadata));
86
78
  },
@@ -95,7 +87,7 @@ function pluginContentPages(context, options) {
95
87
  await createData(
96
88
  // Note that this created data path must be in sync with
97
89
  // metadataPath provided to mdx-loader.
98
- `${utils_1.docuHash(metadata.source)}.json`, JSON.stringify(metadata, null, 2));
90
+ `${(0, utils_1.docuHash)(metadata.source)}.json`, JSON.stringify(metadata, null, 2));
99
91
  addRoute({
100
92
  path: permalink,
101
93
  component: options.mdxPageComponent,
@@ -117,8 +109,8 @@ function pluginContentPages(context, options) {
117
109
  }
118
110
  }));
119
111
  },
120
- configureWebpack(_config, isServer, { getJSLoader }) {
121
- const { rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
112
+ configureWebpack(config, isServer, { getJSLoader }) {
113
+ const { admonitions, rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
122
114
  const contentDirs = getContentPathList(contentPaths);
123
115
  return {
124
116
  resolve: {
@@ -129,7 +121,7 @@ function pluginContentPages(context, options) {
129
121
  module: {
130
122
  rules: [
131
123
  {
132
- test: /(\.mdx?)$/,
124
+ test: /\.mdx?$/i,
133
125
  include: contentDirs
134
126
  // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
135
127
  .map(utils_1.addTrailingPathSeparator),
@@ -138,17 +130,19 @@ function pluginContentPages(context, options) {
138
130
  {
139
131
  loader: require.resolve('@docusaurus/mdx-loader'),
140
132
  options: {
133
+ admonitions,
141
134
  remarkPlugins,
142
135
  rehypePlugins,
143
136
  beforeDefaultRehypePlugins,
144
137
  beforeDefaultRemarkPlugins,
145
- staticDir: path_1.default.join(siteDir, constants_1.STATIC_DIR_NAME),
146
- isMDXPartial: utils_1.createAbsoluteFilePathMatcher(options.exclude, contentDirs),
138
+ staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
139
+ siteDir,
140
+ isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
147
141
  metadataPath: (mdxPath) => {
148
142
  // Note that metadataPath must be the same/in-sync as
149
143
  // the path from createData for each MDX.
150
- const aliasedSource = utils_1.aliasedSitePath(mdxPath, siteDir);
151
- return path_1.default.join(dataDir, `${utils_1.docuHash(aliasedSource)}.json`);
144
+ const aliasedSource = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
145
+ return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedSource)}.json`);
152
146
  },
153
147
  },
154
148
  },
@@ -168,8 +162,5 @@ function pluginContentPages(context, options) {
168
162
  };
169
163
  }
170
164
  exports.default = pluginContentPages;
171
- function validateOptions({ validate, options, }) {
172
- const validatedOptions = validate(pluginOptionSchema_1.PluginOptionSchema, options);
173
- return validatedOptions;
174
- }
175
- exports.validateOptions = validateOptions;
165
+ var options_1 = require("./options");
166
+ Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
@@ -4,9 +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
- /// <reference types="node" />
8
- interface Loader extends Function {
9
- (this: any, source: string): string | Buffer | void | undefined;
10
- }
11
- declare const markdownLoader: Loader;
12
- export default markdownLoader;
7
+ import type { LoaderContext } from 'webpack';
8
+ export default function markdownLoader(this: LoaderContext<undefined>, fileString: string): void;
@@ -6,11 +6,11 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- const markdownLoader = function (fileString) {
9
+ function markdownLoader(fileString) {
10
10
  const callback = this.async();
11
11
  // const options = this.getOptions();
12
- // TODO provide additinal md processing here? like interlinking pages?
12
+ // TODO provide additional md processing here? like interlinking pages?
13
13
  // fileString = linkify(fileString)
14
- return callback && callback(null, fileString);
15
- };
14
+ return callback(null, fileString);
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 { OptionValidationContext } from '@docusaurus/types';
8
+ import type { PluginOptions, Options } from '@docusaurus/plugin-content-pages';
9
+ export declare const DEFAULT_OPTIONS: PluginOptions;
10
+ export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
@@ -1,6 +1,12 @@
1
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
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginOptionSchema = exports.DEFAULT_OPTIONS = void 0;
9
+ exports.validateOptions = exports.DEFAULT_OPTIONS = void 0;
4
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
5
11
  const utils_1 = require("@docusaurus/utils");
6
12
  exports.DEFAULT_OPTIONS = {
@@ -13,9 +19,9 @@ exports.DEFAULT_OPTIONS = {
13
19
  rehypePlugins: [],
14
20
  beforeDefaultRehypePlugins: [],
15
21
  beforeDefaultRemarkPlugins: [],
16
- admonitions: {},
22
+ admonitions: true,
17
23
  };
18
- exports.PluginOptionSchema = utils_validation_1.Joi.object({
24
+ const PluginOptionSchema = utils_validation_1.Joi.object({
19
25
  path: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.path),
20
26
  routeBasePath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.routeBasePath),
21
27
  include: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.include),
@@ -27,3 +33,8 @@ exports.PluginOptionSchema = utils_validation_1.Joi.object({
27
33
  beforeDefaultRemarkPlugins: utils_validation_1.RemarkPluginsSchema.default(exports.DEFAULT_OPTIONS.beforeDefaultRemarkPlugins),
28
34
  admonitions: utils_validation_1.AdmonitionsSchema.default(exports.DEFAULT_OPTIONS.admonitions),
29
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,28 +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 { RemarkAndRehypePluginOptions } from '@docusaurus/mdx-loader';
8
- export interface PluginOptions extends RemarkAndRehypePluginOptions {
9
- id?: string;
10
- path: string;
11
- routeBasePath: string;
12
- include: string[];
13
- exclude: string[];
14
- mdxPageComponent: string;
15
- admonitions: Record<string, unknown>;
16
- }
17
- export declare type JSXPageMetadata = {
18
- type: 'jsx';
19
- permalink: string;
20
- source: string;
21
- };
22
- export declare type MDXPageMetadata = {
23
- type: 'mdx';
24
- permalink: string;
25
- source: string;
26
- };
27
- export declare type Metadata = JSXPageMetadata | MDXPageMetadata;
28
- export declare type LoadedContent = Metadata[];
29
7
  export declare type PagesContentPaths = {
30
8
  contentPath: string;
31
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.fc64c12e4",
3
+ "version": "2.0.0",
4
4
  "description": "Pages plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-pages.d.ts",
@@ -18,23 +18,24 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "2.0.0-beta.fc64c12e4",
22
- "@docusaurus/mdx-loader": "2.0.0-beta.fc64c12e4",
23
- "@docusaurus/types": "2.0.0-beta.fc64c12e4",
24
- "@docusaurus/utils": "2.0.0-beta.fc64c12e4",
25
- "@docusaurus/utils-validation": "2.0.0-beta.fc64c12e4",
26
- "globby": "^11.0.2",
27
- "lodash": "^4.17.20",
28
- "remark-admonitions": "^1.2.1",
29
- "tslib": "^2.1.0",
30
- "webpack": "^5.40.0"
21
+ "@docusaurus/core": "2.0.0",
22
+ "@docusaurus/mdx-loader": "2.0.0",
23
+ "@docusaurus/types": "2.0.0",
24
+ "@docusaurus/utils": "2.0.0",
25
+ "@docusaurus/utils-validation": "2.0.0",
26
+ "fs-extra": "^10.1.0",
27
+ "tslib": "^2.4.0",
28
+ "webpack": "^5.73.0"
29
+ },
30
+ "devDependencies": {
31
+ "@docusaurus/types": "2.0.0-beta.21"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "react": "^16.8.4 || ^17.0.0",
34
35
  "react-dom": "^16.8.4 || ^17.0.0"
35
36
  },
36
37
  "engines": {
37
- "node": ">=12.13.0"
38
+ "node": ">=16.14"
38
39
  },
39
- "gitHead": "830d9e29a94866f19318e19565b9e177af06b964"
40
+ "gitHead": "2a9e8f5ec807e49a973fc72326f1ef26092e977e"
40
41
  }
@@ -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.boolean(),
20
+ ...FrontMatterTOCHeadingLevels,
21
+ });
22
+
23
+ export function validatePageFrontMatter(frontMatter: {
24
+ [key: string]: unknown;
25
+ }): FrontMatter {
26
+ return validateFrontMatter(frontMatter, PageFrontMatterSchema);
27
+ }
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import fs from 'fs';
8
+ import fs from 'fs-extra';
9
9
  import path from 'path';
10
10
  import {
11
11
  encodePath,
@@ -18,29 +18,18 @@ import {
18
18
  Globby,
19
19
  createAbsoluteFilePathMatcher,
20
20
  normalizeUrl,
21
- } from '@docusaurus/utils';
22
- import {
23
- LoadContext,
24
- Plugin,
25
- OptionValidationContext,
26
- ValidationResult,
27
- ConfigureWebpackUtils,
28
- } from '@docusaurus/types';
29
- import {Configuration} from 'webpack';
30
- import admonitions from 'remark-admonitions';
31
- import {PluginOptionSchema} from './pluginOptionSchema';
32
- import {
33
21
  DEFAULT_PLUGIN_ID,
34
- STATIC_DIR_NAME,
35
- } from '@docusaurus/core/lib/constants';
22
+ parseMarkdownString,
23
+ } from '@docusaurus/utils';
24
+ import {validatePageFrontMatter} from './frontMatter';
36
25
 
37
- import {
26
+ import type {LoadContext, Plugin} from '@docusaurus/types';
27
+ import type {PagesContentPaths} from './types';
28
+ import type {
38
29
  PluginOptions,
39
- LoadedContent,
40
30
  Metadata,
41
- PagesContentPaths,
42
- } from './types';
43
- import {flatten} from 'lodash';
31
+ LoadedContent,
32
+ } from '@docusaurus/plugin-content-pages';
44
33
 
45
34
  export function getContentPathList(contentPaths: PagesContentPaths): string[] {
46
35
  return [contentPaths.contentPathLocalized, contentPaths.contentPath];
@@ -53,23 +42,12 @@ export default function pluginContentPages(
53
42
  context: LoadContext,
54
43
  options: PluginOptions,
55
44
  ): Plugin<LoadedContent | null> {
56
- if (options.admonitions) {
57
- options.remarkPlugins = options.remarkPlugins.concat([
58
- [admonitions, options.admonitions || {}],
59
- ]);
60
- }
61
- const {
62
- siteConfig,
63
- siteDir,
64
- generatedFilesDir,
65
- i18n: {currentLocale},
66
- } = context;
45
+ const {siteConfig, siteDir, generatedFilesDir, localizationDir} = context;
67
46
 
68
47
  const contentPaths: PagesContentPaths = {
69
48
  contentPath: path.resolve(siteDir, options.path),
70
49
  contentPathLocalized: getPluginI18nPath({
71
- siteDir,
72
- locale: currentLocale,
50
+ localizationDir,
73
51
  pluginName: 'docusaurus-plugin-content-pages',
74
52
  pluginId: options.id,
75
53
  }),
@@ -85,18 +63,16 @@ export default function pluginContentPages(
85
63
  name: 'docusaurus-plugin-content-pages',
86
64
 
87
65
  getPathsToWatch() {
88
- const {include = []} = options;
89
- return flatten(
90
- getContentPathList(contentPaths).map((contentPath) => {
91
- return include.map((pattern) => `${contentPath}/${pattern}`);
92
- }),
66
+ const {include} = options;
67
+ return getContentPathList(contentPaths).flatMap((contentPath) =>
68
+ include.map((pattern) => `${contentPath}/${pattern}`),
93
69
  );
94
70
  },
95
71
 
96
72
  async loadContent() {
97
73
  const {include} = options;
98
74
 
99
- if (!fs.existsSync(contentPaths.contentPath)) {
75
+ if (!(await fs.pathExists(contentPaths.contentPath))) {
100
76
  return null;
101
77
  }
102
78
 
@@ -120,19 +96,28 @@ export default function pluginContentPages(
120
96
  options.routeBasePath,
121
97
  encodePath(fileToPath(relativeSource)),
122
98
  ]);
123
- if (isMarkdownSource(relativeSource)) {
124
- return {
125
- type: 'mdx',
126
- permalink,
127
- source: aliasedSourcePath,
128
- };
129
- } else {
99
+ if (!isMarkdownSource(relativeSource)) {
130
100
  return {
131
101
  type: 'jsx',
132
102
  permalink,
133
103
  source: aliasedSourcePath,
134
104
  };
135
105
  }
106
+ const content = await fs.readFile(source, 'utf-8');
107
+ const {
108
+ frontMatter: unsafeFrontMatter,
109
+ contentTitle,
110
+ excerpt,
111
+ } = parseMarkdownString(content);
112
+ const frontMatter = validatePageFrontMatter(unsafeFrontMatter);
113
+ return {
114
+ type: 'mdx',
115
+ permalink,
116
+ source: aliasedSourcePath,
117
+ title: frontMatter.title ?? contentTitle,
118
+ description: frontMatter.description ?? excerpt,
119
+ frontMatter,
120
+ };
136
121
  }
137
122
 
138
123
  return Promise.all(pagesFiles.map(toMetadata));
@@ -177,12 +162,9 @@ export default function pluginContentPages(
177
162
  );
178
163
  },
179
164
 
180
- configureWebpack(
181
- _config: Configuration,
182
- isServer: boolean,
183
- {getJSLoader}: ConfigureWebpackUtils,
184
- ) {
165
+ configureWebpack(config, isServer, {getJSLoader}) {
185
166
  const {
167
+ admonitions,
186
168
  rehypePlugins,
187
169
  remarkPlugins,
188
170
  beforeDefaultRehypePlugins,
@@ -198,7 +180,7 @@ export default function pluginContentPages(
198
180
  module: {
199
181
  rules: [
200
182
  {
201
- test: /(\.mdx?)$/,
183
+ test: /\.mdx?$/i,
202
184
  include: contentDirs
203
185
  // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
204
186
  .map(addTrailingPathSeparator),
@@ -207,11 +189,15 @@ export default function pluginContentPages(
207
189
  {
208
190
  loader: require.resolve('@docusaurus/mdx-loader'),
209
191
  options: {
192
+ admonitions,
210
193
  remarkPlugins,
211
194
  rehypePlugins,
212
195
  beforeDefaultRehypePlugins,
213
196
  beforeDefaultRemarkPlugins,
214
- staticDir: path.join(siteDir, STATIC_DIR_NAME),
197
+ staticDirs: siteConfig.staticDirectories.map((dir) =>
198
+ path.resolve(siteDir, dir),
199
+ ),
200
+ siteDir,
215
201
  isMDXPartial: createAbsoluteFilePathMatcher(
216
202
  options.exclude,
217
203
  contentDirs,
@@ -243,10 +229,4 @@ export default function pluginContentPages(
243
229
  };
244
230
  }
245
231
 
246
- export function validateOptions({
247
- validate,
248
- options,
249
- }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
250
- const validatedOptions = validate(PluginOptionSchema, options);
251
- return validatedOptions;
252
- }
232
+ export {validateOptions} from './options';
@@ -5,21 +5,18 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- // TODO temporary until Webpack5 export this type
9
- // see https://github.com/webpack/webpack/issues/11630
10
- interface Loader extends Function {
11
- (this: any, source: string): string | Buffer | void | undefined;
12
- }
8
+ import type {LoaderContext} from 'webpack';
13
9
 
14
- const markdownLoader: Loader = function (fileString) {
10
+ export default function markdownLoader(
11
+ this: LoaderContext<undefined>,
12
+ fileString: string,
13
+ ): void {
15
14
  const callback = this.async();
16
15
 
17
16
  // const options = this.getOptions();
18
17
 
19
- // TODO provide additinal md processing here? like interlinking pages?
18
+ // TODO provide additional md processing here? like interlinking pages?
20
19
  // fileString = linkify(fileString)
21
20
 
22
- return callback && callback(null, fileString);
23
- };
24
-
25
- export default markdownLoader;
21
+ return callback(null, fileString);
22
+ }
@@ -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 {PluginOptions} from './types';
7
+
8
8
  import {
9
9
  Joi,
10
10
  RemarkPluginsSchema,
@@ -12,6 +12,8 @@ import {
12
12
  AdmonitionsSchema,
13
13
  } from '@docusaurus/utils-validation';
14
14
  import {GlobExcludeDefault} from '@docusaurus/utils';
15
+ import type {OptionValidationContext} from '@docusaurus/types';
16
+ import type {PluginOptions, Options} from '@docusaurus/plugin-content-pages';
15
17
 
16
18
  export const DEFAULT_OPTIONS: PluginOptions = {
17
19
  path: 'src/pages', // Path to data on filesystem, relative to site dir.
@@ -23,10 +25,10 @@ export const DEFAULT_OPTIONS: PluginOptions = {
23
25
  rehypePlugins: [],
24
26
  beforeDefaultRehypePlugins: [],
25
27
  beforeDefaultRemarkPlugins: [],
26
- admonitions: {},
28
+ admonitions: true,
27
29
  };
28
30
 
29
- export const PluginOptionSchema = Joi.object({
31
+ const PluginOptionSchema = Joi.object<PluginOptions>({
30
32
  path: Joi.string().default(DEFAULT_OPTIONS.path),
31
33
  routeBasePath: Joi.string().default(DEFAULT_OPTIONS.routeBasePath),
32
34
  include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
@@ -42,3 +44,11 @@ export const PluginOptionSchema = Joi.object({
42
44
  ),
43
45
  admonitions: AdmonitionsSchema.default(DEFAULT_OPTIONS.admonitions),
44
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
+ }