@docusaurus/plugin-content-docs 2.0.0-beta.16 → 2.0.0-beta.19
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/categoryGeneratedIndex.d.ts +1 -1
- package/lib/categoryGeneratedIndex.js +5 -7
- package/lib/cli.d.ts +3 -2
- package/lib/cli.js +49 -41
- package/lib/client/docsClientUtils.d.ts +8 -5
- package/lib/client/docsClientUtils.js +13 -15
- package/lib/client/index.d.ts +12 -9
- package/lib/client/index.js +30 -33
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +8 -15
- package/lib/docs.js +34 -39
- package/lib/{docFrontMatter.d.ts → frontMatter.d.ts} +4 -2
- package/lib/{docFrontMatter.js → frontMatter.js} +3 -0
- package/lib/globalData.d.ts +3 -7
- package/lib/globalData.js +9 -13
- package/lib/index.d.ts +1 -2
- package/lib/index.js +33 -26
- package/lib/lastUpdate.d.ts +4 -6
- package/lib/lastUpdate.js +14 -5
- package/lib/markdown/index.js +1 -1
- package/lib/markdown/linkify.js +5 -2
- package/lib/numberPrefix.js +16 -22
- package/lib/options.d.ts +3 -5
- package/lib/options.js +6 -5
- package/lib/props.d.ts +3 -3
- package/lib/props.js +10 -10
- package/lib/routes.d.ts +5 -4
- package/lib/routes.js +10 -24
- package/lib/server-export.d.ts +2 -1
- package/lib/server-export.js +3 -4
- package/lib/sidebars/generator.js +63 -44
- package/lib/sidebars/index.js +20 -16
- package/lib/sidebars/normalization.js +3 -3
- package/lib/sidebars/postProcessor.js +18 -25
- package/lib/sidebars/processor.d.ts +3 -1
- package/lib/sidebars/processor.js +17 -6
- package/lib/sidebars/types.d.ts +31 -19
- package/lib/sidebars/utils.d.ts +17 -6
- package/lib/sidebars/utils.js +27 -37
- package/lib/sidebars/validation.d.ts +3 -1
- package/lib/sidebars/validation.js +1 -0
- package/lib/slug.d.ts +1 -2
- package/lib/slug.js +4 -5
- package/lib/tags.d.ts +2 -1
- package/lib/tags.js +2 -2
- package/lib/translations.d.ts +3 -3
- package/lib/translations.js +28 -81
- package/lib/types.d.ts +10 -95
- package/lib/versions/files.d.ts +44 -0
- package/lib/versions/files.js +142 -0
- package/lib/versions/index.d.ts +36 -0
- package/lib/versions/index.js +155 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +71 -0
- package/package.json +14 -12
- package/src/categoryGeneratedIndex.ts +10 -9
- package/src/cli.ts +64 -69
- package/src/client/docsClientUtils.ts +14 -16
- package/src/client/index.ts +42 -43
- package/src/constants.ts +4 -2
- package/src/deps.d.ts +1 -1
- package/src/docs.ts +48 -51
- package/src/{docFrontMatter.ts → frontMatter.ts} +9 -6
- package/src/globalData.ts +15 -16
- package/src/index.ts +45 -40
- package/src/lastUpdate.ts +20 -8
- package/src/markdown/index.ts +1 -3
- package/src/markdown/linkify.ts +6 -3
- package/src/numberPrefix.ts +18 -28
- package/src/options.ts +6 -8
- package/src/plugin-content-docs.d.ts +457 -116
- package/src/props.ts +12 -9
- package/src/routes.ts +13 -39
- package/src/server-export.ts +1 -3
- package/src/sidebars/generator.ts +88 -59
- package/src/sidebars/index.ts +20 -15
- package/src/sidebars/normalization.ts +1 -1
- package/src/sidebars/postProcessor.ts +6 -11
- package/src/sidebars/processor.ts +27 -14
- package/src/sidebars/types.ts +25 -23
- package/src/sidebars/utils.ts +45 -46
- package/src/sidebars/validation.ts +4 -3
- package/src/slug.ts +7 -6
- package/src/tags.ts +3 -2
- package/src/translations.ts +32 -84
- package/src/types.ts +15 -107
- package/src/versions/files.ts +220 -0
- package/src/versions/index.ts +247 -0
- package/src/versions/validation.ts +113 -0
- package/lib/versions.d.ts +0 -41
- package/lib/versions.js +0 -329
- package/src/versions.ts +0 -606
package/src/sidebars/types.ts
CHANGED
|
@@ -6,20 +6,21 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type {Optional, Required} from 'utility-types';
|
|
9
|
-
import type {DocMetadataBase, VersionMetadata} from '../types';
|
|
10
9
|
import type {
|
|
11
10
|
NumberPrefixParser,
|
|
12
11
|
SidebarOptions,
|
|
13
12
|
CategoryIndexMatcher,
|
|
13
|
+
DocMetadataBase,
|
|
14
|
+
VersionMetadata,
|
|
14
15
|
} from '@docusaurus/plugin-content-docs';
|
|
15
16
|
import type {Slugger} from '@docusaurus/utils';
|
|
16
17
|
|
|
17
18
|
// Makes all properties visible when hovering over the type
|
|
18
|
-
type Expand<T extends
|
|
19
|
+
type Expand<T extends {[x: string]: unknown}> = {[P in keyof T]: T[P]};
|
|
19
20
|
|
|
20
21
|
export type SidebarItemBase = {
|
|
21
22
|
className?: string;
|
|
22
|
-
customProps?:
|
|
23
|
+
customProps?: {[key: string]: unknown};
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
export type SidebarItemDoc = SidebarItemBase & {
|
|
@@ -179,7 +180,6 @@ export type PropSidebarItemCategory = Expand<
|
|
|
179
180
|
}
|
|
180
181
|
>;
|
|
181
182
|
|
|
182
|
-
// we may want to use a union type in props instead of this generic link?
|
|
183
183
|
export type PropSidebarItemLink = SidebarItemLink & {
|
|
184
184
|
docId?: string;
|
|
185
185
|
};
|
|
@@ -199,16 +199,6 @@ export type PropSidebarBreadcrumbsItem =
|
|
|
199
199
|
| PropSidebarItemLink
|
|
200
200
|
| PropSidebarItemCategory;
|
|
201
201
|
|
|
202
|
-
export type PropVersionDoc = {
|
|
203
|
-
id: string;
|
|
204
|
-
title: string;
|
|
205
|
-
description?: string;
|
|
206
|
-
sidebar?: string;
|
|
207
|
-
};
|
|
208
|
-
export type PropVersionDocs = {
|
|
209
|
-
[docId: string]: PropVersionDoc;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
202
|
export type CategoryMetadataFile = {
|
|
213
203
|
label?: string;
|
|
214
204
|
position?: number;
|
|
@@ -216,6 +206,7 @@ export type CategoryMetadataFile = {
|
|
|
216
206
|
collapsible?: boolean;
|
|
217
207
|
className?: string;
|
|
218
208
|
link?: SidebarItemCategoryLinkConfig | null;
|
|
209
|
+
customProps?: {[key: string]: unknown};
|
|
219
210
|
|
|
220
211
|
// TODO should we allow "items" here? how would this work? would an
|
|
221
212
|
// "autogenerated" type be allowed?
|
|
@@ -230,6 +221,7 @@ export type SidebarItemsGeneratorDoc = Pick<
|
|
|
230
221
|
DocMetadataBase,
|
|
231
222
|
| 'id'
|
|
232
223
|
| 'unversionedId'
|
|
224
|
+
| 'title'
|
|
233
225
|
| 'frontMatter'
|
|
234
226
|
| 'source'
|
|
235
227
|
| 'sourceDirName'
|
|
@@ -241,32 +233,42 @@ export type SidebarItemsGeneratorVersion = Pick<
|
|
|
241
233
|
>;
|
|
242
234
|
|
|
243
235
|
export type SidebarItemsGeneratorArgs = {
|
|
236
|
+
/** The sidebar item with type "autogenerated" to be transformed. */
|
|
244
237
|
item: SidebarItemAutogenerated;
|
|
238
|
+
/** Useful metadata for the version this sidebar belongs to. */
|
|
245
239
|
version: SidebarItemsGeneratorVersion;
|
|
240
|
+
/** All the docs of that version (unfiltered). */
|
|
246
241
|
docs: SidebarItemsGeneratorDoc[];
|
|
242
|
+
/** Number prefix parser configured for this plugin. */
|
|
247
243
|
numberPrefixParser: NumberPrefixParser;
|
|
244
|
+
/** The default category index matcher which you can override. */
|
|
248
245
|
isCategoryIndex: CategoryIndexMatcher;
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
/**
|
|
247
|
+
* Key is the path relative to the doc content directory, value is the
|
|
248
|
+
* category metadata file's content.
|
|
249
|
+
*/
|
|
250
|
+
categoriesMetadata: {[filePath: string]: CategoryMetadataFile};
|
|
251
251
|
};
|
|
252
252
|
export type SidebarItemsGenerator = (
|
|
253
253
|
generatorArgs: SidebarItemsGeneratorArgs,
|
|
254
254
|
) => Promise<NormalizedSidebar>;
|
|
255
255
|
|
|
256
|
-
// Also inject the default generator to conveniently wrap/enhance/sort the
|
|
257
|
-
// default sidebar gen logic
|
|
258
|
-
// see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
|
|
259
|
-
export type SidebarItemsGeneratorOptionArgs = {
|
|
260
|
-
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
261
|
-
} & SidebarItemsGeneratorArgs;
|
|
262
256
|
export type SidebarItemsGeneratorOption = (
|
|
263
|
-
generatorArgs:
|
|
257
|
+
generatorArgs: {
|
|
258
|
+
/**
|
|
259
|
+
* Useful to re-use/enhance the default sidebar generation logic from
|
|
260
|
+
* Docusaurus.
|
|
261
|
+
* @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
|
|
262
|
+
*/
|
|
263
|
+
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
264
|
+
} & SidebarItemsGeneratorArgs,
|
|
264
265
|
) => Promise<NormalizedSidebarItem[]>;
|
|
265
266
|
|
|
266
267
|
export type SidebarProcessorParams = {
|
|
267
268
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
268
269
|
numberPrefixParser: NumberPrefixParser;
|
|
269
270
|
docs: DocMetadataBase[];
|
|
271
|
+
drafts: DocMetadataBase[];
|
|
270
272
|
version: VersionMetadata;
|
|
271
273
|
categoryLabelSlugger: Slugger;
|
|
272
274
|
sidebarOptions: SidebarOptions;
|
package/src/sidebars/utils.ts
CHANGED
|
@@ -20,8 +20,11 @@ import type {
|
|
|
20
20
|
} from './types';
|
|
21
21
|
|
|
22
22
|
import _ from 'lodash';
|
|
23
|
-
import {
|
|
24
|
-
import type {
|
|
23
|
+
import {toMessageRelativeFilePath} from '@docusaurus/utils';
|
|
24
|
+
import type {
|
|
25
|
+
DocMetadataBase,
|
|
26
|
+
PropNavigationLink,
|
|
27
|
+
} from '@docusaurus/plugin-content-docs';
|
|
25
28
|
|
|
26
29
|
export function isCategoriesShorthand(
|
|
27
30
|
item: SidebarItemConfig,
|
|
@@ -107,15 +110,15 @@ export function collectSidebarNavigation(
|
|
|
107
110
|
});
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
export function collectSidebarsDocIds(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
export function collectSidebarsDocIds(sidebars: Sidebars): {
|
|
114
|
+
[sidebarId: string]: string[];
|
|
115
|
+
} {
|
|
113
116
|
return _.mapValues(sidebars, collectSidebarDocIds);
|
|
114
117
|
}
|
|
115
118
|
|
|
116
|
-
export function collectSidebarsNavigations(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
export function collectSidebarsNavigations(sidebars: Sidebars): {
|
|
120
|
+
[sidebarId: string]: SidebarNavigationItem[];
|
|
121
|
+
} {
|
|
119
122
|
return _.mapValues(sidebars, collectSidebarNavigation);
|
|
120
123
|
}
|
|
121
124
|
|
|
@@ -139,6 +142,11 @@ export type SidebarsUtils = {
|
|
|
139
142
|
getCategoryGeneratedIndexNavigation: (
|
|
140
143
|
categoryGeneratedIndexPermalink: string,
|
|
141
144
|
) => SidebarNavigation;
|
|
145
|
+
/**
|
|
146
|
+
* This function may return undefined. This is usually a user mistake, because
|
|
147
|
+
* it means this sidebar will never be displayed; however, we can still use
|
|
148
|
+
* `displayed_sidebar` to make it displayed. Pretty weird but valid use-case
|
|
149
|
+
*/
|
|
142
150
|
getFirstLink: (sidebarId: string) =>
|
|
143
151
|
| {
|
|
144
152
|
type: 'doc';
|
|
@@ -147,7 +155,7 @@ export type SidebarsUtils = {
|
|
|
147
155
|
}
|
|
148
156
|
| {
|
|
149
157
|
type: 'generated-index';
|
|
150
|
-
|
|
158
|
+
permalink: string;
|
|
151
159
|
label: string;
|
|
152
160
|
}
|
|
153
161
|
| undefined;
|
|
@@ -201,12 +209,12 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
201
209
|
if (!sidebarName) {
|
|
202
210
|
return emptySidebarNavigation();
|
|
203
211
|
}
|
|
204
|
-
|
|
212
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
213
|
+
if (!navigationItems) {
|
|
205
214
|
throw new Error(
|
|
206
215
|
`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`,
|
|
207
216
|
);
|
|
208
217
|
}
|
|
209
|
-
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
210
218
|
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
211
219
|
if (item.type === 'doc') {
|
|
212
220
|
return item.id === docId;
|
|
@@ -220,11 +228,11 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
220
228
|
return {sidebarName, next: undefined, previous: undefined};
|
|
221
229
|
}
|
|
222
230
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
currentItemIndex,
|
|
226
|
-
|
|
227
|
-
|
|
231
|
+
return {
|
|
232
|
+
sidebarName,
|
|
233
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
234
|
+
next: navigationItems[currentItemIndex + 1],
|
|
235
|
+
};
|
|
228
236
|
}
|
|
229
237
|
|
|
230
238
|
function getCategoryGeneratedIndexList(): SidebarItemCategoryWithGeneratedIndex[] {
|
|
@@ -258,20 +266,16 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
258
266
|
const sidebarName = Object.entries(sidebarNameToNavigationItems).find(
|
|
259
267
|
([, navigationItems]) =>
|
|
260
268
|
navigationItems.find(isCurrentCategoryGeneratedIndexItem),
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
if (!sidebarName) {
|
|
264
|
-
return emptySidebarNavigation();
|
|
265
|
-
}
|
|
266
|
-
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
269
|
+
)![0];
|
|
270
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName]!;
|
|
267
271
|
const currentItemIndex = navigationItems.findIndex(
|
|
268
272
|
isCurrentCategoryGeneratedIndexItem,
|
|
269
273
|
);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
currentItemIndex,
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
return {
|
|
275
|
+
sidebarName,
|
|
276
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
277
|
+
next: navigationItems[currentItemIndex + 1],
|
|
278
|
+
};
|
|
275
279
|
}
|
|
276
280
|
|
|
277
281
|
function checkSidebarsDocIds(validDocIds: string[], sidebarFilePath: string) {
|
|
@@ -299,7 +303,7 @@ Available document ids are:
|
|
|
299
303
|
}
|
|
300
304
|
| {
|
|
301
305
|
type: 'generated-index';
|
|
302
|
-
|
|
306
|
+
permalink: string;
|
|
303
307
|
label: string;
|
|
304
308
|
}
|
|
305
309
|
| undefined {
|
|
@@ -320,7 +324,7 @@ Available document ids are:
|
|
|
320
324
|
} else if (item.link?.type === 'generated-index') {
|
|
321
325
|
return {
|
|
322
326
|
type: 'generated-index',
|
|
323
|
-
|
|
327
|
+
permalink: item.link.permalink,
|
|
324
328
|
label: item.label,
|
|
325
329
|
};
|
|
326
330
|
}
|
|
@@ -341,11 +345,11 @@ Available document ids are:
|
|
|
341
345
|
getCategoryGeneratedIndexList,
|
|
342
346
|
getCategoryGeneratedIndexNavigation,
|
|
343
347
|
checkSidebarsDocIds,
|
|
344
|
-
getFirstLink: (id) => getFirstLink(sidebars[id]),
|
|
348
|
+
getFirstLink: (id) => getFirstLink(sidebars[id]!),
|
|
345
349
|
};
|
|
346
350
|
}
|
|
347
351
|
|
|
348
|
-
export function toDocNavigationLink(doc: DocMetadataBase):
|
|
352
|
+
export function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink {
|
|
349
353
|
const {
|
|
350
354
|
title,
|
|
351
355
|
permalink,
|
|
@@ -359,8 +363,8 @@ export function toDocNavigationLink(doc: DocMetadataBase): DocNavLink {
|
|
|
359
363
|
|
|
360
364
|
export function toNavigationLink(
|
|
361
365
|
navigationItem: SidebarNavigationItem | undefined,
|
|
362
|
-
docsById:
|
|
363
|
-
):
|
|
366
|
+
docsById: {[docId: string]: DocMetadataBase},
|
|
367
|
+
): PropNavigationLink | undefined {
|
|
364
368
|
function getDocById(docId: string) {
|
|
365
369
|
const doc = docsById[docId];
|
|
366
370
|
if (!doc) {
|
|
@@ -375,18 +379,13 @@ export function toNavigationLink(
|
|
|
375
379
|
return undefined;
|
|
376
380
|
}
|
|
377
381
|
|
|
378
|
-
if (navigationItem.type === '
|
|
379
|
-
return
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
title: navigationItem.label,
|
|
386
|
-
permalink: navigationItem.link.permalink,
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
throw new Error('unexpected category link type');
|
|
382
|
+
if (navigationItem.type === 'category') {
|
|
383
|
+
return navigationItem.link.type === 'doc'
|
|
384
|
+
? toDocNavigationLink(getDocById(navigationItem.link.id))
|
|
385
|
+
: {
|
|
386
|
+
title: navigationItem.label,
|
|
387
|
+
permalink: navigationItem.link.permalink,
|
|
388
|
+
};
|
|
390
389
|
}
|
|
391
|
-
|
|
390
|
+
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
392
391
|
}
|
|
@@ -149,9 +149,9 @@ function validateSidebarItem(
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
export function validateSidebars(
|
|
153
|
-
|
|
154
|
-
): asserts sidebars is NormalizedSidebars {
|
|
152
|
+
export function validateSidebars(sidebars: {
|
|
153
|
+
[sidebarId: string]: unknown;
|
|
154
|
+
}): asserts sidebars is NormalizedSidebars {
|
|
155
155
|
Object.values(sidebars as NormalizedSidebars).forEach((sidebar) => {
|
|
156
156
|
sidebar.forEach(validateSidebarItem);
|
|
157
157
|
});
|
|
@@ -164,6 +164,7 @@ const categoryMetadataFileSchema = Joi.object<CategoryMetadataFile>({
|
|
|
164
164
|
collapsible: Joi.boolean(),
|
|
165
165
|
className: Joi.string(),
|
|
166
166
|
link: sidebarItemCategoryLinkSchema,
|
|
167
|
+
customProps: Joi.object().unknown(),
|
|
167
168
|
});
|
|
168
169
|
|
|
169
170
|
export function validateCategoryMetadataFile(
|
package/src/slug.ts
CHANGED
|
@@ -15,9 +15,11 @@ import {
|
|
|
15
15
|
DefaultNumberPrefixParser,
|
|
16
16
|
stripPathNumberPrefixes,
|
|
17
17
|
} from './numberPrefix';
|
|
18
|
-
import type {DocMetadataBase} from './types';
|
|
19
18
|
import {isCategoryIndex, toCategoryIndexMatcherParam} from './docs';
|
|
20
|
-
import type {
|
|
19
|
+
import type {
|
|
20
|
+
NumberPrefixParser,
|
|
21
|
+
DocMetadataBase,
|
|
22
|
+
} from '@docusaurus/plugin-content-docs';
|
|
21
23
|
|
|
22
24
|
export default function getSlug({
|
|
23
25
|
baseID,
|
|
@@ -63,12 +65,11 @@ export default function getSlug({
|
|
|
63
65
|
function ensureValidSlug(slug: string): string {
|
|
64
66
|
if (!isValidPathname(slug)) {
|
|
65
67
|
throw new Error(
|
|
66
|
-
`We couldn't compute a valid slug for document with
|
|
68
|
+
`We couldn't compute a valid slug for document with ID "${baseID}" in "${sourceDirName}" directory.
|
|
67
69
|
The slug we computed looks invalid: ${slug}.
|
|
68
|
-
Maybe your slug front matter is incorrect or
|
|
69
|
-
By using
|
|
70
|
+
Maybe your slug front matter is incorrect or there are special characters in the file path?
|
|
71
|
+
By using front matter to set a custom slug, you should be able to fix this error:
|
|
70
72
|
|
|
71
|
-
Example =>
|
|
72
73
|
---
|
|
73
74
|
slug: /my/customDocPath
|
|
74
75
|
---
|
package/src/tags.ts
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {groupTaggedItems} from '@docusaurus/utils';
|
|
9
|
-
import type {VersionTags
|
|
9
|
+
import type {VersionTags} from './types';
|
|
10
|
+
import type {DocMetadata} from '@docusaurus/plugin-content-docs';
|
|
10
11
|
import _ from 'lodash';
|
|
11
12
|
|
|
12
13
|
export function getVersionTags(docs: DocMetadata[]): VersionTags {
|
|
13
14
|
const groups = groupTaggedItems(docs, (doc) => doc.tags);
|
|
14
15
|
return _.mapValues(groups, (group) => ({
|
|
15
|
-
|
|
16
|
+
label: group.tag.label,
|
|
16
17
|
docIds: group.items.map((item) => item.id),
|
|
17
18
|
permalink: group.tag.permalink,
|
|
18
19
|
}));
|
package/src/translations.ts
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
LoadedVersion,
|
|
10
|
+
LoadedContent,
|
|
11
|
+
} from '@docusaurus/plugin-content-docs';
|
|
9
12
|
import type {
|
|
10
13
|
Sidebar,
|
|
11
14
|
SidebarItemCategory,
|
|
@@ -22,7 +25,6 @@ import {
|
|
|
22
25
|
import type {
|
|
23
26
|
TranslationFileContent,
|
|
24
27
|
TranslationFile,
|
|
25
|
-
TranslationFiles,
|
|
26
28
|
TranslationMessage,
|
|
27
29
|
} from '@docusaurus/types';
|
|
28
30
|
import {mergeTranslations} from '@docusaurus/utils';
|
|
@@ -54,50 +56,6 @@ function getNormalizedSidebarName({
|
|
|
54
56
|
return rest.join('/');
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
/*
|
|
58
|
-
// Do we need to translate doc metadata?
|
|
59
|
-
// It seems translating front matter labels is good enough
|
|
60
|
-
function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
61
|
-
return {
|
|
62
|
-
[`${doc.unversionedId}.title`]: {
|
|
63
|
-
message: doc.title,
|
|
64
|
-
description: `The title for doc with id=${doc.unversionedId}`,
|
|
65
|
-
},
|
|
66
|
-
...(doc.sidebar_label
|
|
67
|
-
? {
|
|
68
|
-
[`${doc.unversionedId}.sidebar_label`]: {
|
|
69
|
-
message: doc.sidebar_label,
|
|
70
|
-
description:
|
|
71
|
-
`The sidebar label for doc with id=${doc.unversionedId}`,
|
|
72
|
-
},
|
|
73
|
-
}
|
|
74
|
-
: undefined),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function translateDoc(
|
|
78
|
-
doc: DocMetadata,
|
|
79
|
-
docsTranslations: TranslationFileContent,
|
|
80
|
-
): DocMetadata {
|
|
81
|
-
return {
|
|
82
|
-
...doc,
|
|
83
|
-
title: docsTranslations[`${doc.unversionedId}.title`]?.message ?? doc.title,
|
|
84
|
-
sidebar_label:
|
|
85
|
-
docsTranslations[`${doc.unversionedId}.sidebar_label`]?.message ??
|
|
86
|
-
doc.sidebar_label,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function getDocsTranslations(version: LoadedVersion): TranslationFileContent {
|
|
91
|
-
return mergeTranslations(version.docs.map(getDocTranslations));
|
|
92
|
-
}
|
|
93
|
-
function translateDocs(
|
|
94
|
-
docs: DocMetadata[],
|
|
95
|
-
docsTranslations: TranslationFileContent,
|
|
96
|
-
): DocMetadata[] {
|
|
97
|
-
return docs.map((doc) => translateDoc(doc, docsTranslations));
|
|
98
|
-
}
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
59
|
function getSidebarTranslationFileContent(
|
|
102
60
|
sidebar: Sidebar,
|
|
103
61
|
sidebarName: string,
|
|
@@ -118,26 +76,24 @@ function getSidebarTranslationFileContent(
|
|
|
118
76
|
},
|
|
119
77
|
]);
|
|
120
78
|
|
|
121
|
-
if (category.link) {
|
|
122
|
-
if (category.link.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
]);
|
|
140
|
-
}
|
|
79
|
+
if (category.link?.type === 'generated-index') {
|
|
80
|
+
if (category.link.title) {
|
|
81
|
+
entries.push([
|
|
82
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`,
|
|
83
|
+
{
|
|
84
|
+
message: category.link.title,
|
|
85
|
+
description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
|
|
86
|
+
},
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
if (category.link.description) {
|
|
90
|
+
entries.push([
|
|
91
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`,
|
|
92
|
+
{
|
|
93
|
+
message: category.link.description,
|
|
94
|
+
description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
141
97
|
}
|
|
142
98
|
}
|
|
143
99
|
|
|
@@ -244,10 +200,10 @@ function translateSidebars(
|
|
|
244
200
|
);
|
|
245
201
|
}
|
|
246
202
|
|
|
247
|
-
function getVersionTranslationFiles(version: LoadedVersion):
|
|
203
|
+
function getVersionTranslationFiles(version: LoadedVersion): TranslationFile[] {
|
|
248
204
|
const versionTranslations: TranslationFileContent = {
|
|
249
205
|
'version.label': {
|
|
250
|
-
message: version.
|
|
206
|
+
message: version.label,
|
|
251
207
|
description: `The label for version ${version.versionName}`,
|
|
252
208
|
},
|
|
253
209
|
};
|
|
@@ -255,56 +211,48 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
|
|
255
211
|
const sidebarsTranslations: TranslationFileContent =
|
|
256
212
|
getSidebarsTranslations(version);
|
|
257
213
|
|
|
258
|
-
// const docsTranslations: TranslationFileContent =
|
|
259
|
-
// getDocsTranslations(version);
|
|
260
|
-
|
|
261
214
|
return [
|
|
262
215
|
{
|
|
263
216
|
path: getVersionFileName(version.versionName),
|
|
264
|
-
content: mergeTranslations([
|
|
265
|
-
versionTranslations,
|
|
266
|
-
sidebarsTranslations,
|
|
267
|
-
// docsTranslations,
|
|
268
|
-
]),
|
|
217
|
+
content: mergeTranslations([versionTranslations, sidebarsTranslations]),
|
|
269
218
|
},
|
|
270
219
|
];
|
|
271
220
|
}
|
|
272
221
|
function translateVersion(
|
|
273
222
|
version: LoadedVersion,
|
|
274
|
-
translationFiles:
|
|
223
|
+
translationFiles: {[fileName: string]: TranslationFile},
|
|
275
224
|
): LoadedVersion {
|
|
276
225
|
const versionTranslations =
|
|
277
|
-
translationFiles[getVersionFileName(version.versionName)]
|
|
226
|
+
translationFiles[getVersionFileName(version.versionName)]!.content;
|
|
278
227
|
return {
|
|
279
228
|
...version,
|
|
280
|
-
|
|
229
|
+
label: versionTranslations['version.label']?.message ?? version.label,
|
|
281
230
|
sidebars: translateSidebars(version, versionTranslations),
|
|
282
|
-
// docs: translateDocs(version.docs, versionTranslations),
|
|
283
231
|
};
|
|
284
232
|
}
|
|
285
233
|
|
|
286
234
|
function getVersionsTranslationFiles(
|
|
287
235
|
versions: LoadedVersion[],
|
|
288
|
-
):
|
|
236
|
+
): TranslationFile[] {
|
|
289
237
|
return versions.flatMap(getVersionTranslationFiles);
|
|
290
238
|
}
|
|
291
239
|
function translateVersions(
|
|
292
240
|
versions: LoadedVersion[],
|
|
293
|
-
translationFiles:
|
|
241
|
+
translationFiles: {[fileName: string]: TranslationFile},
|
|
294
242
|
): LoadedVersion[] {
|
|
295
243
|
return versions.map((version) => translateVersion(version, translationFiles));
|
|
296
244
|
}
|
|
297
245
|
|
|
298
246
|
export function getLoadedContentTranslationFiles(
|
|
299
247
|
loadedContent: LoadedContent,
|
|
300
|
-
):
|
|
248
|
+
): TranslationFile[] {
|
|
301
249
|
return getVersionsTranslationFiles(loadedContent.loadedVersions);
|
|
302
250
|
}
|
|
303
251
|
export function translateLoadedContent(
|
|
304
252
|
loadedContent: LoadedContent,
|
|
305
253
|
translationFiles: TranslationFile[],
|
|
306
254
|
): LoadedContent {
|
|
307
|
-
const translationFilesMap:
|
|
255
|
+
const translationFilesMap: {[fileName: string]: TranslationFile} = _.keyBy(
|
|
308
256
|
translationFiles,
|
|
309
257
|
(f) => f.path,
|
|
310
258
|
);
|