@docusaurus/plugin-content-pages 3.5.2 → 3.6.0-canary-6134

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,47 @@ 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
+ return (0, mdx_loader_1.createMDXLoaderRule)({
27
+ include: contentDirs
28
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
29
+ .map(utils_1.addTrailingPathSeparator),
30
+ options: {
31
+ useCrossCompilerCache: siteConfig.future.experimental_faster.mdxCrossCompilerCache,
32
+ admonitions,
33
+ remarkPlugins,
34
+ rehypePlugins,
35
+ recmaPlugins,
36
+ beforeDefaultRehypePlugins,
37
+ beforeDefaultRemarkPlugins,
38
+ staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
39
+ siteDir,
40
+ isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
41
+ metadataPath: (mdxPath) => {
42
+ // Note that metadataPath must be the same/in-sync as
43
+ // the path from createData for each MDX.
44
+ const aliasedSource = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
45
+ return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedSource)}.json`);
46
+ },
47
+ // createAssets converts relative paths to require() calls
48
+ createAssets: ({ frontMatter }) => ({
49
+ image: frontMatter.image,
50
+ }),
51
+ markdownConfig: siteConfig.markdown,
52
+ },
53
+ });
54
+ }
55
+ const pagesMDXLoaderRule = await createPagesMDXLoaderRule();
22
56
  return {
23
57
  name: 'docusaurus-plugin-content-pages',
24
58
  getPathsToWatch() {
@@ -38,48 +72,9 @@ function pluginContentPages(context, options) {
38
72
  await (0, routes_1.createAllRoutes)({ content, options, actions });
39
73
  },
40
74
  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
75
  return {
73
76
  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
- ],
77
+ rules: [pagesMDXLoaderRule],
83
78
  },
84
79
  };
85
80
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-pages",
3
- "version": "3.5.2",
3
+ "version": "3.6.0-canary-6134",
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": "3.5.2",
22
- "@docusaurus/mdx-loader": "3.5.2",
23
- "@docusaurus/types": "3.5.2",
24
- "@docusaurus/utils": "3.5.2",
25
- "@docusaurus/utils-validation": "3.5.2",
21
+ "@docusaurus/core": "3.6.0-canary-6134",
22
+ "@docusaurus/mdx-loader": "3.6.0-canary-6134",
23
+ "@docusaurus/types": "3.6.0-canary-6134",
24
+ "@docusaurus/utils": "3.6.0-canary-6134",
25
+ "@docusaurus/utils-validation": "3.6.0-canary-6134",
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": "eeec303dd773774ed5a023884800da0b061f6942"
37
+ "gitHead": "706c96c3bdd92c7d3ac61447ec49e4bfa6d0526b"
38
38
  }
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  createAbsoluteFilePathMatcher,
15
15
  DEFAULT_PLUGIN_ID,
16
16
  } from '@docusaurus/utils';
17
+ import {createMDXLoaderRule} from '@docusaurus/mdx-loader';
17
18
  import {createAllRoutes} from './routes';
18
19
  import {
19
20
  createPagesContentPaths,
@@ -26,13 +27,12 @@ import type {
26
27
  LoadedContent,
27
28
  PageFrontMatter,
28
29
  } from '@docusaurus/plugin-content-pages';
29
- import type {RuleSetUseItem} from 'webpack';
30
- import type {Options as MDXLoaderOptions} from '@docusaurus/mdx-loader/lib/loader';
30
+ import type {RuleSetRule} from 'webpack';
31
31
 
32
- export default function pluginContentPages(
32
+ export default async function pluginContentPages(
33
33
  context: LoadContext,
34
34
  options: PluginOptions,
35
- ): Plugin<LoadedContent | null> {
35
+ ): Promise<Plugin<LoadedContent | null>> {
36
36
  const {siteConfig, siteDir, generatedFilesDir} = context;
37
37
 
38
38
  const contentPaths = createPagesContentPaths({context, options});
@@ -43,6 +43,55 @@ export default function pluginContentPages(
43
43
  );
44
44
  const dataDir = path.join(pluginDataDirRoot, options.id ?? DEFAULT_PLUGIN_ID);
45
45
 
46
+ async function createPagesMDXLoaderRule(): Promise<RuleSetRule> {
47
+ const {
48
+ admonitions,
49
+ rehypePlugins,
50
+ remarkPlugins,
51
+ recmaPlugins,
52
+ beforeDefaultRehypePlugins,
53
+ beforeDefaultRemarkPlugins,
54
+ } = options;
55
+ const contentDirs = getContentPathList(contentPaths);
56
+
57
+ return createMDXLoaderRule({
58
+ include: contentDirs
59
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
60
+ .map(addTrailingPathSeparator),
61
+ options: {
62
+ useCrossCompilerCache:
63
+ siteConfig.future.experimental_faster.mdxCrossCompilerCache,
64
+ admonitions,
65
+ remarkPlugins,
66
+ rehypePlugins,
67
+ recmaPlugins,
68
+ beforeDefaultRehypePlugins,
69
+ beforeDefaultRemarkPlugins,
70
+ staticDirs: siteConfig.staticDirectories.map((dir) =>
71
+ path.resolve(siteDir, dir),
72
+ ),
73
+ siteDir,
74
+ isMDXPartial: createAbsoluteFilePathMatcher(
75
+ options.exclude,
76
+ contentDirs,
77
+ ),
78
+ metadataPath: (mdxPath: string) => {
79
+ // Note that metadataPath must be the same/in-sync as
80
+ // the path from createData for each MDX.
81
+ const aliasedSource = aliasedSitePath(mdxPath, siteDir);
82
+ return path.join(dataDir, `${docuHash(aliasedSource)}.json`);
83
+ },
84
+ // createAssets converts relative paths to require() calls
85
+ createAssets: ({frontMatter}: {frontMatter: PageFrontMatter}) => ({
86
+ image: frontMatter.image,
87
+ }),
88
+ markdownConfig: siteConfig.markdown,
89
+ },
90
+ });
91
+ }
92
+
93
+ const pagesMDXLoaderRule = await createPagesMDXLoaderRule();
94
+
46
95
  return {
47
96
  name: 'docusaurus-plugin-content-pages',
48
97
 
@@ -68,63 +117,9 @@ export default function pluginContentPages(
68
117
  },
69
118
 
70
119
  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
120
  return {
118
121
  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
- ],
122
+ rules: [pagesMDXLoaderRule],
128
123
  },
129
124
  };
130
125
  },