@azerion/bunosaurus-plugin-content-docs 0.0.0-stage → 4.0.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/README.md +6 -2
- package/lib/categoryGeneratedIndex.d.ts +12 -0
- package/lib/categoryGeneratedIndex.js +36 -0
- package/lib/cli.d.ts +13 -0
- package/lib/cli.js +124 -0
- package/lib/client/doc.d.ts +29 -0
- package/lib/client/doc.js +47 -0
- package/lib/client/docSidebarItemsExpandedState.d.ts +30 -0
- package/lib/client/docSidebarItemsExpandedState.js +27 -0
- package/lib/client/docsClientUtils.d.ts +15 -0
- package/lib/client/docsClientUtils.js +86 -0
- package/lib/client/docsPreferredVersion.d.ts +29 -0
- package/lib/client/docsPreferredVersion.js +124 -0
- package/lib/client/docsSearch.d.ts +19 -0
- package/lib/client/docsSearch.js +39 -0
- package/lib/client/docsSidebar.d.ts +25 -0
- package/lib/client/docsSidebar.js +29 -0
- package/lib/client/docsUtils.d.ts +112 -0
- package/lib/client/docsUtils.js +299 -0
- package/lib/client/docsVersion.d.ts +19 -0
- package/lib/client/docsVersion.js +25 -0
- package/lib/client/index.d.ts +91 -0
- package/lib/client/index.js +83 -0
- package/lib/client/structuredDataUtils.d.ts +11 -0
- package/lib/client/structuredDataUtils.js +35 -0
- package/lib/constants.d.ts +14 -0
- package/lib/constants.js +17 -0
- package/lib/contentHelpers.d.ts +12 -0
- package/lib/contentHelpers.js +31 -0
- package/lib/docs.d.ts +48 -0
- package/lib/docs.js +252 -0
- package/lib/frontMatter.d.ts +10 -0
- package/lib/frontMatter.js +46 -0
- package/lib/globalData.d.ts +9 -0
- package/lib/globalData.js +59 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +198 -0
- package/lib/numberPrefix.d.ts +11 -0
- package/lib/numberPrefix.js +50 -0
- package/lib/options.d.ts +10 -0
- package/lib/options.js +138 -0
- package/lib/props.d.ts +21 -0
- package/lib/props.js +156 -0
- package/lib/routes.d.ts +22 -0
- package/lib/routes.js +184 -0
- package/lib/server-export.d.ts +9 -0
- package/lib/server-export.js +25 -0
- package/lib/sidebars/generator.d.ts +10 -0
- package/lib/sidebars/generator.js +217 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +99 -0
- package/lib/sidebars/normalization.d.ts +13 -0
- package/lib/sidebars/normalization.js +58 -0
- package/lib/sidebars/postProcessor.d.ts +11 -0
- package/lib/sidebars/postProcessor.js +82 -0
- package/lib/sidebars/processor.d.ts +10 -0
- package/lib/sidebars/processor.js +77 -0
- package/lib/sidebars/types.d.ts +192 -0
- package/lib/sidebars/types.js +8 -0
- package/lib/sidebars/utils.d.ts +69 -0
- package/lib/sidebars/utils.js +327 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +152 -0
- package/lib/slug.d.ts +15 -0
- package/lib/slug.js +51 -0
- package/lib/translations.d.ts +10 -0
- package/lib/translations.js +243 -0
- package/lib/types.d.ts +27 -0
- package/lib/types.js +8 -0
- package/lib/versions/files.d.ts +54 -0
- package/lib/versions/files.js +152 -0
- package/lib/versions/loadVersion.d.ts +17 -0
- package/lib/versions/loadVersion.js +126 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +70 -0
- package/lib/versions/version.d.ts +40 -0
- package/lib/versions/version.js +189 -0
- package/package.json +70 -4
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +180 -0
- package/src/client/doc.tsx +71 -0
- package/src/client/docSidebarItemsExpandedState.tsx +55 -0
- package/src/client/docsClientUtils.ts +140 -0
- package/src/client/docsPreferredVersion.tsx +245 -0
- package/src/client/docsSearch.test.ts +15 -0
- package/src/client/docsSearch.ts +57 -0
- package/src/client/docsSidebar.tsx +50 -0
- package/src/client/docsUtils.tsx +442 -0
- package/src/client/docsVersion.tsx +36 -0
- package/src/client/index.ts +211 -0
- package/src/client/structuredDataUtils.ts +54 -0
- package/src/constants.ts +15 -0
- package/src/contentHelpers.ts +34 -0
- package/src/docs.ts +402 -0
- package/src/frontMatter.ts +57 -0
- package/src/globalData.ts +79 -0
- package/src/index.ts +289 -0
- package/src/numberPrefix.ts +62 -0
- package/src/options.ts +185 -0
- package/src/plugin-content-docs.d.ts +667 -0
- package/src/props.ts +223 -0
- package/src/routes.ts +263 -0
- package/src/server-export.ts +26 -0
- package/src/sidebars/README.md +10 -0
- package/src/sidebars/generator.ts +307 -0
- package/src/sidebars/index.ts +130 -0
- package/src/sidebars/normalization.ts +91 -0
- package/src/sidebars/postProcessor.ts +115 -0
- package/src/sidebars/processor.ts +122 -0
- package/src/sidebars/types.ts +293 -0
- package/src/sidebars/utils.ts +529 -0
- package/src/sidebars/validation.ts +189 -0
- package/src/slug.ts +79 -0
- package/src/translations.ts +365 -0
- package/src/types.ts +34 -0
- package/src/versions/files.ts +240 -0
- package/src/versions/loadVersion.ts +185 -0
- package/src/versions/validation.ts +115 -0
- package/src/versions/version.ts +300 -0
|
@@ -0,0 +1,243 @@
|
|
|
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.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
|
|
10
|
+
exports.translateLoadedContent = translateLoadedContent;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
const utils_2 = require("./sidebars/utils");
|
|
17
|
+
function getVersionFileName(versionName) {
|
|
18
|
+
if (versionName === constants_1.CURRENT_VERSION_NAME) {
|
|
19
|
+
return versionName;
|
|
20
|
+
}
|
|
21
|
+
// I don't like this "version-" prefix,
|
|
22
|
+
// but it's for consistency with site/versioned_docs
|
|
23
|
+
return `version-${versionName}`;
|
|
24
|
+
}
|
|
25
|
+
function ensureNoSidebarDuplicateEntries(translationEntries) {
|
|
26
|
+
const grouped = lodash_1.default.groupBy(translationEntries, (entry) => entry[0]);
|
|
27
|
+
const duplicates = Object.entries(grouped).filter((entry) => entry[1].length > 1);
|
|
28
|
+
if (duplicates.length > 0) {
|
|
29
|
+
throw new Error(`Multiple docs sidebar items produce the same translation key.
|
|
30
|
+
- ${duplicates
|
|
31
|
+
.map(([translationKey, entries]) => {
|
|
32
|
+
return `${logger_1.default.code(translationKey)}: ${logger_1.default.num(entries.length)} duplicates found:\n - ${entries
|
|
33
|
+
.map((duplicate) => {
|
|
34
|
+
const desc = duplicate[1].description;
|
|
35
|
+
return `${logger_1.default.name(duplicate[1].message)} ${desc ? `(${logger_1.default.subdue(desc)})` : ''}`;
|
|
36
|
+
})
|
|
37
|
+
.join('\n - ')}`;
|
|
38
|
+
})
|
|
39
|
+
.join('\n\n- ')}
|
|
40
|
+
|
|
41
|
+
To avoid translation key conflicts, use the ${logger_1.default.code('key')} attribute on the sidebar items above to uniquely identify them.
|
|
42
|
+
|
|
43
|
+
When using autogenerated sidebars, you can provide a unique translation key by adding:
|
|
44
|
+
- the ${logger_1.default.code('key')} attribute to category item metadata (${logger_1.default.code('_category_.json')} / ${logger_1.default.code('_category_.yml')})
|
|
45
|
+
- the ${logger_1.default.code('sidebar_key')} attribute to doc item metadata (front matter in ${logger_1.default.code('Category/index.mdx')})`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
49
|
+
const categories = (0, utils_2.collectSidebarCategories)(sidebar);
|
|
50
|
+
const categoryEntries = categories.flatMap((category) => {
|
|
51
|
+
const entries = [];
|
|
52
|
+
const categoryKey = category.key ?? category.label;
|
|
53
|
+
entries.push([
|
|
54
|
+
`sidebar.${sidebarName}.category.${categoryKey}`,
|
|
55
|
+
{
|
|
56
|
+
message: category.label,
|
|
57
|
+
description: `The label for category '${category.label}' in sidebar '${sidebarName}'`,
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
if (category.link?.type === 'generated-index') {
|
|
61
|
+
if (category.link.title) {
|
|
62
|
+
entries.push([
|
|
63
|
+
`sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.title`,
|
|
64
|
+
{
|
|
65
|
+
message: category.link.title,
|
|
66
|
+
description: `The generated-index page title for category '${category.label}' in sidebar '${sidebarName}'`,
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
if (category.link.description) {
|
|
71
|
+
entries.push([
|
|
72
|
+
`sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.description`,
|
|
73
|
+
{
|
|
74
|
+
message: category.link.description,
|
|
75
|
+
description: `The generated-index page description for category '${category.label}' in sidebar '${sidebarName}'`,
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return entries;
|
|
81
|
+
});
|
|
82
|
+
const links = (0, utils_2.collectSidebarLinks)(sidebar);
|
|
83
|
+
const linksEntries = links.map((link) => {
|
|
84
|
+
const linkKey = link.key ?? link.label;
|
|
85
|
+
return [
|
|
86
|
+
`sidebar.${sidebarName}.link.${linkKey}`,
|
|
87
|
+
{
|
|
88
|
+
message: link.label,
|
|
89
|
+
description: `The label for link '${link.label}' in sidebar '${sidebarName}', linking to '${link.href}'`,
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
});
|
|
93
|
+
const docs = (0, utils_2.collectSidebarDocItems)(sidebar)
|
|
94
|
+
.concat((0, utils_2.collectSidebarRefs)(sidebar))
|
|
95
|
+
.filter((item) => item.translatable);
|
|
96
|
+
const docLinksEntries = docs.map((doc) => {
|
|
97
|
+
const docKey = doc.key ?? doc.label;
|
|
98
|
+
return [
|
|
99
|
+
`sidebar.${sidebarName}.doc.${docKey}`,
|
|
100
|
+
{
|
|
101
|
+
message: doc.label,
|
|
102
|
+
description: `The label for the doc item '${doc.label}' in sidebar '${sidebarName}', linking to the doc ${doc.id}`,
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
});
|
|
106
|
+
const allEntries = [...categoryEntries, ...linksEntries, ...docLinksEntries];
|
|
107
|
+
ensureNoSidebarDuplicateEntries(allEntries);
|
|
108
|
+
return Object.fromEntries(allEntries);
|
|
109
|
+
}
|
|
110
|
+
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
111
|
+
function transformSidebarCategoryLink(category) {
|
|
112
|
+
if (!category.link) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
if (category.link.type === 'generated-index') {
|
|
116
|
+
const categoryKey = category.key ?? category.label;
|
|
117
|
+
const title = sidebarsTranslations[`sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.title`]?.message ?? category.link.title;
|
|
118
|
+
const description = sidebarsTranslations[`sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.description`]?.message ?? category.link.description;
|
|
119
|
+
return {
|
|
120
|
+
...category.link,
|
|
121
|
+
title,
|
|
122
|
+
description,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return category.link;
|
|
126
|
+
}
|
|
127
|
+
return (0, utils_2.transformSidebarItems)(sidebar, (item) => {
|
|
128
|
+
if (item.type === 'category') {
|
|
129
|
+
const link = transformSidebarCategoryLink(item);
|
|
130
|
+
const categoryKey = item.key ?? item.label;
|
|
131
|
+
return {
|
|
132
|
+
...item,
|
|
133
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.category.${categoryKey}`]
|
|
134
|
+
?.message ?? item.label,
|
|
135
|
+
...(link && { link }),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (item.type === 'link') {
|
|
139
|
+
const linkKey = item.key ?? item.label;
|
|
140
|
+
return {
|
|
141
|
+
...item,
|
|
142
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.link.${linkKey}`]
|
|
143
|
+
?.message ?? item.label,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
if ((item.type === 'doc' || item.type === 'ref') && item.translatable) {
|
|
147
|
+
const docKey = item.key ?? item.label;
|
|
148
|
+
return {
|
|
149
|
+
...item,
|
|
150
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.doc.${docKey}`]
|
|
151
|
+
?.message ?? item.label,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return item;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function getSidebarsTranslations(version) {
|
|
158
|
+
return (0, utils_1.mergeTranslations)(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => getSidebarTranslationFileContent(sidebar, sidebarName)));
|
|
159
|
+
}
|
|
160
|
+
function translateSidebars(version, sidebarsTranslations) {
|
|
161
|
+
return lodash_1.default.mapValues(version.sidebars, (sidebar, sidebarName) => translateSidebar({
|
|
162
|
+
sidebar,
|
|
163
|
+
sidebarName,
|
|
164
|
+
sidebarsTranslations,
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
function getVersionTranslationFiles(version) {
|
|
168
|
+
const versionTranslations = {
|
|
169
|
+
'version.label': {
|
|
170
|
+
message: version.label,
|
|
171
|
+
description: `The label for version ${version.versionName}`,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
const sidebarsTranslations = getSidebarsTranslations(version);
|
|
175
|
+
return [
|
|
176
|
+
{
|
|
177
|
+
path: getVersionFileName(version.versionName),
|
|
178
|
+
content: (0, utils_1.mergeTranslations)([versionTranslations, sidebarsTranslations]),
|
|
179
|
+
},
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
// TODO Docusaurus v4 or later
|
|
183
|
+
// this temporarily works, but it is not an ideal solution
|
|
184
|
+
// The docs navigation can be computed and shouldn't be part of LoadedVersion
|
|
185
|
+
// We need to derive the navigation from already translated content
|
|
186
|
+
// See https://github.com/facebook/docusaurus/pull/11794
|
|
187
|
+
function translateDocNavigation(docs, translatedSidebars) {
|
|
188
|
+
// Build a map of permalink -> translated label for generated-index categories
|
|
189
|
+
const translatedLabelByPermalink = new Map();
|
|
190
|
+
for (const sidebar of Object.values(translatedSidebars)) {
|
|
191
|
+
for (const category of (0, utils_2.collectSidebarCategories)(sidebar)) {
|
|
192
|
+
if (category.link?.type === 'generated-index') {
|
|
193
|
+
translatedLabelByPermalink.set(category.link.permalink, category.label);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (translatedLabelByPermalink.size === 0) {
|
|
198
|
+
return docs;
|
|
199
|
+
}
|
|
200
|
+
return docs.map((doc) => {
|
|
201
|
+
const previous = doc.previous && translatedLabelByPermalink.has(doc.previous.permalink)
|
|
202
|
+
? {
|
|
203
|
+
...doc.previous,
|
|
204
|
+
title: translatedLabelByPermalink.get(doc.previous.permalink),
|
|
205
|
+
}
|
|
206
|
+
: doc.previous;
|
|
207
|
+
const next = doc.next && translatedLabelByPermalink.has(doc.next.permalink)
|
|
208
|
+
? {
|
|
209
|
+
...doc.next,
|
|
210
|
+
title: translatedLabelByPermalink.get(doc.next.permalink),
|
|
211
|
+
}
|
|
212
|
+
: doc.next;
|
|
213
|
+
if (previous === doc.previous && next === doc.next) {
|
|
214
|
+
return doc;
|
|
215
|
+
}
|
|
216
|
+
return { ...doc, previous, next };
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function translateVersion(version, translationFiles) {
|
|
220
|
+
const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
|
|
221
|
+
const translatedSidebars = translateSidebars(version, versionTranslations);
|
|
222
|
+
return {
|
|
223
|
+
...version,
|
|
224
|
+
label: versionTranslations['version.label']?.message ?? version.label,
|
|
225
|
+
sidebars: translatedSidebars,
|
|
226
|
+
docs: translateDocNavigation(version.docs, translatedSidebars),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function getVersionsTranslationFiles(versions) {
|
|
230
|
+
return versions.flatMap(getVersionTranslationFiles);
|
|
231
|
+
}
|
|
232
|
+
function translateVersions(versions, translationFiles) {
|
|
233
|
+
return versions.map((version) => translateVersion(version, translationFiles));
|
|
234
|
+
}
|
|
235
|
+
function getLoadedContentTranslationFiles(loadedContent) {
|
|
236
|
+
return getVersionsTranslationFiles(loadedContent.loadedVersions);
|
|
237
|
+
}
|
|
238
|
+
function translateLoadedContent(loadedContent, translationFiles) {
|
|
239
|
+
const translationFilesMap = lodash_1.default.keyBy(translationFiles, (f) => f.path);
|
|
240
|
+
return {
|
|
241
|
+
loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
|
|
242
|
+
};
|
|
243
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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 { TagMetadata } from '@docusaurus/utils';
|
|
8
|
+
import type { LoadedVersion, CategoryGeneratedIndexMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
import type { SidebarsUtils } from './sidebars/utils';
|
|
10
|
+
export type DocFile = {
|
|
11
|
+
contentPath: string;
|
|
12
|
+
filePath: string;
|
|
13
|
+
source: string;
|
|
14
|
+
content: string;
|
|
15
|
+
};
|
|
16
|
+
export type VersionTag = TagMetadata & {
|
|
17
|
+
/** All doc ids having this tag. */
|
|
18
|
+
docIds: string[];
|
|
19
|
+
unlisted: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type VersionTags = {
|
|
22
|
+
[permalink: string]: VersionTag;
|
|
23
|
+
};
|
|
24
|
+
export type FullVersion = LoadedVersion & {
|
|
25
|
+
sidebarsUtils: SidebarsUtils;
|
|
26
|
+
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
27
|
+
};
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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 });
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { PluginOptions, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { VersionContext } from './version';
|
|
9
|
+
/** `[siteDir]/community_versioned_docs/version-1.0.0` */
|
|
10
|
+
export declare function getVersionDocsDirPath(siteDir: string, pluginId: string, versionName: string): string;
|
|
11
|
+
/** `[siteDir]/community_versioned_sidebars/version-1.0.0-sidebars.json` */
|
|
12
|
+
export declare function getVersionSidebarsPath(siteDir: string, pluginId: string, versionName: string): string;
|
|
13
|
+
export declare function getDocsDirPathLocalized({ localizationDir, pluginId, versionName, }: {
|
|
14
|
+
localizationDir: string;
|
|
15
|
+
pluginId: string;
|
|
16
|
+
versionName: string;
|
|
17
|
+
}): string;
|
|
18
|
+
export declare function getPluginDirPathLocalized({ localizationDir, pluginId, }: {
|
|
19
|
+
localizationDir: string;
|
|
20
|
+
pluginId: string;
|
|
21
|
+
}): string;
|
|
22
|
+
/** `community` => `[siteDir]/community_versions.json` */
|
|
23
|
+
export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Reads the plugin's respective `versions.json` file, and returns its content.
|
|
26
|
+
*
|
|
27
|
+
* @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
|
|
28
|
+
* array of valid version names.
|
|
29
|
+
*/
|
|
30
|
+
export declare function readVersionsFile(siteDir: string, pluginId: string): Promise<string[] | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Reads the `versions.json` file, and returns an ordered list of version names.
|
|
33
|
+
*
|
|
34
|
+
* - If `disableVersioning` is turned on, it will return `["current"]` (requires
|
|
35
|
+
* `includeCurrentVersion` to be true);
|
|
36
|
+
* - If `includeCurrentVersion` is turned on, "current" will be inserted at the
|
|
37
|
+
* beginning, if not already there.
|
|
38
|
+
*
|
|
39
|
+
* You need to use {@link filterVersions} after this.
|
|
40
|
+
*
|
|
41
|
+
* @throws Throws an error if `disableVersioning: true` but `versions.json`
|
|
42
|
+
* doesn't exist (i.e. site is not versioned)
|
|
43
|
+
* @throws Throws an error if versions list is empty (empty `versions.json` or
|
|
44
|
+
* `disableVersioning` is true, and not including current version)
|
|
45
|
+
*/
|
|
46
|
+
export declare function readVersionNames(siteDir: string, options: PluginOptions): Promise<string[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the path-related version metadata.
|
|
49
|
+
*
|
|
50
|
+
* @throws Throws if the resolved docs folder or sidebars file doesn't exist.
|
|
51
|
+
* Does not throw if a versioned sidebar is missing (since we don't create empty
|
|
52
|
+
* files).
|
|
53
|
+
*/
|
|
54
|
+
export declare function getVersionMetadataPaths({ versionName, context, options, }: VersionContext): Promise<Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized' | 'sidebarFilePath'>>;
|
|
@@ -0,0 +1,152 @@
|
|
|
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.getVersionDocsDirPath = getVersionDocsDirPath;
|
|
10
|
+
exports.getVersionSidebarsPath = getVersionSidebarsPath;
|
|
11
|
+
exports.getDocsDirPathLocalized = getDocsDirPathLocalized;
|
|
12
|
+
exports.getPluginDirPathLocalized = getPluginDirPathLocalized;
|
|
13
|
+
exports.getVersionsFilePath = getVersionsFilePath;
|
|
14
|
+
exports.readVersionsFile = readVersionsFile;
|
|
15
|
+
exports.readVersionNames = readVersionNames;
|
|
16
|
+
exports.getVersionMetadataPaths = getVersionMetadataPaths;
|
|
17
|
+
const tslib_1 = require("tslib");
|
|
18
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
19
|
+
const utils_1 = require("@docusaurus/utils");
|
|
20
|
+
const fs_1 = require("@docusaurus/fs");
|
|
21
|
+
const constants_1 = require("../constants");
|
|
22
|
+
const validation_1 = require("./validation");
|
|
23
|
+
/** Add a prefix like `community_version-1.0.0`. No-op for default instance. */
|
|
24
|
+
function addPluginIdPrefix(fileOrDir, pluginId) {
|
|
25
|
+
return pluginId === utils_1.DEFAULT_PLUGIN_ID
|
|
26
|
+
? fileOrDir
|
|
27
|
+
: `${pluginId}_${fileOrDir}`;
|
|
28
|
+
}
|
|
29
|
+
/** `[siteDir]/community_versioned_docs/version-1.0.0` */
|
|
30
|
+
function getVersionDocsDirPath(siteDir, pluginId, versionName) {
|
|
31
|
+
return node_path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_DOCS_DIR, pluginId), `version-${versionName}`);
|
|
32
|
+
}
|
|
33
|
+
/** `[siteDir]/community_versioned_sidebars/version-1.0.0-sidebars.json` */
|
|
34
|
+
function getVersionSidebarsPath(siteDir, pluginId, versionName) {
|
|
35
|
+
return node_path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_SIDEBARS_DIR, pluginId), `version-${versionName}-sidebars.json`);
|
|
36
|
+
}
|
|
37
|
+
function getDocsDirPathLocalized({ localizationDir, pluginId, versionName, }) {
|
|
38
|
+
return (0, utils_1.getPluginI18nPath)({
|
|
39
|
+
localizationDir,
|
|
40
|
+
pluginName: 'docusaurus-plugin-content-docs',
|
|
41
|
+
pluginId,
|
|
42
|
+
subPaths: [
|
|
43
|
+
versionName === constants_1.CURRENT_VERSION_NAME
|
|
44
|
+
? constants_1.CURRENT_VERSION_NAME
|
|
45
|
+
: `version-${versionName}`,
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function getPluginDirPathLocalized({ localizationDir, pluginId, }) {
|
|
50
|
+
return (0, utils_1.getPluginI18nPath)({
|
|
51
|
+
localizationDir,
|
|
52
|
+
pluginName: 'docusaurus-plugin-content-docs',
|
|
53
|
+
pluginId,
|
|
54
|
+
subPaths: [],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** `community` => `[siteDir]/community_versions.json` */
|
|
58
|
+
function getVersionsFilePath(siteDir, pluginId) {
|
|
59
|
+
return node_path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONS_JSON_FILE, pluginId));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Reads the plugin's respective `versions.json` file, and returns its content.
|
|
63
|
+
*
|
|
64
|
+
* @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
|
|
65
|
+
* array of valid version names.
|
|
66
|
+
*/
|
|
67
|
+
async function readVersionsFile(siteDir, pluginId) {
|
|
68
|
+
const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
|
|
69
|
+
if (await (0, fs_1.pathExists)(versionsFilePath)) {
|
|
70
|
+
const content = await (0, fs_1.readJSON)(versionsFilePath);
|
|
71
|
+
(0, validation_1.validateVersionNames)(content);
|
|
72
|
+
return content;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Reads the `versions.json` file, and returns an ordered list of version names.
|
|
78
|
+
*
|
|
79
|
+
* - If `disableVersioning` is turned on, it will return `["current"]` (requires
|
|
80
|
+
* `includeCurrentVersion` to be true);
|
|
81
|
+
* - If `includeCurrentVersion` is turned on, "current" will be inserted at the
|
|
82
|
+
* beginning, if not already there.
|
|
83
|
+
*
|
|
84
|
+
* You need to use {@link filterVersions} after this.
|
|
85
|
+
*
|
|
86
|
+
* @throws Throws an error if `disableVersioning: true` but `versions.json`
|
|
87
|
+
* doesn't exist (i.e. site is not versioned)
|
|
88
|
+
* @throws Throws an error if versions list is empty (empty `versions.json` or
|
|
89
|
+
* `disableVersioning` is true, and not including current version)
|
|
90
|
+
*/
|
|
91
|
+
async function readVersionNames(siteDir, options) {
|
|
92
|
+
const versionFileContent = await readVersionsFile(siteDir, options.id);
|
|
93
|
+
if (!versionFileContent && options.disableVersioning) {
|
|
94
|
+
throw new Error(`Docs: using "disableVersioning: true" option on a non-versioned site does not make sense.`);
|
|
95
|
+
}
|
|
96
|
+
const versions = options.disableVersioning ? [] : (versionFileContent ?? []);
|
|
97
|
+
// We add the current version at the beginning, unless:
|
|
98
|
+
// - user don't want to; or
|
|
99
|
+
// - it's already been explicitly added to versions.json
|
|
100
|
+
if (options.includeCurrentVersion &&
|
|
101
|
+
!versions.includes(constants_1.CURRENT_VERSION_NAME)) {
|
|
102
|
+
versions.unshift(constants_1.CURRENT_VERSION_NAME);
|
|
103
|
+
}
|
|
104
|
+
if (versions.length === 0) {
|
|
105
|
+
throw new Error(`It is not possible to use docs without any version. No version is included because you have requested to not include ${node_path_1.default.resolve(options.path)} through "includeCurrentVersion: false", while ${options.disableVersioning
|
|
106
|
+
? 'versioning is disabled with "disableVersioning: true"'
|
|
107
|
+
: `the versions file is empty/non-existent`}.`);
|
|
108
|
+
}
|
|
109
|
+
return versions;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Gets the path-related version metadata.
|
|
113
|
+
*
|
|
114
|
+
* @throws Throws if the resolved docs folder or sidebars file doesn't exist.
|
|
115
|
+
* Does not throw if a versioned sidebar is missing (since we don't create empty
|
|
116
|
+
* files).
|
|
117
|
+
*/
|
|
118
|
+
async function getVersionMetadataPaths({ versionName, context, options, }) {
|
|
119
|
+
const isCurrent = versionName === constants_1.CURRENT_VERSION_NAME;
|
|
120
|
+
const shouldTranslate = (0, utils_1.getLocaleConfig)(context.i18n).translate;
|
|
121
|
+
const contentPathLocalized = shouldTranslate
|
|
122
|
+
? getDocsDirPathLocalized({
|
|
123
|
+
localizationDir: context.localizationDir,
|
|
124
|
+
pluginId: options.id,
|
|
125
|
+
versionName,
|
|
126
|
+
})
|
|
127
|
+
: undefined;
|
|
128
|
+
const contentPath = isCurrent
|
|
129
|
+
? node_path_1.default.resolve(context.siteDir, options.path)
|
|
130
|
+
: getVersionDocsDirPath(context.siteDir, options.id, versionName);
|
|
131
|
+
const sidebarFilePath = isCurrent
|
|
132
|
+
? options.sidebarPath
|
|
133
|
+
: getVersionSidebarsPath(context.siteDir, options.id, versionName);
|
|
134
|
+
if (!(await (0, fs_1.pathExists)(contentPath))) {
|
|
135
|
+
throw new Error(`The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${node_path_1.default.relative(context.siteDir, contentPath)}.`);
|
|
136
|
+
}
|
|
137
|
+
// If the current version defines a path to a sidebar file that does not
|
|
138
|
+
// exist, we throw! Note: for versioned sidebars, the file may not exist (as
|
|
139
|
+
// we prefer to not create it rather than to create an empty file)
|
|
140
|
+
// See https://github.com/facebook/docusaurus/issues/3366
|
|
141
|
+
// See https://github.com/facebook/docusaurus/pull/4775
|
|
142
|
+
if (versionName === constants_1.CURRENT_VERSION_NAME &&
|
|
143
|
+
typeof sidebarFilePath === 'string' &&
|
|
144
|
+
!(await (0, fs_1.pathExists)(sidebarFilePath))) {
|
|
145
|
+
throw new Error(`The path to the sidebar file does not exist at "${node_path_1.default.relative(context.siteDir, sidebarFilePath)}".
|
|
146
|
+
Please set the docs "sidebarPath" field in your config file to:
|
|
147
|
+
- a sidebars path that exists
|
|
148
|
+
- false: to disable the sidebar
|
|
149
|
+
- undefined: for Docusaurus to generate it automatically`);
|
|
150
|
+
}
|
|
151
|
+
return { contentPath, contentPathLocalized, sidebarFilePath };
|
|
152
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 DocEnv } from '../docs';
|
|
8
|
+
import type { LoadedVersion, PluginOptions, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
10
|
+
type LoadVersionParams = {
|
|
11
|
+
context: LoadContext;
|
|
12
|
+
options: PluginOptions;
|
|
13
|
+
versionMetadata: VersionMetadata;
|
|
14
|
+
env: DocEnv;
|
|
15
|
+
};
|
|
16
|
+
export declare function loadVersion(params: LoadVersionParams): Promise<LoadedVersion>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
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.loadVersion = loadVersion;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
15
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
16
|
+
const docs_1 = require("../docs");
|
|
17
|
+
const sidebars_1 = require("../sidebars");
|
|
18
|
+
const utils_2 = require("../sidebars/utils");
|
|
19
|
+
function ensureNoDuplicateDocId(docs) {
|
|
20
|
+
const duplicatesById = lodash_1.default.chain(docs)
|
|
21
|
+
.sort((d1, d2) => {
|
|
22
|
+
// Need to sort because glob order is non-deterministic
|
|
23
|
+
// TODO maybe we should create a deterministic glob utils?
|
|
24
|
+
// see https://github.com/sindresorhus/globby/issues/131
|
|
25
|
+
return d1.source.localeCompare(d2.source);
|
|
26
|
+
})
|
|
27
|
+
.groupBy((d) => d.id)
|
|
28
|
+
.pickBy((group) => group.length > 1)
|
|
29
|
+
.value();
|
|
30
|
+
const duplicateIdEntries = Object.entries(duplicatesById);
|
|
31
|
+
if (duplicateIdEntries.length) {
|
|
32
|
+
const idMessages = duplicateIdEntries
|
|
33
|
+
.map(([id, duplicateDocs]) => {
|
|
34
|
+
return logger_1.default.interpolate `- code=${id} found in number=${duplicateDocs.length} docs:
|
|
35
|
+
- ${duplicateDocs
|
|
36
|
+
.map((d) => (0, utils_1.aliasedSitePathToRelativePath)(d.source))
|
|
37
|
+
.join('\n - ')}`;
|
|
38
|
+
})
|
|
39
|
+
.join('\n\n');
|
|
40
|
+
const message = `The docs plugin found docs sharing the same id:
|
|
41
|
+
\n${idMessages}\n
|
|
42
|
+
Docs should have distinct ids.
|
|
43
|
+
In case of conflict, you can rename the docs file, or use the ${logger_1.default.code('id')} front matter to assign an explicit distinct id to each doc.
|
|
44
|
+
`;
|
|
45
|
+
throw new Error(message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function loadVersionDocsBase({ tagsFile, context, options, versionMetadata, env, }) {
|
|
49
|
+
const docFiles = await (0, docs_1.readVersionDocs)(versionMetadata, options);
|
|
50
|
+
if (docFiles.length === 0) {
|
|
51
|
+
throw new Error(`Docs version "${versionMetadata.versionName}" has no docs! At least one doc should exist at "${node_path_1.default.relative(context.siteDir, versionMetadata.contentPath)}".`);
|
|
52
|
+
}
|
|
53
|
+
function processVersionDoc(docFile) {
|
|
54
|
+
return (0, docs_1.processDocMetadata)({
|
|
55
|
+
docFile,
|
|
56
|
+
versionMetadata,
|
|
57
|
+
context,
|
|
58
|
+
options,
|
|
59
|
+
env,
|
|
60
|
+
tagsFile,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const docs = await Promise.all(docFiles.map(processVersionDoc));
|
|
64
|
+
ensureNoDuplicateDocId(docs);
|
|
65
|
+
return docs;
|
|
66
|
+
}
|
|
67
|
+
async function doLoadVersion({ context, options, versionMetadata, env, }) {
|
|
68
|
+
const tagsFile = await (0, utils_validation_1.getTagsFile)({
|
|
69
|
+
contentPaths: versionMetadata,
|
|
70
|
+
tags: options.tags,
|
|
71
|
+
});
|
|
72
|
+
const docsBase = await loadVersionDocsBase({
|
|
73
|
+
tagsFile,
|
|
74
|
+
context,
|
|
75
|
+
options,
|
|
76
|
+
versionMetadata,
|
|
77
|
+
env,
|
|
78
|
+
});
|
|
79
|
+
// TODO we only ever need draftIds in further code, not full draft items
|
|
80
|
+
// To simplify and prevent mistakes, avoid exposing draft
|
|
81
|
+
// replace draft=>draftIds in content loaded
|
|
82
|
+
const [drafts, docs] = lodash_1.default.partition(docsBase, (doc) => doc.draft);
|
|
83
|
+
const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
|
|
84
|
+
sidebarItemsGenerator: options.sidebarItemsGenerator,
|
|
85
|
+
numberPrefixParser: options.numberPrefixParser,
|
|
86
|
+
docs,
|
|
87
|
+
drafts,
|
|
88
|
+
version: versionMetadata,
|
|
89
|
+
sidebarOptions: {
|
|
90
|
+
sidebarCollapsed: options.sidebarCollapsed,
|
|
91
|
+
sidebarCollapsible: options.sidebarCollapsible,
|
|
92
|
+
},
|
|
93
|
+
categoryLabelSlugger: (0, utils_1.createSlugger)(),
|
|
94
|
+
});
|
|
95
|
+
const sidebarsUtils = (0, utils_2.createSidebarsUtils)(sidebars);
|
|
96
|
+
const docsById = (0, docs_1.createDocsByIdIndex)(docs);
|
|
97
|
+
const allDocIds = Object.keys(docsById);
|
|
98
|
+
sidebarsUtils.checkLegacyVersionedSidebarNames({
|
|
99
|
+
sidebarFilePath: versionMetadata.sidebarFilePath,
|
|
100
|
+
versionMetadata,
|
|
101
|
+
});
|
|
102
|
+
sidebarsUtils.checkSidebarsDocIds({
|
|
103
|
+
allDocIds,
|
|
104
|
+
sidebarFilePath: versionMetadata.sidebarFilePath,
|
|
105
|
+
versionMetadata,
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
...versionMetadata,
|
|
109
|
+
docs: (0, docs_1.addDocNavigation)({
|
|
110
|
+
docs,
|
|
111
|
+
sidebarsUtils,
|
|
112
|
+
}),
|
|
113
|
+
drafts,
|
|
114
|
+
sidebars,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function loadVersion(params) {
|
|
118
|
+
try {
|
|
119
|
+
return await doLoadVersion(params);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
// TODO use error cause (but need to refactor many tests)
|
|
123
|
+
logger_1.default.error `Loading of version failed for version name=${params.versionMetadata.versionName}`;
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { VersionsOptions } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
export declare function validateVersionName(name: unknown): asserts name is string;
|
|
9
|
+
export declare function validateVersionNames(names: unknown): asserts names is string[];
|
|
10
|
+
/**
|
|
11
|
+
* @throws Throws for one of the following invalid options:
|
|
12
|
+
* - `lastVersion` is non-existent
|
|
13
|
+
* - `versions` includes unknown keys
|
|
14
|
+
* - `onlyIncludeVersions` is empty, contains unknown names, or doesn't include
|
|
15
|
+
* `latestVersion` (if provided)
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateVersionsOptions(availableVersionNames: string[], options: VersionsOptions): void;
|