@docusaurus/plugin-content-pages 3.9.2 → 3.10.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.
package/lib/content.js CHANGED
@@ -49,6 +49,7 @@ async function loadPagesContent(params) {
49
49
  async function processPageSourceFile(relativeSource, params) {
50
50
  const { context, options, contentPaths } = params;
51
51
  const { siteConfig, baseUrl, siteDir, i18n } = context;
52
+ const vcs = siteConfig.future.experimental_vcs;
52
53
  const { editUrl } = options;
53
54
  // Lookup in localized folder in priority
54
55
  const contentPath = await (0, utils_1.getFolderContainingFile)((0, utils_1.getContentPathList)(contentPaths), relativeSource);
@@ -101,7 +102,7 @@ async function processPageSourceFile(relativeSource, params) {
101
102
  }
102
103
  return undefined;
103
104
  }
104
- const lastUpdatedData = await (0, utils_1.readLastUpdateData)(source, options, frontMatter.last_update);
105
+ const lastUpdatedData = await (0, utils_1.readLastUpdateData)(source, options, frontMatter.last_update, vcs);
105
106
  if ((0, utils_1.isDraft)({ frontMatter })) {
106
107
  return undefined;
107
108
  }
@@ -0,0 +1,12 @@
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 { LoadedContent, Metadata } from '@docusaurus/plugin-content-pages';
8
+ export declare function createContentHelpers(): {
9
+ updateContent: (content: LoadedContent) => void;
10
+ sourceToPage: Map<string, Metadata>;
11
+ sourceToPermalink: Map<string, string>;
12
+ };
@@ -0,0 +1,30 @@
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.createContentHelpers = createContentHelpers;
10
+ function indexPagesBySource(content) {
11
+ return new Map(content.map((page) => [page.source, page]));
12
+ }
13
+ // TODO this is bad, we should have a better way to do this (new lifecycle?)
14
+ // The source to page/permalink is a mutable map passed to the mdx loader
15
+ // See https://github.com/facebook/docusaurus/pull/10457
16
+ // See https://github.com/facebook/docusaurus/pull/10185
17
+ function createContentHelpers() {
18
+ const sourceToPage = new Map();
19
+ const sourceToPermalink = new Map();
20
+ // Mutable map update :/
21
+ function updateContent(content) {
22
+ sourceToPage.clear();
23
+ sourceToPermalink.clear();
24
+ indexPagesBySource(content).forEach((value, key) => {
25
+ sourceToPage.set(key, value);
26
+ sourceToPermalink.set(key, value.permalink);
27
+ });
28
+ }
29
+ return { updateContent, sourceToPage, sourceToPermalink };
30
+ }
package/lib/index.js CHANGED
@@ -15,11 +15,13 @@ const utils_1 = require("@docusaurus/utils");
15
15
  const mdx_loader_1 = require("@docusaurus/mdx-loader");
16
16
  const routes_1 = require("./routes");
17
17
  const content_1 = require("./content");
18
+ const contentHelpers_1 = require("./contentHelpers");
18
19
  async function pluginContentPages(context, options) {
19
20
  const { siteConfig, siteDir, generatedFilesDir } = context;
20
21
  const contentPaths = (0, content_1.createPagesContentPaths)({ context, options });
22
+ const contentHelpers = (0, contentHelpers_1.createContentHelpers)();
21
23
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-pages');
22
- const dataDir = path_1.default.join(pluginDataDirRoot, options.id ?? utils_1.DEFAULT_PLUGIN_ID);
24
+ const dataDir = path_1.default.join(pluginDataDirRoot, options.id);
23
25
  async function createPagesMDXLoaderRule() {
24
26
  const { admonitions, rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
25
27
  const contentDirs = (0, utils_1.getContentPathList)(contentPaths);
@@ -28,7 +30,7 @@ async function pluginContentPages(context, options) {
28
30
  // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
29
31
  .map(utils_1.addTrailingPathSeparator),
30
32
  options: {
31
- useCrossCompilerCache: siteConfig.future.experimental_faster.mdxCrossCompilerCache,
33
+ useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache,
32
34
  admonitions,
33
35
  remarkPlugins,
34
36
  rehypePlugins,
@@ -49,6 +51,14 @@ async function pluginContentPages(context, options) {
49
51
  image: frontMatter.image,
50
52
  }),
51
53
  markdownConfig: siteConfig.markdown,
54
+ resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
55
+ return (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
56
+ sourceFilePath,
57
+ sourceToPermalink: contentHelpers.sourceToPermalink,
58
+ siteDir,
59
+ contentPaths,
60
+ });
61
+ },
52
62
  },
53
63
  });
54
64
  }
@@ -69,6 +79,7 @@ async function pluginContentPages(context, options) {
69
79
  if (!content) {
70
80
  return;
71
81
  }
82
+ contentHelpers.updateContent(content);
72
83
  await (0, routes_1.createAllRoutes)({ content, options, actions });
73
84
  },
74
85
  configureWebpack() {
package/lib/options.js CHANGED
@@ -11,6 +11,7 @@ exports.validateOptions = validateOptions;
11
11
  const utils_validation_1 = require("@docusaurus/utils-validation");
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  exports.DEFAULT_OPTIONS = {
14
+ id: utils_1.DEFAULT_PLUGIN_ID,
14
15
  path: 'src/pages', // Path to data on filesystem, relative to site dir.
15
16
  routeBasePath: '/', // URL Route.
16
17
  include: ['**/*.{js,jsx,ts,tsx,md,mdx}'], // Extensions to include.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-pages",
3
- "version": "3.9.2",
3
+ "version": "3.10.0",
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.9.2",
22
- "@docusaurus/mdx-loader": "3.9.2",
23
- "@docusaurus/types": "3.9.2",
24
- "@docusaurus/utils": "3.9.2",
25
- "@docusaurus/utils-validation": "3.9.2",
21
+ "@docusaurus/core": "3.10.0",
22
+ "@docusaurus/mdx-loader": "3.10.0",
23
+ "@docusaurus/types": "3.10.0",
24
+ "@docusaurus/utils": "3.10.0",
25
+ "@docusaurus/utils-validation": "3.10.0",
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": ">=20.0"
36
36
  },
37
- "gitHead": "abfbe5621b08407bc3dcbe6111ff118d4c22f7a1"
37
+ "gitHead": "0d98888a7645a5fb1330c905b75faf868f829f5c"
38
38
  }
package/src/content.ts CHANGED
@@ -98,6 +98,7 @@ async function processPageSourceFile(
98
98
  ): Promise<Metadata | undefined> {
99
99
  const {context, options, contentPaths} = params;
100
100
  const {siteConfig, baseUrl, siteDir, i18n} = context;
101
+ const vcs = siteConfig.future.experimental_vcs;
101
102
  const {editUrl} = options;
102
103
 
103
104
  // Lookup in localized folder in priority
@@ -180,6 +181,7 @@ async function processPageSourceFile(
180
181
  source,
181
182
  options,
182
183
  frontMatter.last_update,
184
+ vcs,
183
185
  );
184
186
 
185
187
  if (isDraft({frontMatter})) {
@@ -0,0 +1,33 @@
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 type {LoadedContent, Metadata} from '@docusaurus/plugin-content-pages';
9
+
10
+ function indexPagesBySource(content: LoadedContent): Map<string, Metadata> {
11
+ return new Map(content.map((page) => [page.source, page]));
12
+ }
13
+
14
+ // TODO this is bad, we should have a better way to do this (new lifecycle?)
15
+ // The source to page/permalink is a mutable map passed to the mdx loader
16
+ // See https://github.com/facebook/docusaurus/pull/10457
17
+ // See https://github.com/facebook/docusaurus/pull/10185
18
+ export function createContentHelpers() {
19
+ const sourceToPage = new Map<string, Metadata>();
20
+ const sourceToPermalink = new Map<string, string>();
21
+
22
+ // Mutable map update :/
23
+ function updateContent(content: LoadedContent): void {
24
+ sourceToPage.clear();
25
+ sourceToPermalink.clear();
26
+ indexPagesBySource(content).forEach((value, key) => {
27
+ sourceToPage.set(key, value);
28
+ sourceToPermalink.set(key, value.permalink);
29
+ });
30
+ }
31
+
32
+ return {updateContent, sourceToPage, sourceToPermalink};
33
+ }
package/src/index.ts CHANGED
@@ -13,11 +13,12 @@ import {
13
13
  addTrailingPathSeparator,
14
14
  createAbsoluteFilePathMatcher,
15
15
  getContentPathList,
16
- DEFAULT_PLUGIN_ID,
16
+ resolveMarkdownLinkPathname,
17
17
  } from '@docusaurus/utils';
18
18
  import {createMDXLoaderRule} from '@docusaurus/mdx-loader';
19
19
  import {createAllRoutes} from './routes';
20
20
  import {createPagesContentPaths, loadPagesContent} from './content';
21
+ import {createContentHelpers} from './contentHelpers';
21
22
  import type {LoadContext, Plugin} from '@docusaurus/types';
22
23
  import type {
23
24
  PluginOptions,
@@ -33,12 +34,13 @@ export default async function pluginContentPages(
33
34
  const {siteConfig, siteDir, generatedFilesDir} = context;
34
35
 
35
36
  const contentPaths = createPagesContentPaths({context, options});
37
+ const contentHelpers = createContentHelpers();
36
38
 
37
39
  const pluginDataDirRoot = path.join(
38
40
  generatedFilesDir,
39
41
  'docusaurus-plugin-content-pages',
40
42
  );
41
- const dataDir = path.join(pluginDataDirRoot, options.id ?? DEFAULT_PLUGIN_ID);
43
+ const dataDir = path.join(pluginDataDirRoot, options.id);
42
44
 
43
45
  async function createPagesMDXLoaderRule(): Promise<RuleSetRule> {
44
46
  const {
@@ -56,8 +58,7 @@ export default async function pluginContentPages(
56
58
  // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
57
59
  .map(addTrailingPathSeparator),
58
60
  options: {
59
- useCrossCompilerCache:
60
- siteConfig.future.experimental_faster.mdxCrossCompilerCache,
61
+ useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache,
61
62
  admonitions,
62
63
  remarkPlugins,
63
64
  rehypePlugins,
@@ -83,6 +84,14 @@ export default async function pluginContentPages(
83
84
  image: frontMatter.image,
84
85
  }),
85
86
  markdownConfig: siteConfig.markdown,
87
+ resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
88
+ return resolveMarkdownLinkPathname(linkPathname, {
89
+ sourceFilePath,
90
+ sourceToPermalink: contentHelpers.sourceToPermalink,
91
+ siteDir,
92
+ contentPaths,
93
+ });
94
+ },
86
95
  },
87
96
  });
88
97
  }
@@ -110,6 +119,7 @@ export default async function pluginContentPages(
110
119
  if (!content) {
111
120
  return;
112
121
  }
122
+ contentHelpers.updateContent(content);
113
123
  await createAllRoutes({content, options, actions});
114
124
  },
115
125
 
package/src/options.ts CHANGED
@@ -14,11 +14,12 @@ import {
14
14
  RouteBasePathSchema,
15
15
  URISchema,
16
16
  } from '@docusaurus/utils-validation';
17
- import {GlobExcludeDefault} from '@docusaurus/utils';
17
+ import {DEFAULT_PLUGIN_ID, GlobExcludeDefault} from '@docusaurus/utils';
18
18
  import type {OptionValidationContext} from '@docusaurus/types';
19
19
  import type {PluginOptions, Options} from '@docusaurus/plugin-content-pages';
20
20
 
21
21
  export const DEFAULT_OPTIONS: PluginOptions = {
22
+ id: DEFAULT_PLUGIN_ID,
22
23
  path: 'src/pages', // Path to data on filesystem, relative to site dir.
23
24
  routeBasePath: '/', // URL Route.
24
25
  include: ['**/*.{js,jsx,ts,tsx,md,mdx}'], // Extensions to include.
@@ -19,7 +19,7 @@ declare module '@docusaurus/plugin-content-pages' {
19
19
  };
20
20
 
21
21
  export type PluginOptions = MDXOptions & {
22
- id?: string;
22
+ id: string;
23
23
  path: string;
24
24
  routeBasePath: string;
25
25
  include: string[];