@docusaurus/plugin-content-pages 0.0.0-6058 → 0.0.0-6061

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.d.ts CHANGED
@@ -6,5 +6,5 @@
6
6
  */
7
7
  import type { LoadContext, Plugin } from '@docusaurus/types';
8
8
  import type { PluginOptions, LoadedContent } from '@docusaurus/plugin-content-pages';
9
- export default function pluginContentPages(context: LoadContext, options: PluginOptions): Plugin<LoadedContent | null>;
9
+ export default function pluginContentPages(context: LoadContext, options: PluginOptions): Promise<Plugin<LoadedContent | null>>;
10
10
  export { validateOptions } from './options';
package/lib/index.js CHANGED
@@ -12,13 +12,48 @@ const tslib_1 = require("tslib");
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
13
  const path_1 = tslib_1.__importDefault(require("path"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
+ const mdx_loader_1 = require("@docusaurus/mdx-loader");
15
16
  const routes_1 = require("./routes");
16
17
  const content_1 = require("./content");
17
- function pluginContentPages(context, options) {
18
+ async function pluginContentPages(context, options) {
18
19
  const { siteConfig, siteDir, generatedFilesDir } = context;
19
20
  const contentPaths = (0, content_1.createPagesContentPaths)({ context, options });
20
21
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-pages');
21
22
  const dataDir = path_1.default.join(pluginDataDirRoot, options.id ?? utils_1.DEFAULT_PLUGIN_ID);
23
+ async function createPagesMDXLoaderRule() {
24
+ const { admonitions, rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
25
+ const contentDirs = (0, content_1.getContentPathList)(contentPaths);
26
+ const loaderOptions = {
27
+ admonitions,
28
+ remarkPlugins,
29
+ rehypePlugins,
30
+ recmaPlugins,
31
+ beforeDefaultRehypePlugins,
32
+ beforeDefaultRemarkPlugins,
33
+ staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
34
+ siteDir,
35
+ isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
36
+ metadataPath: (mdxPath) => {
37
+ // Note that metadataPath must be the same/in-sync as
38
+ // the path from createData for each MDX.
39
+ const aliasedSource = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
40
+ return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedSource)}.json`);
41
+ },
42
+ // Assets allow to convert some relative images paths to
43
+ // require(...) calls
44
+ createAssets: ({ frontMatter }) => ({
45
+ image: frontMatter.image,
46
+ }),
47
+ markdownConfig: siteConfig.markdown,
48
+ };
49
+ return (0, mdx_loader_1.createMDXLoaderRule)({
50
+ include: contentDirs
51
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
52
+ .map(utils_1.addTrailingPathSeparator),
53
+ options: loaderOptions,
54
+ });
55
+ }
56
+ const pagesMDXLoaderRule = await createPagesMDXLoaderRule();
22
57
  return {
23
58
  name: 'docusaurus-plugin-content-pages',
24
59
  getPathsToWatch() {
@@ -38,48 +73,9 @@ function pluginContentPages(context, options) {
38
73
  await (0, routes_1.createAllRoutes)({ content, options, actions });
39
74
  },
40
75
  configureWebpack() {
41
- const { admonitions, rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
42
- const contentDirs = (0, content_1.getContentPathList)(contentPaths);
43
- function createMDXLoader() {
44
- const loaderOptions = {
45
- admonitions,
46
- remarkPlugins,
47
- rehypePlugins,
48
- recmaPlugins,
49
- beforeDefaultRehypePlugins,
50
- beforeDefaultRemarkPlugins,
51
- staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
52
- siteDir,
53
- isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
54
- metadataPath: (mdxPath) => {
55
- // Note that metadataPath must be the same/in-sync as
56
- // the path from createData for each MDX.
57
- const aliasedSource = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
58
- return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedSource)}.json`);
59
- },
60
- // Assets allow to convert some relative images paths to
61
- // require(...) calls
62
- createAssets: ({ frontMatter }) => ({
63
- image: frontMatter.image,
64
- }),
65
- markdownConfig: siteConfig.markdown,
66
- };
67
- return {
68
- loader: require.resolve('@docusaurus/mdx-loader'),
69
- options: loaderOptions,
70
- };
71
- }
72
76
  return {
73
77
  module: {
74
- rules: [
75
- {
76
- test: /\.mdx?$/i,
77
- include: contentDirs
78
- // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
79
- .map(utils_1.addTrailingPathSeparator),
80
- use: [createMDXLoader()],
81
- },
82
- ],
78
+ rules: [pagesMDXLoaderRule],
83
79
  },
84
80
  };
85
81
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-pages",
3
- "version": "0.0.0-6058",
3
+ "version": "0.0.0-6061",
4
4
  "description": "Pages plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-pages.d.ts",
@@ -18,11 +18,11 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "0.0.0-6058",
22
- "@docusaurus/mdx-loader": "0.0.0-6058",
23
- "@docusaurus/types": "0.0.0-6058",
24
- "@docusaurus/utils": "0.0.0-6058",
25
- "@docusaurus/utils-validation": "0.0.0-6058",
21
+ "@docusaurus/core": "0.0.0-6061",
22
+ "@docusaurus/mdx-loader": "0.0.0-6061",
23
+ "@docusaurus/types": "0.0.0-6061",
24
+ "@docusaurus/utils": "0.0.0-6061",
25
+ "@docusaurus/utils-validation": "0.0.0-6061",
26
26
  "fs-extra": "^11.1.1",
27
27
  "tslib": "^2.6.0",
28
28
  "webpack": "^5.88.1"
@@ -34,5 +34,5 @@
34
34
  "engines": {
35
35
  "node": ">=18.0"
36
36
  },
37
- "gitHead": "1108fcbe4d387e2e3d0195d91157a968275970b3"
37
+ "gitHead": "3e2c2a06f0d0400f0adf145fd24ba37776c65dbf"
38
38
  }
package/src/index.ts CHANGED
@@ -14,6 +14,10 @@ import {
14
14
  createAbsoluteFilePathMatcher,
15
15
  DEFAULT_PLUGIN_ID,
16
16
  } from '@docusaurus/utils';
17
+ import {
18
+ createMDXLoaderRule,
19
+ type Options as MDXLoaderOptions,
20
+ } from '@docusaurus/mdx-loader';
17
21
  import {createAllRoutes} from './routes';
18
22
  import {
19
23
  createPagesContentPaths,
@@ -26,13 +30,12 @@ import type {
26
30
  LoadedContent,
27
31
  PageFrontMatter,
28
32
  } from '@docusaurus/plugin-content-pages';
29
- import type {RuleSetUseItem} from 'webpack';
30
- import type {Options as MDXLoaderOptions} from '@docusaurus/mdx-loader/lib/loader';
33
+ import type {RuleSetRule} from 'webpack';
31
34
 
32
- export default function pluginContentPages(
35
+ export default async function pluginContentPages(
33
36
  context: LoadContext,
34
37
  options: PluginOptions,
35
- ): Plugin<LoadedContent | null> {
38
+ ): Promise<Plugin<LoadedContent | null>> {
36
39
  const {siteConfig, siteDir, generatedFilesDir} = context;
37
40
 
38
41
  const contentPaths = createPagesContentPaths({context, options});
@@ -43,6 +46,53 @@ export default function pluginContentPages(
43
46
  );
44
47
  const dataDir = path.join(pluginDataDirRoot, options.id ?? DEFAULT_PLUGIN_ID);
45
48
 
49
+ async function createPagesMDXLoaderRule(): Promise<RuleSetRule> {
50
+ const {
51
+ admonitions,
52
+ rehypePlugins,
53
+ remarkPlugins,
54
+ recmaPlugins,
55
+ beforeDefaultRehypePlugins,
56
+ beforeDefaultRemarkPlugins,
57
+ } = options;
58
+ const contentDirs = getContentPathList(contentPaths);
59
+
60
+ const loaderOptions: MDXLoaderOptions = {
61
+ admonitions,
62
+ remarkPlugins,
63
+ rehypePlugins,
64
+ recmaPlugins,
65
+ beforeDefaultRehypePlugins,
66
+ beforeDefaultRemarkPlugins,
67
+ staticDirs: siteConfig.staticDirectories.map((dir) =>
68
+ path.resolve(siteDir, dir),
69
+ ),
70
+ siteDir,
71
+ isMDXPartial: createAbsoluteFilePathMatcher(options.exclude, contentDirs),
72
+ metadataPath: (mdxPath: string) => {
73
+ // Note that metadataPath must be the same/in-sync as
74
+ // the path from createData for each MDX.
75
+ const aliasedSource = aliasedSitePath(mdxPath, siteDir);
76
+ return path.join(dataDir, `${docuHash(aliasedSource)}.json`);
77
+ },
78
+ // Assets allow to convert some relative images paths to
79
+ // require(...) calls
80
+ createAssets: ({frontMatter}: {frontMatter: PageFrontMatter}) => ({
81
+ image: frontMatter.image,
82
+ }),
83
+ markdownConfig: siteConfig.markdown,
84
+ };
85
+
86
+ return createMDXLoaderRule({
87
+ include: contentDirs
88
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
89
+ .map(addTrailingPathSeparator),
90
+ options: loaderOptions,
91
+ });
92
+ }
93
+
94
+ const pagesMDXLoaderRule = await createPagesMDXLoaderRule();
95
+
46
96
  return {
47
97
  name: 'docusaurus-plugin-content-pages',
48
98
 
@@ -68,63 +118,9 @@ export default function pluginContentPages(
68
118
  },
69
119
 
70
120
  configureWebpack() {
71
- const {
72
- admonitions,
73
- rehypePlugins,
74
- remarkPlugins,
75
- recmaPlugins,
76
- beforeDefaultRehypePlugins,
77
- beforeDefaultRemarkPlugins,
78
- } = options;
79
- const contentDirs = getContentPathList(contentPaths);
80
-
81
- function createMDXLoader(): RuleSetUseItem {
82
- const loaderOptions: MDXLoaderOptions = {
83
- admonitions,
84
- remarkPlugins,
85
- rehypePlugins,
86
- recmaPlugins,
87
- beforeDefaultRehypePlugins,
88
- beforeDefaultRemarkPlugins,
89
- staticDirs: siteConfig.staticDirectories.map((dir) =>
90
- path.resolve(siteDir, dir),
91
- ),
92
- siteDir,
93
- isMDXPartial: createAbsoluteFilePathMatcher(
94
- options.exclude,
95
- contentDirs,
96
- ),
97
- metadataPath: (mdxPath: string) => {
98
- // Note that metadataPath must be the same/in-sync as
99
- // the path from createData for each MDX.
100
- const aliasedSource = aliasedSitePath(mdxPath, siteDir);
101
- return path.join(dataDir, `${docuHash(aliasedSource)}.json`);
102
- },
103
- // Assets allow to convert some relative images paths to
104
- // require(...) calls
105
- createAssets: ({frontMatter}: {frontMatter: PageFrontMatter}) => ({
106
- image: frontMatter.image,
107
- }),
108
- markdownConfig: siteConfig.markdown,
109
- };
110
-
111
- return {
112
- loader: require.resolve('@docusaurus/mdx-loader'),
113
- options: loaderOptions,
114
- };
115
- }
116
-
117
121
  return {
118
122
  module: {
119
- rules: [
120
- {
121
- test: /\.mdx?$/i,
122
- include: contentDirs
123
- // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
124
- .map(addTrailingPathSeparator),
125
- use: [createMDXLoader()],
126
- },
127
- ],
123
+ rules: [pagesMDXLoaderRule],
128
124
  },
129
125
  };
130
126
  },