@docusaurus/plugin-content-pages 3.9.2-canary-6465 → 3.9.2-canary-6499
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/contentHelpers.d.ts +12 -0
- package/lib/contentHelpers.js +30 -0
- package/lib/index.js +11 -0
- package/package.json +7 -7
- package/src/contentHelpers.ts +33 -0
- package/src/index.ts +12 -0
|
@@ -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,9 +15,11 @@ 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
24
|
const dataDir = path_1.default.join(pluginDataDirRoot, options.id);
|
|
23
25
|
async function createPagesMDXLoaderRule() {
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-pages",
|
|
3
|
-
"version": "3.9.2-canary-
|
|
3
|
+
"version": "3.9.2-canary-6499",
|
|
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-canary-
|
|
22
|
-
"@docusaurus/mdx-loader": "3.9.2-canary-
|
|
23
|
-
"@docusaurus/types": "3.9.2-canary-
|
|
24
|
-
"@docusaurus/utils": "3.9.2-canary-
|
|
25
|
-
"@docusaurus/utils-validation": "3.9.2-canary-
|
|
21
|
+
"@docusaurus/core": "3.9.2-canary-6499",
|
|
22
|
+
"@docusaurus/mdx-loader": "3.9.2-canary-6499",
|
|
23
|
+
"@docusaurus/types": "3.9.2-canary-6499",
|
|
24
|
+
"@docusaurus/utils": "3.9.2-canary-6499",
|
|
25
|
+
"@docusaurus/utils-validation": "3.9.2-canary-6499",
|
|
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": "
|
|
37
|
+
"gitHead": "5ad8c2b9301411f0be8fabe95315c6a4ac7a7af4"
|
|
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.permalink);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {updateContent, sourceToPage, sourceToPermalink};
|
|
33
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -13,10 +13,12 @@ import {
|
|
|
13
13
|
addTrailingPathSeparator,
|
|
14
14
|
createAbsoluteFilePathMatcher,
|
|
15
15
|
getContentPathList,
|
|
16
|
+
resolveMarkdownLinkPathname,
|
|
16
17
|
} from '@docusaurus/utils';
|
|
17
18
|
import {createMDXLoaderRule} from '@docusaurus/mdx-loader';
|
|
18
19
|
import {createAllRoutes} from './routes';
|
|
19
20
|
import {createPagesContentPaths, loadPagesContent} from './content';
|
|
21
|
+
import {createContentHelpers} from './contentHelpers';
|
|
20
22
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
21
23
|
import type {
|
|
22
24
|
PluginOptions,
|
|
@@ -32,6 +34,7 @@ export default async function pluginContentPages(
|
|
|
32
34
|
const {siteConfig, siteDir, generatedFilesDir} = context;
|
|
33
35
|
|
|
34
36
|
const contentPaths = createPagesContentPaths({context, options});
|
|
37
|
+
const contentHelpers = createContentHelpers();
|
|
35
38
|
|
|
36
39
|
const pluginDataDirRoot = path.join(
|
|
37
40
|
generatedFilesDir,
|
|
@@ -82,6 +85,14 @@ export default async function pluginContentPages(
|
|
|
82
85
|
image: frontMatter.image,
|
|
83
86
|
}),
|
|
84
87
|
markdownConfig: siteConfig.markdown,
|
|
88
|
+
resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
|
|
89
|
+
return resolveMarkdownLinkPathname(linkPathname, {
|
|
90
|
+
sourceFilePath,
|
|
91
|
+
sourceToPermalink: contentHelpers.sourceToPermalink,
|
|
92
|
+
siteDir,
|
|
93
|
+
contentPaths,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
85
96
|
},
|
|
86
97
|
});
|
|
87
98
|
}
|
|
@@ -109,6 +120,7 @@ export default async function pluginContentPages(
|
|
|
109
120
|
if (!content) {
|
|
110
121
|
return;
|
|
111
122
|
}
|
|
123
|
+
contentHelpers.updateContent(content);
|
|
112
124
|
await createAllRoutes({content, options, actions});
|
|
113
125
|
},
|
|
114
126
|
|