@docusaurus/plugin-content-docs 0.0.0-4240 → 0.0.0-4244
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/.tsbuildinfo +1 -1
- package/lib/categoryGeneratedIndex.d.ts +12 -0
- package/lib/categoryGeneratedIndex.js +37 -0
- package/lib/cli.js +5 -23
- package/lib/docs.d.ts +22 -2
- package/lib/docs.js +71 -29
- package/lib/index.js +34 -62
- package/lib/options.js +2 -0
- package/lib/props.js +35 -6
- package/lib/routes.d.ts +27 -0
- package/lib/routes.js +105 -0
- package/lib/sidebars/generator.d.ts +2 -1
- package/lib/sidebars/generator.js +55 -13
- package/lib/sidebars/index.d.ts +5 -4
- package/lib/sidebars/index.js +18 -9
- package/lib/sidebars/normalization.d.ts +8 -3
- package/lib/sidebars/normalization.js +36 -17
- package/lib/sidebars/processor.d.ts +5 -3
- package/lib/sidebars/processor.js +33 -18
- package/lib/sidebars/types.d.ts +43 -2
- package/lib/sidebars/utils.d.ts +18 -6
- package/lib/sidebars/utils.js +149 -24
- package/lib/sidebars/validation.d.ts +2 -0
- package/lib/sidebars/validation.js +44 -8
- package/lib/slug.d.ts +4 -3
- package/lib/slug.js +26 -14
- package/lib/translations.js +51 -7
- package/lib/types.d.ts +18 -3
- package/package.json +8 -8
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +2 -2
- package/src/__tests__/__snapshots__/cli.test.ts.snap +48 -106
- package/src/__tests__/__snapshots__/index.test.ts.snap +279 -28
- package/src/__tests__/__snapshots__/translations.test.ts.snap +45 -0
- package/src/__tests__/docs.test.ts +122 -7
- package/src/__tests__/index.test.ts +27 -1
- package/src/__tests__/options.test.ts +2 -0
- package/src/__tests__/slug.test.ts +127 -20
- package/src/__tests__/translations.test.ts +7 -0
- package/src/categoryGeneratedIndex.ts +57 -0
- package/src/cli.ts +5 -35
- package/src/docs.ts +103 -45
- package/src/index.ts +55 -93
- package/src/options.ts +4 -0
- package/src/plugin-content-docs.d.ts +71 -8
- package/src/props.ts +48 -9
- package/src/routes.ts +173 -0
- package/src/sidebars/__tests__/__snapshots__/index.test.ts.snap +21 -6
- package/src/sidebars/__tests__/generator.test.ts +105 -1
- package/src/sidebars/__tests__/index.test.ts +26 -24
- package/src/sidebars/__tests__/processor.test.ts +110 -19
- package/src/sidebars/__tests__/utils.test.ts +320 -20
- package/src/sidebars/__tests__/validation.test.ts +105 -0
- package/src/sidebars/generator.ts +82 -19
- package/src/sidebars/index.ts +23 -13
- package/src/sidebars/normalization.ts +47 -23
- package/src/sidebars/processor.ts +57 -27
- package/src/sidebars/types.ts +64 -3
- package/src/sidebars/utils.ts +217 -42
- package/src/sidebars/validation.ts +52 -8
- package/src/slug.ts +32 -17
- package/src/translations.ts +74 -8
- package/src/types.ts +22 -5
package/src/docs.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
10
|
import chalk from 'chalk';
|
|
11
|
-
import {keyBy} from 'lodash';
|
|
11
|
+
import {keyBy, last} from 'lodash';
|
|
12
12
|
import {
|
|
13
13
|
aliasedSitePath,
|
|
14
14
|
getEditUrl,
|
|
@@ -38,8 +38,11 @@ import {CURRENT_VERSION_NAME} from './constants';
|
|
|
38
38
|
import {getDocsDirPaths} from './versions';
|
|
39
39
|
import {stripPathNumberPrefixes} from './numberPrefix';
|
|
40
40
|
import {validateDocFrontMatter} from './docFrontMatter';
|
|
41
|
-
import
|
|
42
|
-
|
|
41
|
+
import {
|
|
42
|
+
SidebarsUtils,
|
|
43
|
+
toDocNavigationLink,
|
|
44
|
+
toNavigationLink,
|
|
45
|
+
} from './sidebars/utils';
|
|
43
46
|
|
|
44
47
|
type LastUpdateOptions = Pick<
|
|
45
48
|
PluginOptions,
|
|
@@ -205,7 +208,8 @@ function doProcessDocMetadata({
|
|
|
205
208
|
? '/'
|
|
206
209
|
: getSlug({
|
|
207
210
|
baseID,
|
|
208
|
-
|
|
211
|
+
source,
|
|
212
|
+
sourceDirName,
|
|
209
213
|
frontmatterSlug: frontMatter.slug,
|
|
210
214
|
stripDirNumberPrefixes: parseNumberPrefixes,
|
|
211
215
|
numberPrefixParser: options.numberPrefixParser,
|
|
@@ -291,68 +295,76 @@ export function processDocMetadata(args: {
|
|
|
291
295
|
}
|
|
292
296
|
}
|
|
293
297
|
|
|
294
|
-
export function
|
|
298
|
+
export function addDocNavigation(
|
|
295
299
|
docsBase: DocMetadataBase[],
|
|
296
|
-
|
|
300
|
+
sidebarsUtils: SidebarsUtils,
|
|
297
301
|
sidebarFilePath: string,
|
|
298
|
-
):
|
|
299
|
-
const
|
|
300
|
-
const {checkSidebarsDocIds, getDocNavigation, getFirstDocIdOfFirstSidebar} =
|
|
301
|
-
createSidebarsUtils(sidebars);
|
|
302
|
+
): LoadedVersion['docs'] {
|
|
303
|
+
const docsById = createDocsByIdIndex(docsBase);
|
|
302
304
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
+
sidebarsUtils.checkSidebarsDocIds(
|
|
306
|
+
docsBase.flatMap(getDocIds),
|
|
307
|
+
sidebarFilePath,
|
|
308
|
+
);
|
|
305
309
|
|
|
306
310
|
// Add sidebar/next/previous to the docs
|
|
307
311
|
function addNavData(doc: DocMetadataBase): DocMetadata {
|
|
308
|
-
const
|
|
309
|
-
|
|
312
|
+
const navigation = sidebarsUtils.getDocNavigation(
|
|
313
|
+
doc.unversionedId,
|
|
314
|
+
doc.id,
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
const toNavigationLinkByDocId = (
|
|
310
318
|
docId: string | null | undefined,
|
|
311
319
|
type: 'prev' | 'next',
|
|
312
320
|
): DocNavLink | undefined => {
|
|
313
321
|
if (!docId) {
|
|
314
322
|
return undefined;
|
|
315
323
|
}
|
|
316
|
-
|
|
324
|
+
const navDoc = docsById[docId];
|
|
325
|
+
if (!navDoc) {
|
|
317
326
|
// This could only happen if user provided the ID through front matter
|
|
318
327
|
throw new Error(
|
|
319
328
|
`Error when loading ${doc.id} in ${doc.sourceDirName}: the pagination_${type} front matter points to a non-existent ID ${docId}.`,
|
|
320
329
|
);
|
|
321
330
|
}
|
|
322
|
-
|
|
323
|
-
title,
|
|
324
|
-
permalink,
|
|
325
|
-
frontMatter: {
|
|
326
|
-
pagination_label: paginationLabel,
|
|
327
|
-
sidebar_label: sidebarLabel,
|
|
328
|
-
},
|
|
329
|
-
} = docsBaseById[docId];
|
|
330
|
-
return {title: paginationLabel ?? sidebarLabel ?? title, permalink};
|
|
331
|
+
return toDocNavigationLink(navDoc);
|
|
331
332
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
return {...doc, sidebar: sidebarName, previous, next};
|
|
333
|
+
|
|
334
|
+
const previous: DocNavLink | undefined = doc.frontMatter.pagination_prev
|
|
335
|
+
? toNavigationLinkByDocId(doc.frontMatter.pagination_prev, 'prev')
|
|
336
|
+
: toNavigationLink(navigation.previous, docsById);
|
|
337
|
+
const next: DocNavLink | undefined = doc.frontMatter.pagination_next
|
|
338
|
+
? toNavigationLinkByDocId(doc.frontMatter.pagination_next, 'next')
|
|
339
|
+
: toNavigationLink(navigation.next, docsById);
|
|
340
|
+
|
|
341
|
+
return {...doc, sidebar: navigation.sidebarName, previous, next};
|
|
341
342
|
}
|
|
342
|
-
|
|
343
|
+
|
|
344
|
+
const docsWithNavigation = docsBase.map(addNavData);
|
|
343
345
|
// sort to ensure consistent output for tests
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
346
|
+
docsWithNavigation.sort((a, b) => a.id.localeCompare(b.id));
|
|
347
|
+
return docsWithNavigation;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* The "main doc" is the "version entry point"
|
|
352
|
+
* We browse this doc by clicking on a version:
|
|
353
|
+
* - the "home" doc (at '/docs/')
|
|
354
|
+
* - the first doc of the first sidebar
|
|
355
|
+
* - a random doc (if no docs are in any sidebar... edge case)
|
|
356
|
+
*/
|
|
357
|
+
export function getMainDocId({
|
|
358
|
+
docs,
|
|
359
|
+
sidebarsUtils,
|
|
360
|
+
}: {
|
|
361
|
+
docs: DocMetadataBase[];
|
|
362
|
+
sidebarsUtils: SidebarsUtils;
|
|
363
|
+
}): string {
|
|
353
364
|
function getMainDoc(): DocMetadata {
|
|
354
365
|
const versionHomeDoc = docs.find((doc) => doc.slug === '/');
|
|
355
|
-
const firstDocIdOfFirstSidebar =
|
|
366
|
+
const firstDocIdOfFirstSidebar =
|
|
367
|
+
sidebarsUtils.getFirstDocIdOfFirstSidebar();
|
|
356
368
|
if (versionHomeDoc) {
|
|
357
369
|
return versionHomeDoc;
|
|
358
370
|
} else if (firstDocIdOfFirstSidebar) {
|
|
@@ -362,5 +374,51 @@ export function handleNavigation(
|
|
|
362
374
|
}
|
|
363
375
|
}
|
|
364
376
|
|
|
365
|
-
return
|
|
377
|
+
return getMainDoc().unversionedId;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function getLastPathSegment(str: string): string {
|
|
381
|
+
return last(str.split('/'))!;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// By convention, Docusaurus considers some docs are "indexes":
|
|
385
|
+
// - index.md
|
|
386
|
+
// - readme.md
|
|
387
|
+
// - <folder>/<folder>.md
|
|
388
|
+
//
|
|
389
|
+
// Those index docs produce a different behavior
|
|
390
|
+
// - Slugs do not end with a weird "/index" suffix
|
|
391
|
+
// - Auto-generated sidebar categories link to them as intro
|
|
392
|
+
export function isConventionalDocIndex(doc: {
|
|
393
|
+
source: DocMetadataBase['slug'];
|
|
394
|
+
sourceDirName: DocMetadataBase['sourceDirName'];
|
|
395
|
+
}): boolean {
|
|
396
|
+
// "@site/docs/folder/subFolder/subSubFolder/myDoc.md" => "myDoc"
|
|
397
|
+
const docName = path.parse(doc.source).name;
|
|
398
|
+
|
|
399
|
+
// "folder/subFolder/subSubFolder" => "subSubFolder"
|
|
400
|
+
const lastDirName = getLastPathSegment(doc.sourceDirName);
|
|
401
|
+
|
|
402
|
+
const eligibleDocIndexNames = ['index', 'readme', lastDirName.toLowerCase()];
|
|
403
|
+
|
|
404
|
+
return eligibleDocIndexNames.includes(docName.toLowerCase());
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Return both doc ids
|
|
408
|
+
// TODO legacy retro-compatibility due to old versioned sidebars using versioned doc ids
|
|
409
|
+
// ("id" should be removed & "versionedId" should be renamed to "id")
|
|
410
|
+
export function getDocIds(doc: DocMetadataBase): [string, string] {
|
|
411
|
+
return [doc.unversionedId, doc.id];
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// docs are indexed by both versioned and unversioned ids at the same time
|
|
415
|
+
// TODO legacy retro-compatibility due to old versioned sidebars using versioned doc ids
|
|
416
|
+
// ("id" should be removed & "versionedId" should be renamed to "id")
|
|
417
|
+
export function createDocsByIdIndex<
|
|
418
|
+
Doc extends {id: string; unversionedId: string},
|
|
419
|
+
>(docs: Doc[]): Record<string, Doc> {
|
|
420
|
+
return {
|
|
421
|
+
...keyBy(docs, (doc) => doc.unversionedId),
|
|
422
|
+
...keyBy(docs, (doc) => doc.id),
|
|
423
|
+
};
|
|
366
424
|
}
|
package/src/index.ts
CHANGED
|
@@ -16,11 +16,17 @@ import {
|
|
|
16
16
|
posixPath,
|
|
17
17
|
addTrailingPathSeparator,
|
|
18
18
|
createAbsoluteFilePathMatcher,
|
|
19
|
+
createSlugger,
|
|
19
20
|
} from '@docusaurus/utils';
|
|
20
|
-
import type {LoadContext, Plugin
|
|
21
|
+
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
21
22
|
import {loadSidebars} from './sidebars';
|
|
22
23
|
import {CategoryMetadataFilenamePattern} from './sidebars/generator';
|
|
23
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
readVersionDocs,
|
|
26
|
+
processDocMetadata,
|
|
27
|
+
addDocNavigation,
|
|
28
|
+
getMainDocId,
|
|
29
|
+
} from './docs';
|
|
24
30
|
import {getDocsDirPaths, readVersionsMetadata} from './versions';
|
|
25
31
|
|
|
26
32
|
import {
|
|
@@ -28,7 +34,6 @@ import {
|
|
|
28
34
|
LoadedContent,
|
|
29
35
|
SourceToPermalink,
|
|
30
36
|
DocMetadataBase,
|
|
31
|
-
DocMetadata,
|
|
32
37
|
GlobalPluginData,
|
|
33
38
|
VersionMetadata,
|
|
34
39
|
LoadedVersion,
|
|
@@ -41,14 +46,17 @@ import {cliDocsVersionCommand} from './cli';
|
|
|
41
46
|
import {VERSIONS_JSON_FILE} from './constants';
|
|
42
47
|
import {keyBy, mapValues} from 'lodash';
|
|
43
48
|
import {toGlobalDataVersion} from './globalData';
|
|
44
|
-
import {toTagDocListProp
|
|
49
|
+
import {toTagDocListProp} from './props';
|
|
45
50
|
import {
|
|
46
51
|
translateLoadedContent,
|
|
47
52
|
getLoadedContentTranslationFiles,
|
|
48
53
|
} from './translations';
|
|
49
54
|
import chalk from 'chalk';
|
|
50
55
|
import {getVersionTags} from './tags';
|
|
56
|
+
import {createVersionRoutes} from './routes';
|
|
51
57
|
import type {PropTagsListPage} from '@docusaurus/plugin-content-docs';
|
|
58
|
+
import {createSidebarsUtils} from './sidebars/utils';
|
|
59
|
+
import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
|
|
52
60
|
|
|
53
61
|
export default function pluginContentDocs(
|
|
54
62
|
context: LoadContext,
|
|
@@ -157,28 +165,37 @@ export default function pluginContentDocs(
|
|
|
157
165
|
async function doLoadVersion(
|
|
158
166
|
versionMetadata: VersionMetadata,
|
|
159
167
|
): Promise<LoadedVersion> {
|
|
160
|
-
const
|
|
168
|
+
const docs: DocMetadataBase[] = await loadVersionDocsBase(
|
|
161
169
|
versionMetadata,
|
|
162
170
|
);
|
|
163
171
|
|
|
164
172
|
const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, {
|
|
165
173
|
sidebarItemsGenerator: options.sidebarItemsGenerator,
|
|
166
174
|
numberPrefixParser: options.numberPrefixParser,
|
|
167
|
-
docs
|
|
175
|
+
docs,
|
|
168
176
|
version: versionMetadata,
|
|
169
|
-
|
|
177
|
+
sidebarOptions: {
|
|
170
178
|
sidebarCollapsed: options.sidebarCollapsed,
|
|
171
179
|
sidebarCollapsible: options.sidebarCollapsible,
|
|
172
180
|
},
|
|
181
|
+
categoryLabelSlugger: createSlugger(),
|
|
173
182
|
});
|
|
183
|
+
|
|
184
|
+
const sidebarsUtils = createSidebarsUtils(sidebars);
|
|
185
|
+
|
|
174
186
|
return {
|
|
175
187
|
...versionMetadata,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
188
|
+
docs: addDocNavigation(
|
|
189
|
+
docs,
|
|
190
|
+
sidebarsUtils,
|
|
179
191
|
versionMetadata.sidebarFilePath as string,
|
|
180
192
|
),
|
|
181
193
|
sidebars,
|
|
194
|
+
mainDocId: getMainDocId({docs, sidebarsUtils}),
|
|
195
|
+
categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
|
|
196
|
+
docs,
|
|
197
|
+
sidebarsUtils,
|
|
198
|
+
}),
|
|
182
199
|
};
|
|
183
200
|
}
|
|
184
201
|
|
|
@@ -206,45 +223,17 @@ export default function pluginContentDocs(
|
|
|
206
223
|
|
|
207
224
|
async contentLoaded({content, actions}) {
|
|
208
225
|
const {loadedVersions} = content;
|
|
209
|
-
const {
|
|
226
|
+
const {
|
|
227
|
+
docLayoutComponent,
|
|
228
|
+
docItemComponent,
|
|
229
|
+
docCategoryGeneratedIndexComponent,
|
|
230
|
+
} = options;
|
|
210
231
|
const {addRoute, createData, setGlobalData} = actions;
|
|
211
232
|
|
|
212
|
-
|
|
213
|
-
docs
|
|
214
|
-
): Promise<RouteConfig[]> => {
|
|
215
|
-
const routes = await Promise.all(
|
|
216
|
-
docs.map(async (metadataItem) => {
|
|
217
|
-
await createData(
|
|
218
|
-
// Note that this created data path must be in sync with
|
|
219
|
-
// metadataPath provided to mdx-loader.
|
|
220
|
-
`${docuHash(metadataItem.source)}.json`,
|
|
221
|
-
JSON.stringify(metadataItem, null, 2),
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
const docRoute: RouteConfig = {
|
|
225
|
-
path: metadataItem.permalink,
|
|
226
|
-
component: docItemComponent,
|
|
227
|
-
exact: true,
|
|
228
|
-
modules: {
|
|
229
|
-
content: metadataItem.source,
|
|
230
|
-
},
|
|
231
|
-
// Because the parent (DocPage) comp need to access it easily
|
|
232
|
-
// This permits to render the sidebar once without unmount/remount when navigating (and preserve sidebar state)
|
|
233
|
-
...(metadataItem.sidebar && {
|
|
234
|
-
sidebar: metadataItem.sidebar,
|
|
235
|
-
}),
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
return docRoute;
|
|
239
|
-
}),
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
return routes.sort((a, b) => a.path.localeCompare(b.path));
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
async function createVersionTagsRoutes(loadedVersion: LoadedVersion) {
|
|
246
|
-
const versionTags = getVersionTags(loadedVersion.docs);
|
|
233
|
+
async function createVersionTagsRoutes(version: LoadedVersion) {
|
|
234
|
+
const versionTags = getVersionTags(version.docs);
|
|
247
235
|
|
|
236
|
+
// TODO tags should be a sub route of the version route
|
|
248
237
|
async function createTagsListPage() {
|
|
249
238
|
const tagsProp: PropTagsListPage['tags'] = Object.values(
|
|
250
239
|
versionTags,
|
|
@@ -257,11 +246,11 @@ export default function pluginContentDocs(
|
|
|
257
246
|
// Only create /tags page if there are tags.
|
|
258
247
|
if (Object.keys(tagsProp).length > 0) {
|
|
259
248
|
const tagsPropPath = await createData(
|
|
260
|
-
`${docuHash(`tags-list-${
|
|
249
|
+
`${docuHash(`tags-list-${version.versionName}-prop`)}.json`,
|
|
261
250
|
JSON.stringify(tagsProp, null, 2),
|
|
262
251
|
);
|
|
263
252
|
addRoute({
|
|
264
|
-
path:
|
|
253
|
+
path: version.tagsPath,
|
|
265
254
|
exact: true,
|
|
266
255
|
component: options.docTagsListComponent,
|
|
267
256
|
modules: {
|
|
@@ -271,11 +260,12 @@ export default function pluginContentDocs(
|
|
|
271
260
|
}
|
|
272
261
|
}
|
|
273
262
|
|
|
263
|
+
// TODO tags should be a sub route of the version route
|
|
274
264
|
async function createTagDocListPage(tag: VersionTag) {
|
|
275
265
|
const tagProps = toTagDocListProp({
|
|
276
|
-
allTagsPath:
|
|
266
|
+
allTagsPath: version.tagsPath,
|
|
277
267
|
tag,
|
|
278
|
-
docs:
|
|
268
|
+
docs: version.docs,
|
|
279
269
|
});
|
|
280
270
|
const tagPropPath = await createData(
|
|
281
271
|
`${docuHash(`tag-${tag.permalink}`)}.json`,
|
|
@@ -295,50 +285,22 @@ export default function pluginContentDocs(
|
|
|
295
285
|
await Promise.all(Object.values(versionTags).map(createTagDocListPage));
|
|
296
286
|
}
|
|
297
287
|
|
|
298
|
-
|
|
299
|
-
loadedVersion
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
addRoute({
|
|
312
|
-
path: loadedVersion.versionPath,
|
|
313
|
-
// allow matching /docs/* as well
|
|
314
|
-
exact: false,
|
|
315
|
-
// main docs component (DocPage)
|
|
316
|
-
component: docLayoutComponent,
|
|
317
|
-
// sub-routes for each doc
|
|
318
|
-
routes: await createDocRoutes(loadedVersion.docs),
|
|
319
|
-
modules: {
|
|
320
|
-
versionMetadata: aliasedSource(versionMetadataPropPath),
|
|
321
|
-
},
|
|
322
|
-
priority: loadedVersion.routePriority,
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
async function createVersionRoutes(
|
|
327
|
-
loadedVersion: LoadedVersion,
|
|
328
|
-
): Promise<void> {
|
|
329
|
-
try {
|
|
330
|
-
return await doCreateVersionRoutes(loadedVersion);
|
|
331
|
-
} catch (e) {
|
|
332
|
-
console.error(
|
|
333
|
-
chalk.red(
|
|
334
|
-
`Can't create version routes for version "${loadedVersion.versionName}"`,
|
|
335
|
-
),
|
|
336
|
-
);
|
|
337
|
-
throw e;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
288
|
+
await Promise.all(
|
|
289
|
+
loadedVersions.map((loadedVersion) =>
|
|
290
|
+
createVersionRoutes({
|
|
291
|
+
loadedVersion,
|
|
292
|
+
docItemComponent,
|
|
293
|
+
docLayoutComponent,
|
|
294
|
+
docCategoryGeneratedIndexComponent,
|
|
295
|
+
pluginId,
|
|
296
|
+
aliasedSource,
|
|
297
|
+
actions,
|
|
298
|
+
}),
|
|
299
|
+
),
|
|
300
|
+
);
|
|
340
301
|
|
|
341
|
-
|
|
302
|
+
// TODO tags should be a sub route of the version route
|
|
303
|
+
await Promise.all(loadedVersions.map(createVersionTagsRoutes));
|
|
342
304
|
|
|
343
305
|
setGlobalData<GlobalPluginData>({
|
|
344
306
|
path: normalizeUrl([baseUrl, options.routeBasePath]),
|
package/src/options.ts
CHANGED
|
@@ -39,6 +39,7 @@ export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
|
|
|
39
39
|
docItemComponent: '@theme/DocItem',
|
|
40
40
|
docTagDocListComponent: '@theme/DocTagDocListPage',
|
|
41
41
|
docTagsListComponent: '@theme/DocTagsListPage',
|
|
42
|
+
docCategoryGeneratedIndexComponent: '@theme/DocCategoryGeneratedIndexPage',
|
|
42
43
|
remarkPlugins: [],
|
|
43
44
|
rehypePlugins: [],
|
|
44
45
|
beforeDefaultRemarkPlugins: [],
|
|
@@ -109,6 +110,9 @@ export const OptionsSchema = Joi.object({
|
|
|
109
110
|
docTagDocListComponent: Joi.string().default(
|
|
110
111
|
DEFAULT_OPTIONS.docTagDocListComponent,
|
|
111
112
|
),
|
|
113
|
+
docCategoryGeneratedIndexComponent: Joi.string().default(
|
|
114
|
+
DEFAULT_OPTIONS.docCategoryGeneratedIndexComponent,
|
|
115
|
+
),
|
|
112
116
|
remarkPlugins: RemarkPluginsSchema.default(DEFAULT_OPTIONS.remarkPlugins),
|
|
113
117
|
rehypePlugins: RehypePluginsSchema.default(DEFAULT_OPTIONS.rehypePlugins),
|
|
114
118
|
beforeDefaultRemarkPlugins: RemarkPluginsSchema.default(
|
|
@@ -15,6 +15,18 @@ declare module '@docusaurus/plugin-content-docs' {
|
|
|
15
15
|
|
|
16
16
|
export type {GlobalDataVersion, GlobalDataDoc};
|
|
17
17
|
|
|
18
|
+
export type PropNavigationLink = {
|
|
19
|
+
readonly title: string;
|
|
20
|
+
readonly permalink: string;
|
|
21
|
+
};
|
|
22
|
+
export type PropNavigation = {
|
|
23
|
+
readonly previous?: PropNavigationLink;
|
|
24
|
+
readonly next?: PropNavigationLink;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type PropVersionDoc = import('./sidebars/types').PropVersionDoc;
|
|
28
|
+
export type PropVersionDocs = import('./sidebars/types').PropVersionDocs;
|
|
29
|
+
|
|
18
30
|
export type PropVersionMetadata = {
|
|
19
31
|
pluginId: string;
|
|
20
32
|
version: string;
|
|
@@ -24,12 +36,23 @@ declare module '@docusaurus/plugin-content-docs' {
|
|
|
24
36
|
className: string;
|
|
25
37
|
isLast: boolean;
|
|
26
38
|
docsSidebars: PropSidebars;
|
|
39
|
+
docs: PropVersionDocs;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type PropCategoryGeneratedIndex = {
|
|
43
|
+
title: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
slug: string;
|
|
46
|
+
permalink: string;
|
|
47
|
+
navigation: PropNavigation;
|
|
27
48
|
};
|
|
28
49
|
|
|
29
|
-
export type PropSidebarItemLink =
|
|
50
|
+
export type PropSidebarItemLink =
|
|
51
|
+
import('./sidebars/types').PropSidebarItemLink;
|
|
30
52
|
export type PropSidebarItemCategory =
|
|
31
53
|
import('./sidebars/types').PropSidebarItemCategory;
|
|
32
54
|
export type PropSidebarItem = import('./sidebars/types').PropSidebarItem;
|
|
55
|
+
export type PropSidebar = import('./sidebars/types').PropSidebar;
|
|
33
56
|
export type PropSidebars = import('./sidebars/types').PropSidebars;
|
|
34
57
|
|
|
35
58
|
export type PropTagDocListDoc = {
|
|
@@ -56,7 +79,10 @@ declare module '@docusaurus/plugin-content-docs' {
|
|
|
56
79
|
|
|
57
80
|
declare module '@theme/DocItem' {
|
|
58
81
|
import type {TOCItem} from '@docusaurus/types';
|
|
59
|
-
import type {
|
|
82
|
+
import type {
|
|
83
|
+
PropNavigationLink,
|
|
84
|
+
PropVersionMetadata,
|
|
85
|
+
} from '@docusaurus/plugin-content-docs';
|
|
60
86
|
|
|
61
87
|
export type DocumentRoute = {
|
|
62
88
|
readonly component: () => JSX.Element;
|
|
@@ -85,8 +111,8 @@ declare module '@theme/DocItem' {
|
|
|
85
111
|
readonly formattedLastUpdatedAt?: string;
|
|
86
112
|
readonly lastUpdatedBy?: string;
|
|
87
113
|
readonly version?: string;
|
|
88
|
-
readonly previous?:
|
|
89
|
-
readonly next?:
|
|
114
|
+
readonly previous?: PropNavigationLink;
|
|
115
|
+
readonly next?: PropNavigationLink;
|
|
90
116
|
readonly tags: readonly {
|
|
91
117
|
readonly label: string;
|
|
92
118
|
readonly permalink: string;
|
|
@@ -109,6 +135,38 @@ declare module '@theme/DocItem' {
|
|
|
109
135
|
export default DocItem;
|
|
110
136
|
}
|
|
111
137
|
|
|
138
|
+
declare module '@theme/DocCard' {
|
|
139
|
+
import type {PropSidebarItem} from '@docusaurus/plugin-content-docs';
|
|
140
|
+
|
|
141
|
+
export interface Props {
|
|
142
|
+
readonly item: PropSidebarItem;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export default function DocCard(props: Props): JSX.Element;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
declare module '@theme/DocCardList' {
|
|
149
|
+
import type {PropSidebarItem} from '@docusaurus/plugin-content-docs';
|
|
150
|
+
|
|
151
|
+
export interface Props {
|
|
152
|
+
readonly items: PropSidebarItem[];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export default function DocCardList(props: Props): JSX.Element;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
declare module '@theme/DocCategoryGeneratedIndexPage' {
|
|
159
|
+
import type {PropCategoryGeneratedIndex} from '@docusaurus/plugin-content-docs';
|
|
160
|
+
|
|
161
|
+
export interface Props {
|
|
162
|
+
readonly categoryGeneratedIndex: PropCategoryGeneratedIndex;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default function DocCategoryGeneratedIndexPage(
|
|
166
|
+
props: Props,
|
|
167
|
+
): JSX.Element;
|
|
168
|
+
}
|
|
169
|
+
|
|
112
170
|
declare module '@theme/DocItemFooter' {
|
|
113
171
|
import type {Props} from '@theme/DocItem';
|
|
114
172
|
|
|
@@ -132,14 +190,19 @@ declare module '@theme/DocTagDocListPage' {
|
|
|
132
190
|
}
|
|
133
191
|
|
|
134
192
|
declare module '@theme/DocVersionBanner' {
|
|
135
|
-
|
|
193
|
+
export interface Props {
|
|
194
|
+
readonly className?: string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export default function DocVersionBanner(props: Props): JSX.Element;
|
|
198
|
+
}
|
|
136
199
|
|
|
200
|
+
declare module '@theme/DocVersionBadge' {
|
|
137
201
|
export interface Props {
|
|
138
|
-
readonly
|
|
202
|
+
readonly className?: string;
|
|
139
203
|
}
|
|
140
204
|
|
|
141
|
-
|
|
142
|
-
export default DocVersionBanner;
|
|
205
|
+
export default function DocVersionBadge(props: Props): JSX.Element;
|
|
143
206
|
}
|
|
144
207
|
|
|
145
208
|
declare module '@theme/DocPage' {
|