@docusaurus/plugin-content-docs 0.0.0-5962 → 0.0.0-5963
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.js +22 -8
- package/lib/types.d.ts +0 -3
- package/package.json +10 -10
- package/src/index.ts +31 -13
- package/src/types.ts +0 -4
package/lib/index.js
CHANGED
|
@@ -23,6 +23,25 @@ const globalData_1 = require("./globalData");
|
|
|
23
23
|
const translations_1 = require("./translations");
|
|
24
24
|
const routes_1 = require("./routes");
|
|
25
25
|
const utils_2 = require("./sidebars/utils");
|
|
26
|
+
// TODO this is bad, we should have a better way to do this (new lifecycle?)
|
|
27
|
+
// The source to permalink is currently a mutable map passed to the mdx loader
|
|
28
|
+
// for link resolution
|
|
29
|
+
// see https://github.com/facebook/docusaurus/pull/10185
|
|
30
|
+
function createSourceToPermalinkHelper() {
|
|
31
|
+
const sourceToPermalink = new Map();
|
|
32
|
+
function computeSourceToPermalink(content) {
|
|
33
|
+
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
34
|
+
return new Map(allDocs.map(({ source, permalink }) => [source, permalink]));
|
|
35
|
+
}
|
|
36
|
+
// Mutable map update :/
|
|
37
|
+
function update(content) {
|
|
38
|
+
sourceToPermalink.clear();
|
|
39
|
+
computeSourceToPermalink(content).forEach((value, key) => {
|
|
40
|
+
sourceToPermalink.set(key, value);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return { get: () => sourceToPermalink, update };
|
|
44
|
+
}
|
|
26
45
|
async function pluginContentDocs(context, options) {
|
|
27
46
|
const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
|
|
28
47
|
// Mutate options to resolve sidebar path according to siteDir
|
|
@@ -37,6 +56,7 @@ async function pluginContentDocs(context, options) {
|
|
|
37
56
|
const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
|
|
38
57
|
// TODO env should be injected into all plugins
|
|
39
58
|
const env = process.env.NODE_ENV;
|
|
59
|
+
const sourceToPermalinkHelper = createSourceToPermalinkHelper();
|
|
40
60
|
return {
|
|
41
61
|
name: 'docusaurus-plugin-content-docs',
|
|
42
62
|
extendCli(cli) {
|
|
@@ -154,6 +174,7 @@ async function pluginContentDocs(context, options) {
|
|
|
154
174
|
return (0, translations_1.translateLoadedContent)(content, translationFiles);
|
|
155
175
|
},
|
|
156
176
|
async contentLoaded({ content, actions }) {
|
|
177
|
+
sourceToPermalinkHelper.update(content);
|
|
157
178
|
const versions = content.loadedVersions.map(versions_1.toFullVersion);
|
|
158
179
|
await (0, routes_1.createAllRoutes)({
|
|
159
180
|
baseUrl,
|
|
@@ -174,13 +195,6 @@ async function pluginContentDocs(context, options) {
|
|
|
174
195
|
.flatMap(utils_1.getContentPathList)
|
|
175
196
|
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
176
197
|
.map(utils_1.addTrailingPathSeparator);
|
|
177
|
-
// TODO this does not re-run when content gets updated in dev!
|
|
178
|
-
// it's probably better to restore a mutable cache in the plugin
|
|
179
|
-
function getSourceToPermalink() {
|
|
180
|
-
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
181
|
-
return Object.fromEntries(allDocs.map(({ source, permalink }) => [source, permalink]));
|
|
182
|
-
}
|
|
183
|
-
const sourceToPermalink = getSourceToPermalink();
|
|
184
198
|
function createMDXLoader() {
|
|
185
199
|
const loaderOptions = {
|
|
186
200
|
admonitions: options.admonitions,
|
|
@@ -207,7 +221,7 @@ async function pluginContentDocs(context, options) {
|
|
|
207
221
|
const version = (0, versions_1.getVersionFromSourceFilePath)(sourceFilePath, content.loadedVersions);
|
|
208
222
|
const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
|
|
209
223
|
sourceFilePath,
|
|
210
|
-
sourceToPermalink,
|
|
224
|
+
sourceToPermalink: sourceToPermalinkHelper.get(),
|
|
211
225
|
siteDir,
|
|
212
226
|
contentPaths: version,
|
|
213
227
|
});
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5963",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@docusaurus/core": "0.0.0-
|
|
39
|
-
"@docusaurus/logger": "0.0.0-
|
|
40
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
41
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
42
|
-
"@docusaurus/types": "0.0.0-
|
|
43
|
-
"@docusaurus/utils": "0.0.0-
|
|
44
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
45
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
38
|
+
"@docusaurus/core": "0.0.0-5963",
|
|
39
|
+
"@docusaurus/logger": "0.0.0-5963",
|
|
40
|
+
"@docusaurus/mdx-loader": "0.0.0-5963",
|
|
41
|
+
"@docusaurus/module-type-aliases": "0.0.0-5963",
|
|
42
|
+
"@docusaurus/types": "0.0.0-5963",
|
|
43
|
+
"@docusaurus/utils": "0.0.0-5963",
|
|
44
|
+
"@docusaurus/utils-common": "0.0.0-5963",
|
|
45
|
+
"@docusaurus/utils-validation": "0.0.0-5963",
|
|
46
46
|
"@types/react-router-config": "^5.0.7",
|
|
47
47
|
"combine-promises": "^1.1.0",
|
|
48
48
|
"fs-extra": "^11.1.1",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"engines": {
|
|
67
67
|
"node": ">=18.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "e9090dc8a38a21043b0849887aa7d54d04c4af9f"
|
|
70
70
|
}
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
createSlugger,
|
|
20
20
|
resolveMarkdownLinkPathname,
|
|
21
21
|
DEFAULT_PLUGIN_ID,
|
|
22
|
+
type SourceToPermalink,
|
|
23
|
+
type TagsFile,
|
|
22
24
|
} from '@docusaurus/utils';
|
|
23
25
|
import {
|
|
24
26
|
getTagsFile,
|
|
@@ -47,7 +49,6 @@ import {
|
|
|
47
49
|
} from './translations';
|
|
48
50
|
import {createAllRoutes} from './routes';
|
|
49
51
|
import {createSidebarsUtils} from './sidebars/utils';
|
|
50
|
-
import type {TagsFile} from '@docusaurus/utils';
|
|
51
52
|
import type {Options as MDXLoaderOptions} from '@docusaurus/mdx-loader';
|
|
52
53
|
|
|
53
54
|
import type {
|
|
@@ -59,9 +60,32 @@ import type {
|
|
|
59
60
|
LoadedVersion,
|
|
60
61
|
} from '@docusaurus/plugin-content-docs';
|
|
61
62
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
62
|
-
import type {
|
|
63
|
+
import type {DocFile, FullVersion} from './types';
|
|
63
64
|
import type {RuleSetUseItem} from 'webpack';
|
|
64
65
|
|
|
66
|
+
// TODO this is bad, we should have a better way to do this (new lifecycle?)
|
|
67
|
+
// The source to permalink is currently a mutable map passed to the mdx loader
|
|
68
|
+
// for link resolution
|
|
69
|
+
// see https://github.com/facebook/docusaurus/pull/10185
|
|
70
|
+
function createSourceToPermalinkHelper() {
|
|
71
|
+
const sourceToPermalink: SourceToPermalink = new Map();
|
|
72
|
+
|
|
73
|
+
function computeSourceToPermalink(content: LoadedContent): SourceToPermalink {
|
|
74
|
+
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
75
|
+
return new Map(allDocs.map(({source, permalink}) => [source, permalink]));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Mutable map update :/
|
|
79
|
+
function update(content: LoadedContent): void {
|
|
80
|
+
sourceToPermalink.clear();
|
|
81
|
+
computeSourceToPermalink(content).forEach((value, key) => {
|
|
82
|
+
sourceToPermalink.set(key, value);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {get: () => sourceToPermalink, update};
|
|
87
|
+
}
|
|
88
|
+
|
|
65
89
|
export default async function pluginContentDocs(
|
|
66
90
|
context: LoadContext,
|
|
67
91
|
options: PluginOptions,
|
|
@@ -88,6 +112,8 @@ export default async function pluginContentDocs(
|
|
|
88
112
|
// TODO env should be injected into all plugins
|
|
89
113
|
const env = process.env.NODE_ENV as DocEnv;
|
|
90
114
|
|
|
115
|
+
const sourceToPermalinkHelper = createSourceToPermalinkHelper();
|
|
116
|
+
|
|
91
117
|
return {
|
|
92
118
|
name: 'docusaurus-plugin-content-docs',
|
|
93
119
|
|
|
@@ -244,6 +270,8 @@ export default async function pluginContentDocs(
|
|
|
244
270
|
},
|
|
245
271
|
|
|
246
272
|
async contentLoaded({content, actions}) {
|
|
273
|
+
sourceToPermalinkHelper.update(content);
|
|
274
|
+
|
|
247
275
|
const versions: FullVersion[] = content.loadedVersions.map(toFullVersion);
|
|
248
276
|
|
|
249
277
|
await createAllRoutes({
|
|
@@ -274,16 +302,6 @@ export default async function pluginContentDocs(
|
|
|
274
302
|
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
275
303
|
.map(addTrailingPathSeparator);
|
|
276
304
|
|
|
277
|
-
// TODO this does not re-run when content gets updated in dev!
|
|
278
|
-
// it's probably better to restore a mutable cache in the plugin
|
|
279
|
-
function getSourceToPermalink(): SourceToPermalink {
|
|
280
|
-
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
281
|
-
return Object.fromEntries(
|
|
282
|
-
allDocs.map(({source, permalink}) => [source, permalink]),
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
const sourceToPermalink = getSourceToPermalink();
|
|
286
|
-
|
|
287
305
|
function createMDXLoader(): RuleSetUseItem {
|
|
288
306
|
const loaderOptions: MDXLoaderOptions = {
|
|
289
307
|
admonitions: options.admonitions,
|
|
@@ -318,7 +336,7 @@ export default async function pluginContentDocs(
|
|
|
318
336
|
);
|
|
319
337
|
const permalink = resolveMarkdownLinkPathname(linkPathname, {
|
|
320
338
|
sourceFilePath,
|
|
321
|
-
sourceToPermalink,
|
|
339
|
+
sourceToPermalink: sourceToPermalinkHelper.get(),
|
|
322
340
|
siteDir,
|
|
323
341
|
contentPaths: version,
|
|
324
342
|
});
|
package/src/types.ts
CHANGED