@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,300 @@
|
|
|
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 path from 'node:path';
|
|
9
|
+
import {getContentPathList, normalizeUrl, posixPath} from '@docusaurus/utils';
|
|
10
|
+
import {CURRENT_VERSION_NAME} from '../constants';
|
|
11
|
+
import {validateVersionsOptions} from './validation';
|
|
12
|
+
import {
|
|
13
|
+
getDocsDirPathLocalized,
|
|
14
|
+
getVersionMetadataPaths,
|
|
15
|
+
readVersionNames,
|
|
16
|
+
} from './files';
|
|
17
|
+
import {createSidebarsUtils} from '../sidebars/utils';
|
|
18
|
+
import {getCategoryGeneratedIndexMetadataList} from '../categoryGeneratedIndex';
|
|
19
|
+
import type {FullVersion} from '../types';
|
|
20
|
+
import type {LoadContext} from '@docusaurus/types';
|
|
21
|
+
import type {
|
|
22
|
+
LoadedVersion,
|
|
23
|
+
PluginOptions,
|
|
24
|
+
VersionBanner,
|
|
25
|
+
VersionMetadata,
|
|
26
|
+
} from '@docusaurus/plugin-content-docs';
|
|
27
|
+
|
|
28
|
+
export type VersionContext = {
|
|
29
|
+
/** The version name to get banner of. */
|
|
30
|
+
versionName: string;
|
|
31
|
+
/** All versions, ordered from newest to oldest. */
|
|
32
|
+
versionNames: string[];
|
|
33
|
+
lastVersionName: string;
|
|
34
|
+
context: LoadContext;
|
|
35
|
+
options: PluginOptions;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function getVersionEditUrls({
|
|
39
|
+
contentPath,
|
|
40
|
+
contentPathLocalized,
|
|
41
|
+
context,
|
|
42
|
+
options,
|
|
43
|
+
}: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'> & {
|
|
44
|
+
context: LoadContext;
|
|
45
|
+
options: PluginOptions;
|
|
46
|
+
}): Pick<VersionMetadata, 'editUrl' | 'editUrlLocalized'> {
|
|
47
|
+
// If the user is using the functional form of editUrl,
|
|
48
|
+
// she has total freedom and we can't compute a "version edit url"
|
|
49
|
+
if (!options.editUrl || typeof options.editUrl === 'function') {
|
|
50
|
+
return {editUrl: undefined, editUrlLocalized: undefined};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Intermediate var just to please TS not narrowing to "string"
|
|
54
|
+
const editUrlOption = options.editUrl;
|
|
55
|
+
|
|
56
|
+
const getEditUrl = () => {
|
|
57
|
+
const editDirPath = options.editCurrentVersion ? options.path : contentPath;
|
|
58
|
+
|
|
59
|
+
return normalizeUrl([
|
|
60
|
+
editUrlOption,
|
|
61
|
+
posixPath(
|
|
62
|
+
path.relative(
|
|
63
|
+
context.siteDir,
|
|
64
|
+
path.resolve(context.siteDir, editDirPath),
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
]);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const getEditUrlLocalized = () => {
|
|
71
|
+
if (!contentPathLocalized) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
const editDirPathLocalized = options.editCurrentVersion
|
|
75
|
+
? getDocsDirPathLocalized({
|
|
76
|
+
localizationDir: context.localizationDir,
|
|
77
|
+
versionName: CURRENT_VERSION_NAME,
|
|
78
|
+
pluginId: options.id,
|
|
79
|
+
})
|
|
80
|
+
: contentPathLocalized;
|
|
81
|
+
|
|
82
|
+
return normalizeUrl([
|
|
83
|
+
editUrlOption,
|
|
84
|
+
posixPath(
|
|
85
|
+
path.relative(
|
|
86
|
+
context.siteDir,
|
|
87
|
+
path.resolve(context.siteDir, editDirPathLocalized),
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
]);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return {editUrl: getEditUrl(), editUrlLocalized: getEditUrlLocalized()};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The default version banner depends on the version's relative position to the
|
|
98
|
+
* latest version. More recent ones are "unreleased", and older ones are
|
|
99
|
+
* "unmaintained".
|
|
100
|
+
*/
|
|
101
|
+
export function getDefaultVersionBanner({
|
|
102
|
+
versionName,
|
|
103
|
+
versionNames,
|
|
104
|
+
lastVersionName,
|
|
105
|
+
}: VersionContext): VersionBanner | null {
|
|
106
|
+
// Current version: good, no banner
|
|
107
|
+
if (versionName === lastVersionName) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
// Upcoming versions: unreleased banner
|
|
111
|
+
if (
|
|
112
|
+
versionNames.indexOf(versionName) < versionNames.indexOf(lastVersionName)
|
|
113
|
+
) {
|
|
114
|
+
return 'unreleased';
|
|
115
|
+
}
|
|
116
|
+
// Older versions: display unmaintained banner
|
|
117
|
+
return 'unmaintained';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function getVersionBanner(
|
|
121
|
+
context: VersionContext,
|
|
122
|
+
): VersionMetadata['banner'] {
|
|
123
|
+
const {versionName, options} = context;
|
|
124
|
+
const versionBannerOption = options.versions[versionName]?.banner;
|
|
125
|
+
if (versionBannerOption) {
|
|
126
|
+
return versionBannerOption === 'none' ? null : versionBannerOption;
|
|
127
|
+
}
|
|
128
|
+
return getDefaultVersionBanner(context);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function getVersionBadge({
|
|
132
|
+
versionName,
|
|
133
|
+
versionNames,
|
|
134
|
+
options,
|
|
135
|
+
}: VersionContext): VersionMetadata['badge'] {
|
|
136
|
+
// If site is not versioned or only one version is included
|
|
137
|
+
// we don't show the version badge by default
|
|
138
|
+
// See https://github.com/facebook/docusaurus/issues/3362
|
|
139
|
+
const defaultVersionBadge = versionNames.length !== 1;
|
|
140
|
+
return options.versions[versionName]?.badge ?? defaultVersionBadge;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function getVersionNoIndex({
|
|
144
|
+
versionName,
|
|
145
|
+
options,
|
|
146
|
+
}: VersionContext): VersionMetadata['noIndex'] {
|
|
147
|
+
return options.versions[versionName]?.noIndex ?? false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function getVersionClassName({
|
|
151
|
+
versionName,
|
|
152
|
+
options,
|
|
153
|
+
}: VersionContext): VersionMetadata['className'] {
|
|
154
|
+
const defaultVersionClassName = `docs-version-${versionName}`;
|
|
155
|
+
return options.versions[versionName]?.className ?? defaultVersionClassName;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function getVersionLabel({
|
|
159
|
+
versionName,
|
|
160
|
+
options,
|
|
161
|
+
}: VersionContext): VersionMetadata['label'] {
|
|
162
|
+
const defaultVersionLabel =
|
|
163
|
+
versionName === CURRENT_VERSION_NAME ? 'Next' : versionName;
|
|
164
|
+
return options.versions[versionName]?.label ?? defaultVersionLabel;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function getVersionPathPart({
|
|
168
|
+
versionName,
|
|
169
|
+
options,
|
|
170
|
+
lastVersionName,
|
|
171
|
+
}: VersionContext): string {
|
|
172
|
+
function getDefaultVersionPathPart() {
|
|
173
|
+
if (versionName === lastVersionName) {
|
|
174
|
+
return '';
|
|
175
|
+
}
|
|
176
|
+
return versionName === CURRENT_VERSION_NAME ? 'next' : versionName;
|
|
177
|
+
}
|
|
178
|
+
return options.versions[versionName]?.path ?? getDefaultVersionPathPart();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function createVersionMetadata(
|
|
182
|
+
context: VersionContext,
|
|
183
|
+
): Promise<VersionMetadata> {
|
|
184
|
+
const {versionName, lastVersionName, options, context: loadContext} = context;
|
|
185
|
+
const {sidebarFilePath, contentPath, contentPathLocalized} =
|
|
186
|
+
await getVersionMetadataPaths(context);
|
|
187
|
+
const versionPathPart = getVersionPathPart(context);
|
|
188
|
+
|
|
189
|
+
const routePath = normalizeUrl([
|
|
190
|
+
loadContext.baseUrl,
|
|
191
|
+
options.routeBasePath,
|
|
192
|
+
versionPathPart,
|
|
193
|
+
]);
|
|
194
|
+
|
|
195
|
+
const versionEditUrls = getVersionEditUrls({
|
|
196
|
+
contentPath,
|
|
197
|
+
contentPathLocalized,
|
|
198
|
+
context: loadContext,
|
|
199
|
+
options,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
versionName,
|
|
204
|
+
label: getVersionLabel(context),
|
|
205
|
+
banner: getVersionBanner(context),
|
|
206
|
+
badge: getVersionBadge(context),
|
|
207
|
+
noIndex: getVersionNoIndex(context),
|
|
208
|
+
className: getVersionClassName(context),
|
|
209
|
+
path: routePath,
|
|
210
|
+
tagsPath: normalizeUrl([routePath, options.tagsBasePath]),
|
|
211
|
+
...versionEditUrls,
|
|
212
|
+
isLast: versionName === lastVersionName,
|
|
213
|
+
routePriority: versionPathPart === '' ? -1 : undefined,
|
|
214
|
+
sidebarFilePath,
|
|
215
|
+
contentPath,
|
|
216
|
+
contentPathLocalized,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Filter versions according to provided options (i.e. `onlyIncludeVersions`).
|
|
222
|
+
*
|
|
223
|
+
* Note: we preserve the order in which versions are provided; the order of the
|
|
224
|
+
* `onlyIncludeVersions` array does not matter
|
|
225
|
+
*/
|
|
226
|
+
export function filterVersions(
|
|
227
|
+
versionNamesUnfiltered: string[],
|
|
228
|
+
options: PluginOptions,
|
|
229
|
+
): string[] {
|
|
230
|
+
if (options.onlyIncludeVersions) {
|
|
231
|
+
return versionNamesUnfiltered.filter((name) =>
|
|
232
|
+
options.onlyIncludeVersions!.includes(name),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
return versionNamesUnfiltered;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function getLastVersionName({
|
|
239
|
+
versionNames,
|
|
240
|
+
options,
|
|
241
|
+
}: Pick<VersionContext, 'versionNames' | 'options'>) {
|
|
242
|
+
return (
|
|
243
|
+
options.lastVersion ??
|
|
244
|
+
versionNames.find((name) => name !== CURRENT_VERSION_NAME) ??
|
|
245
|
+
CURRENT_VERSION_NAME
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export async function readVersionsMetadata({
|
|
250
|
+
context,
|
|
251
|
+
options,
|
|
252
|
+
}: {
|
|
253
|
+
context: LoadContext;
|
|
254
|
+
options: PluginOptions;
|
|
255
|
+
}): Promise<VersionMetadata[]> {
|
|
256
|
+
const allVersionNames = await readVersionNames(context.siteDir, options);
|
|
257
|
+
validateVersionsOptions(allVersionNames, options);
|
|
258
|
+
const versionNames = filterVersions(allVersionNames, options);
|
|
259
|
+
const lastVersionName = getLastVersionName({versionNames, options});
|
|
260
|
+
return Promise.all(
|
|
261
|
+
versionNames.map((versionName) =>
|
|
262
|
+
createVersionMetadata({
|
|
263
|
+
versionName,
|
|
264
|
+
versionNames,
|
|
265
|
+
lastVersionName,
|
|
266
|
+
context,
|
|
267
|
+
options,
|
|
268
|
+
}),
|
|
269
|
+
),
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function toFullVersion(version: LoadedVersion): FullVersion {
|
|
274
|
+
const sidebarsUtils = createSidebarsUtils(version.sidebars);
|
|
275
|
+
return {
|
|
276
|
+
...version,
|
|
277
|
+
sidebarsUtils,
|
|
278
|
+
categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
|
|
279
|
+
docs: version.docs,
|
|
280
|
+
sidebarsUtils,
|
|
281
|
+
}),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function getVersionFromSourceFilePath(
|
|
286
|
+
filePath: string,
|
|
287
|
+
versionsMetadata: VersionMetadata[],
|
|
288
|
+
): VersionMetadata {
|
|
289
|
+
const versionFound = versionsMetadata.find((version) =>
|
|
290
|
+
getContentPathList(version).some((docsDirPath) =>
|
|
291
|
+
filePath.startsWith(docsDirPath),
|
|
292
|
+
),
|
|
293
|
+
);
|
|
294
|
+
if (!versionFound) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
`Unexpected error: file at "${filePath}" does not belong to any docs version!`,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
return versionFound;
|
|
300
|
+
}
|