@docusaurus/plugin-content-pages 0.0.0-6063 → 0.0.0-6065

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.
@@ -0,0 +1,11 @@
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
+ };
@@ -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<string, string>();
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.metadata.permalink);
27
+ });
28
+ }
29
+ return { updateContent, sourceToPage };
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 });
21
22
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-pages');
22
23
  const dataDir = path_1.default.join(pluginDataDirRoot, options.id ?? utils_1.DEFAULT_PLUGIN_ID);
24
+ const contentHelpers = (0, contentHelpers_1.createContentHelpers)();
23
25
  async function createPagesMDXLoaderRule() {
24
26
  const { admonitions, rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
25
27
  const contentDirs = (0, content_1.getContentPathList)(contentPaths);
@@ -37,7 +39,12 @@ async function pluginContentPages(context, options) {
37
39
  // Note that metadataPath must be the same/in-sync as
38
40
  // the path from createData for each MDX.
39
41
  const aliasedSource = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
40
- return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedSource)}.json`);
42
+ const metadataPath = path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedSource)}.json`);
43
+ const metadataContent = contentHelpers.sourceToPage.get(aliasedSource);
44
+ return {
45
+ metadataPath,
46
+ metadataContent,
47
+ };
41
48
  },
42
49
  // Assets allow to convert some relative images paths to
43
50
  // require(...) calls
@@ -70,6 +77,7 @@ async function pluginContentPages(context, options) {
70
77
  if (!content) {
71
78
  return;
72
79
  }
80
+ contentHelpers.updateContent(content);
73
81
  await (0, routes_1.createAllRoutes)({ content, options, actions });
74
82
  },
75
83
  configureWebpack() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-pages",
3
- "version": "0.0.0-6063",
3
+ "version": "0.0.0-6065",
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-6063",
22
- "@docusaurus/mdx-loader": "0.0.0-6063",
23
- "@docusaurus/types": "0.0.0-6063",
24
- "@docusaurus/utils": "0.0.0-6063",
25
- "@docusaurus/utils-validation": "0.0.0-6063",
21
+ "@docusaurus/core": "0.0.0-6065",
22
+ "@docusaurus/mdx-loader": "0.0.0-6065",
23
+ "@docusaurus/types": "0.0.0-6065",
24
+ "@docusaurus/utils": "0.0.0-6065",
25
+ "@docusaurus/utils-validation": "0.0.0-6065",
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": "d6fbbb85fcb98fd3bf658610f6d7345e5dad2530"
37
+ "gitHead": "6da713a524315a36515fc3e998ff1551bfa054d2"
38
38
  }
@@ -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.metadata.permalink);
29
+ });
30
+ }
31
+
32
+ return {updateContent, sourceToPage};
33
+ }
package/src/index.ts CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  getContentPathList,
25
25
  loadPagesContent,
26
26
  } from './content';
27
+ import {createContentHelpers} from './contentHelpers';
27
28
  import type {LoadContext, Plugin} from '@docusaurus/types';
28
29
  import type {
29
30
  PluginOptions,
@@ -46,6 +47,8 @@ export default async function pluginContentPages(
46
47
  );
47
48
  const dataDir = path.join(pluginDataDirRoot, options.id ?? DEFAULT_PLUGIN_ID);
48
49
 
50
+ const contentHelpers = createContentHelpers();
51
+
49
52
  async function createPagesMDXLoaderRule(): Promise<RuleSetRule> {
50
53
  const {
51
54
  admonitions,
@@ -73,7 +76,15 @@ export default async function pluginContentPages(
73
76
  // Note that metadataPath must be the same/in-sync as
74
77
  // the path from createData for each MDX.
75
78
  const aliasedSource = aliasedSitePath(mdxPath, siteDir);
76
- return path.join(dataDir, `${docuHash(aliasedSource)}.json`);
79
+ const metadataPath = path.join(
80
+ dataDir,
81
+ `${docuHash(aliasedSource)}.json`,
82
+ );
83
+ const metadataContent = contentHelpers.sourceToPage.get(aliasedSource);
84
+ return {
85
+ metadataPath,
86
+ metadataContent,
87
+ };
77
88
  },
78
89
  // Assets allow to convert some relative images paths to
79
90
  // require(...) calls
@@ -114,6 +125,7 @@ export default async function pluginContentPages(
114
125
  if (!content) {
115
126
  return;
116
127
  }
128
+ contentHelpers.updateContent(content);
117
129
  await createAllRoutes({content, options, actions});
118
130
  },
119
131