@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
|
@@ -10,13 +10,14 @@ exports.processSidebars = void 0;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const generator_1 = require("./generator");
|
|
12
12
|
const validation_1 = require("./validation");
|
|
13
|
-
const lodash_1 =
|
|
14
|
-
const combine_promises_1 =
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
+
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
15
15
|
const docs_1 = require("../docs");
|
|
16
16
|
function toSidebarItemsGeneratorDoc(doc) {
|
|
17
17
|
return lodash_1.default.pick(doc, [
|
|
18
18
|
'id',
|
|
19
19
|
'unversionedId',
|
|
20
|
+
'title',
|
|
20
21
|
'frontMatter',
|
|
21
22
|
'source',
|
|
22
23
|
'sourceDirName',
|
|
@@ -29,7 +30,7 @@ function toSidebarItemsGeneratorVersion(version) {
|
|
|
29
30
|
// Handle the generation of autogenerated sidebar items and other
|
|
30
31
|
// post-processing checks
|
|
31
32
|
async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
32
|
-
const { sidebarItemsGenerator, numberPrefixParser, docs,
|
|
33
|
+
const { sidebarItemsGenerator, numberPrefixParser, docs, drafts, version } = params;
|
|
33
34
|
// Just a minor lazy transformation optimization
|
|
34
35
|
const getSidebarItemsGeneratorDocsAndVersion = lodash_1.default.memoize(() => ({
|
|
35
36
|
docs: docs.map(toSidebarItemsGeneratorDoc),
|
|
@@ -42,7 +43,6 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
|
42
43
|
defaultSidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
|
|
43
44
|
isCategoryIndex: docs_1.isCategoryIndex,
|
|
44
45
|
...getSidebarItemsGeneratorDocsAndVersion(),
|
|
45
|
-
options: sidebarOptions,
|
|
46
46
|
categoriesMetadata,
|
|
47
47
|
});
|
|
48
48
|
// Process again... weird but sidebar item generated might generate some
|
|
@@ -51,12 +51,23 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
|
51
51
|
// more autogenerated items, or when loop count (e.g. 10) is reached
|
|
52
52
|
return processItems(generatedItems);
|
|
53
53
|
}
|
|
54
|
+
const draftIds = new Set(drafts.flatMap(docs_1.getDocIds));
|
|
55
|
+
const isDraftItem = (item) => {
|
|
56
|
+
if (item.type === 'doc' || item.type === 'ref') {
|
|
57
|
+
return draftIds.has(item.id);
|
|
58
|
+
}
|
|
59
|
+
// If a category only contains draft items, it should be filtered entirely.
|
|
60
|
+
if (item.type === 'category') {
|
|
61
|
+
return item.items.every(isDraftItem);
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
};
|
|
54
65
|
async function processItem(item) {
|
|
55
66
|
if (item.type === 'category') {
|
|
56
67
|
return [
|
|
57
68
|
{
|
|
58
69
|
...item,
|
|
59
|
-
items:
|
|
70
|
+
items: await processItems(item.items),
|
|
60
71
|
},
|
|
61
72
|
];
|
|
62
73
|
}
|
|
@@ -66,7 +77,7 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
|
66
77
|
return [item];
|
|
67
78
|
}
|
|
68
79
|
async function processItems(items) {
|
|
69
|
-
return (await Promise.all(items.map(processItem))).flat();
|
|
80
|
+
return (await Promise.all(items.filter((i) => !isDraftItem(i)).map(processItem))).flat();
|
|
70
81
|
}
|
|
71
82
|
const processedSidebar = await processItems(unprocessedSidebar);
|
|
72
83
|
return processedSidebar;
|
package/lib/sidebars/types.d.ts
CHANGED
|
@@ -5,15 +5,18 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Optional, Required } from 'utility-types';
|
|
8
|
-
import type { DocMetadataBase, VersionMetadata } from '
|
|
9
|
-
import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
10
9
|
import type { Slugger } from '@docusaurus/utils';
|
|
11
|
-
declare type Expand<T extends
|
|
10
|
+
declare type Expand<T extends {
|
|
11
|
+
[x: string]: unknown;
|
|
12
|
+
}> = {
|
|
12
13
|
[P in keyof T]: T[P];
|
|
13
14
|
};
|
|
14
15
|
export declare type SidebarItemBase = {
|
|
15
16
|
className?: string;
|
|
16
|
-
customProps?:
|
|
17
|
+
customProps?: {
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
21
|
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
19
22
|
type: 'doc' | 'ref';
|
|
@@ -122,15 +125,6 @@ export declare type PropSidebars = {
|
|
|
122
125
|
[sidebarId: string]: PropSidebar;
|
|
123
126
|
};
|
|
124
127
|
export declare type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
|
|
125
|
-
export declare type PropVersionDoc = {
|
|
126
|
-
id: string;
|
|
127
|
-
title: string;
|
|
128
|
-
description?: string;
|
|
129
|
-
sidebar?: string;
|
|
130
|
-
};
|
|
131
|
-
export declare type PropVersionDocs = {
|
|
132
|
-
[docId: string]: PropVersionDoc;
|
|
133
|
-
};
|
|
134
128
|
export declare type CategoryMetadataFile = {
|
|
135
129
|
label?: string;
|
|
136
130
|
position?: number;
|
|
@@ -138,27 +132,45 @@ export declare type CategoryMetadataFile = {
|
|
|
138
132
|
collapsible?: boolean;
|
|
139
133
|
className?: string;
|
|
140
134
|
link?: SidebarItemCategoryLinkConfig | null;
|
|
135
|
+
customProps?: {
|
|
136
|
+
[key: string]: unknown;
|
|
137
|
+
};
|
|
141
138
|
};
|
|
142
|
-
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
139
|
+
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'title' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
143
140
|
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
144
141
|
export declare type SidebarItemsGeneratorArgs = {
|
|
142
|
+
/** The sidebar item with type "autogenerated" to be transformed. */
|
|
145
143
|
item: SidebarItemAutogenerated;
|
|
144
|
+
/** Useful metadata for the version this sidebar belongs to. */
|
|
146
145
|
version: SidebarItemsGeneratorVersion;
|
|
146
|
+
/** All the docs of that version (unfiltered). */
|
|
147
147
|
docs: SidebarItemsGeneratorDoc[];
|
|
148
|
+
/** Number prefix parser configured for this plugin. */
|
|
148
149
|
numberPrefixParser: NumberPrefixParser;
|
|
150
|
+
/** The default category index matcher which you can override. */
|
|
149
151
|
isCategoryIndex: CategoryIndexMatcher;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Key is the path relative to the doc content directory, value is the
|
|
154
|
+
* category metadata file's content.
|
|
155
|
+
*/
|
|
156
|
+
categoriesMetadata: {
|
|
157
|
+
[filePath: string]: CategoryMetadataFile;
|
|
158
|
+
};
|
|
152
159
|
};
|
|
153
160
|
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
|
|
154
|
-
export declare type
|
|
161
|
+
export declare type SidebarItemsGeneratorOption = (generatorArgs: {
|
|
162
|
+
/**
|
|
163
|
+
* Useful to re-use/enhance the default sidebar generation logic from
|
|
164
|
+
* Docusaurus.
|
|
165
|
+
* @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
|
|
166
|
+
*/
|
|
155
167
|
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
156
|
-
} & SidebarItemsGeneratorArgs
|
|
157
|
-
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<NormalizedSidebarItem[]>;
|
|
168
|
+
} & SidebarItemsGeneratorArgs) => Promise<NormalizedSidebarItem[]>;
|
|
158
169
|
export declare type SidebarProcessorParams = {
|
|
159
170
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
160
171
|
numberPrefixParser: NumberPrefixParser;
|
|
161
172
|
docs: DocMetadataBase[];
|
|
173
|
+
drafts: DocMetadataBase[];
|
|
162
174
|
version: VersionMetadata;
|
|
163
175
|
categoryLabelSlugger: Slugger;
|
|
164
176
|
sidebarOptions: SidebarOptions;
|
package/lib/sidebars/utils.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Sidebars, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc, SidebarCategoriesShorthand, SidebarItemConfig, SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
|
|
8
|
-
import type { DocMetadataBase,
|
|
8
|
+
import type { DocMetadataBase, PropNavigationLink } from '@docusaurus/plugin-content-docs';
|
|
9
9
|
export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
|
|
10
10
|
export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
|
|
11
11
|
export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
|
|
@@ -13,8 +13,12 @@ export declare function collectSidebarCategories(sidebar: Sidebar): SidebarItemC
|
|
|
13
13
|
export declare function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[];
|
|
14
14
|
export declare function collectSidebarDocIds(sidebar: Sidebar): string[];
|
|
15
15
|
export declare function collectSidebarNavigation(sidebar: Sidebar): SidebarNavigationItem[];
|
|
16
|
-
export declare function collectSidebarsDocIds(sidebars: Sidebars):
|
|
17
|
-
|
|
16
|
+
export declare function collectSidebarsDocIds(sidebars: Sidebars): {
|
|
17
|
+
[sidebarId: string]: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare function collectSidebarsNavigations(sidebars: Sidebars): {
|
|
20
|
+
[sidebarId: string]: SidebarNavigationItem[];
|
|
21
|
+
};
|
|
18
22
|
export declare type SidebarNavigation = {
|
|
19
23
|
sidebarName: string | undefined;
|
|
20
24
|
previous: SidebarNavigationItem | undefined;
|
|
@@ -27,17 +31,24 @@ export declare type SidebarsUtils = {
|
|
|
27
31
|
getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
|
|
28
32
|
getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
|
|
29
33
|
getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
|
|
34
|
+
/**
|
|
35
|
+
* This function may return undefined. This is usually a user mistake, because
|
|
36
|
+
* it means this sidebar will never be displayed; however, we can still use
|
|
37
|
+
* `displayed_sidebar` to make it displayed. Pretty weird but valid use-case
|
|
38
|
+
*/
|
|
30
39
|
getFirstLink: (sidebarId: string) => {
|
|
31
40
|
type: 'doc';
|
|
32
41
|
id: string;
|
|
33
42
|
label: string;
|
|
34
43
|
} | {
|
|
35
44
|
type: 'generated-index';
|
|
36
|
-
|
|
45
|
+
permalink: string;
|
|
37
46
|
label: string;
|
|
38
47
|
} | undefined;
|
|
39
48
|
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
|
40
49
|
};
|
|
41
50
|
export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
|
|
42
|
-
export declare function toDocNavigationLink(doc: DocMetadataBase):
|
|
43
|
-
export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById:
|
|
51
|
+
export declare function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink;
|
|
52
|
+
export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: {
|
|
53
|
+
[docId: string]: DocMetadataBase;
|
|
54
|
+
}): PropNavigationLink | undefined;
|
package/lib/sidebars/utils.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.toNavigationLink = exports.toDocNavigationLink = exports.createSidebarsUtils = exports.collectSidebarsNavigations = exports.collectSidebarsDocIds = exports.collectSidebarNavigation = exports.collectSidebarDocIds = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = exports.isCategoriesShorthand = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const lodash_1 =
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
function isCategoriesShorthand(item) {
|
|
14
14
|
return typeof item === 'object' && !item.type;
|
|
@@ -58,9 +58,8 @@ exports.collectSidebarLinks = collectSidebarLinks;
|
|
|
58
58
|
// /!\ docId order matters for navigation!
|
|
59
59
|
function collectSidebarDocIds(sidebar) {
|
|
60
60
|
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
61
|
-
var _a;
|
|
62
61
|
if (item.type === 'category') {
|
|
63
|
-
return
|
|
62
|
+
return item.link?.type === 'doc' ? [item.link.id] : [];
|
|
64
63
|
}
|
|
65
64
|
if (item.type === 'doc') {
|
|
66
65
|
return [item.id];
|
|
@@ -95,8 +94,7 @@ function createSidebarsUtils(sidebars) {
|
|
|
95
94
|
// Reverse mapping
|
|
96
95
|
const docIdToSidebarName = Object.fromEntries(Object.entries(sidebarNameToDocIds).flatMap(([sidebarName, docIds]) => docIds.map((docId) => [docId, sidebarName])));
|
|
97
96
|
function getFirstDocIdOfFirstSidebar() {
|
|
98
|
-
|
|
99
|
-
return (_a = Object.values(sidebarNameToDocIds)[0]) === null || _a === void 0 ? void 0 : _a[0];
|
|
97
|
+
return Object.values(sidebarNameToDocIds)[0]?.[0];
|
|
100
98
|
}
|
|
101
99
|
function getSidebarNameByDocId(docId) {
|
|
102
100
|
return docIdToSidebarName[docId];
|
|
@@ -121,10 +119,10 @@ function createSidebarsUtils(sidebars) {
|
|
|
121
119
|
if (!sidebarName) {
|
|
122
120
|
return emptySidebarNavigation();
|
|
123
121
|
}
|
|
124
|
-
|
|
122
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
123
|
+
if (!navigationItems) {
|
|
125
124
|
throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
|
|
126
125
|
}
|
|
127
|
-
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
128
126
|
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
129
127
|
if (item.type === 'doc') {
|
|
130
128
|
return item.id === docId;
|
|
@@ -137,8 +135,11 @@ function createSidebarsUtils(sidebars) {
|
|
|
137
135
|
if (currentItemIndex === -1) {
|
|
138
136
|
return { sidebarName, next: undefined, previous: undefined };
|
|
139
137
|
}
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
return {
|
|
139
|
+
sidebarName,
|
|
140
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
141
|
+
next: navigationItems[currentItemIndex + 1],
|
|
142
|
+
};
|
|
142
143
|
}
|
|
143
144
|
function getCategoryGeneratedIndexList() {
|
|
144
145
|
return Object.values(sidebarNameToNavigationItems)
|
|
@@ -155,21 +156,19 @@ function createSidebarsUtils(sidebars) {
|
|
|
155
156
|
* unique). More reliable than using object identity
|
|
156
157
|
*/
|
|
157
158
|
function getCategoryGeneratedIndexNavigation(categoryGeneratedIndexPermalink) {
|
|
158
|
-
var _a;
|
|
159
159
|
function isCurrentCategoryGeneratedIndexItem(item) {
|
|
160
|
-
var _a;
|
|
161
160
|
return (item.type === 'category' &&
|
|
162
|
-
|
|
161
|
+
item.link?.type === 'generated-index' &&
|
|
163
162
|
item.link.permalink === categoryGeneratedIndexPermalink);
|
|
164
163
|
}
|
|
165
|
-
const sidebarName =
|
|
166
|
-
if (!sidebarName) {
|
|
167
|
-
return emptySidebarNavigation();
|
|
168
|
-
}
|
|
164
|
+
const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))[0];
|
|
169
165
|
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
170
166
|
const currentItemIndex = navigationItems.findIndex(isCurrentCategoryGeneratedIndexItem);
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
return {
|
|
168
|
+
sidebarName,
|
|
169
|
+
previous: navigationItems[currentItemIndex - 1],
|
|
170
|
+
next: navigationItems[currentItemIndex + 1],
|
|
171
|
+
};
|
|
173
172
|
}
|
|
174
173
|
function checkSidebarsDocIds(validDocIds, sidebarFilePath) {
|
|
175
174
|
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
@@ -184,27 +183,26 @@ Available document ids are:
|
|
|
184
183
|
}
|
|
185
184
|
}
|
|
186
185
|
function getFirstLink(sidebar) {
|
|
187
|
-
var _a, _b, _c;
|
|
188
186
|
for (const item of sidebar) {
|
|
189
187
|
if (item.type === 'doc') {
|
|
190
188
|
return {
|
|
191
189
|
type: 'doc',
|
|
192
190
|
id: item.id,
|
|
193
|
-
label:
|
|
191
|
+
label: item.label ?? item.id,
|
|
194
192
|
};
|
|
195
193
|
}
|
|
196
194
|
else if (item.type === 'category') {
|
|
197
|
-
if (
|
|
195
|
+
if (item.link?.type === 'doc') {
|
|
198
196
|
return {
|
|
199
197
|
type: 'doc',
|
|
200
198
|
id: item.link.id,
|
|
201
199
|
label: item.label,
|
|
202
200
|
};
|
|
203
201
|
}
|
|
204
|
-
else if (
|
|
202
|
+
else if (item.link?.type === 'generated-index') {
|
|
205
203
|
return {
|
|
206
204
|
type: 'generated-index',
|
|
207
|
-
|
|
205
|
+
permalink: item.link.permalink,
|
|
208
206
|
label: item.label,
|
|
209
207
|
};
|
|
210
208
|
}
|
|
@@ -229,9 +227,8 @@ Available document ids are:
|
|
|
229
227
|
}
|
|
230
228
|
exports.createSidebarsUtils = createSidebarsUtils;
|
|
231
229
|
function toDocNavigationLink(doc) {
|
|
232
|
-
var _a;
|
|
233
230
|
const { title, permalink, frontMatter: { pagination_label: paginationLabel, sidebar_label: sidebarLabel, }, } = doc;
|
|
234
|
-
return { title:
|
|
231
|
+
return { title: paginationLabel ?? sidebarLabel ?? title, permalink };
|
|
235
232
|
}
|
|
236
233
|
exports.toDocNavigationLink = toDocNavigationLink;
|
|
237
234
|
function toNavigationLink(navigationItem, docsById) {
|
|
@@ -245,21 +242,14 @@ function toNavigationLink(navigationItem, docsById) {
|
|
|
245
242
|
if (!navigationItem) {
|
|
246
243
|
return undefined;
|
|
247
244
|
}
|
|
248
|
-
if (navigationItem.type === '
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (navigationItem.link.type === 'doc') {
|
|
253
|
-
return toDocNavigationLink(getDocById(navigationItem.link.id));
|
|
254
|
-
}
|
|
255
|
-
else if (navigationItem.link.type === 'generated-index') {
|
|
256
|
-
return {
|
|
245
|
+
if (navigationItem.type === 'category') {
|
|
246
|
+
return navigationItem.link.type === 'doc'
|
|
247
|
+
? toDocNavigationLink(getDocById(navigationItem.link.id))
|
|
248
|
+
: {
|
|
257
249
|
title: navigationItem.label,
|
|
258
250
|
permalink: navigationItem.link.permalink,
|
|
259
251
|
};
|
|
260
|
-
}
|
|
261
|
-
throw new Error('unexpected category link type');
|
|
262
252
|
}
|
|
263
|
-
|
|
253
|
+
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
264
254
|
}
|
|
265
255
|
exports.toNavigationLink = toNavigationLink;
|
|
@@ -5,5 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { NormalizedSidebars, CategoryMetadataFile } from './types';
|
|
8
|
-
export declare function validateSidebars(sidebars:
|
|
8
|
+
export declare function validateSidebars(sidebars: {
|
|
9
|
+
[sidebarId: string]: unknown;
|
|
10
|
+
}): asserts sidebars is NormalizedSidebars;
|
|
9
11
|
export declare function validateCategoryMetadataFile(unsafeContent: unknown): CategoryMetadataFile;
|
|
@@ -130,6 +130,7 @@ const categoryMetadataFileSchema = utils_validation_1.Joi.object({
|
|
|
130
130
|
collapsible: utils_validation_1.Joi.boolean(),
|
|
131
131
|
className: utils_validation_1.Joi.string(),
|
|
132
132
|
link: sidebarItemCategoryLinkSchema,
|
|
133
|
+
customProps: utils_validation_1.Joi.object().unknown(),
|
|
133
134
|
});
|
|
134
135
|
function validateCategoryMetadataFile(unsafeContent) {
|
|
135
136
|
return utils_validation_1.Joi.attempt(unsafeContent, categoryMetadataFileSchema);
|
package/lib/slug.d.ts
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type { DocMetadataBase } from '
|
|
8
|
-
import type { NumberPrefixParser } from '@docusaurus/plugin-content-docs';
|
|
7
|
+
import type { NumberPrefixParser, DocMetadataBase } from '@docusaurus/plugin-content-docs';
|
|
9
8
|
export default function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
|
|
10
9
|
baseID: string;
|
|
11
10
|
frontMatterSlug?: string;
|
package/lib/slug.js
CHANGED
|
@@ -20,7 +20,7 @@ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumbe
|
|
|
20
20
|
return resolveDirname;
|
|
21
21
|
}
|
|
22
22
|
function computeSlug() {
|
|
23
|
-
if (frontMatterSlug
|
|
23
|
+
if (frontMatterSlug?.startsWith('/')) {
|
|
24
24
|
return frontMatterSlug;
|
|
25
25
|
}
|
|
26
26
|
const dirNameSlug = getDirNameSlug();
|
|
@@ -33,12 +33,11 @@ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumbe
|
|
|
33
33
|
}
|
|
34
34
|
function ensureValidSlug(slug) {
|
|
35
35
|
if (!(0, utils_1.isValidPathname)(slug)) {
|
|
36
|
-
throw new Error(`We couldn't compute a valid slug for document with
|
|
36
|
+
throw new Error(`We couldn't compute a valid slug for document with ID "${baseID}" in "${sourceDirName}" directory.
|
|
37
37
|
The slug we computed looks invalid: ${slug}.
|
|
38
|
-
Maybe your slug front matter is incorrect or
|
|
39
|
-
By using
|
|
38
|
+
Maybe your slug front matter is incorrect or there are special characters in the file path?
|
|
39
|
+
By using front matter to set a custom slug, you should be able to fix this error:
|
|
40
40
|
|
|
41
|
-
Example =>
|
|
42
41
|
---
|
|
43
42
|
slug: /my/customDocPath
|
|
44
43
|
---
|
package/lib/tags.d.ts
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type { VersionTags
|
|
7
|
+
import type { VersionTags } from './types';
|
|
8
|
+
import type { DocMetadata } from '@docusaurus/plugin-content-docs';
|
|
8
9
|
export declare function getVersionTags(docs: DocMetadata[]): VersionTags;
|
package/lib/tags.js
CHANGED
|
@@ -9,11 +9,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.getVersionTags = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const lodash_1 =
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
13
|
function getVersionTags(docs) {
|
|
14
14
|
const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
|
|
15
15
|
return lodash_1.default.mapValues(groups, (group) => ({
|
|
16
|
-
|
|
16
|
+
label: group.tag.label,
|
|
17
17
|
docIds: group.items.map((item) => item.id),
|
|
18
18
|
permalink: group.tag.permalink,
|
|
19
19
|
}));
|
package/lib/translations.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type { LoadedContent } from '
|
|
8
|
-
import type { TranslationFile
|
|
9
|
-
export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent):
|
|
7
|
+
import type { LoadedContent } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { TranslationFile } from '@docusaurus/types';
|
|
9
|
+
export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent): TranslationFile[];
|
|
10
10
|
export declare function translateLoadedContent(loadedContent: LoadedContent, translationFiles: TranslationFile[]): LoadedContent;
|
package/lib/translations.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const lodash_1 =
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("./sidebars/utils");
|
|
13
13
|
const utils_2 = require("@docusaurus/utils");
|
|
14
14
|
const constants_1 = require("./constants");
|
|
@@ -30,49 +30,6 @@ function getNormalizedSidebarName({ versionName, sidebarName, }) {
|
|
|
30
30
|
const [, ...rest] = sidebarName.split('/');
|
|
31
31
|
return rest.join('/');
|
|
32
32
|
}
|
|
33
|
-
/*
|
|
34
|
-
// Do we need to translate doc metadata?
|
|
35
|
-
// It seems translating front matter labels is good enough
|
|
36
|
-
function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
37
|
-
return {
|
|
38
|
-
[`${doc.unversionedId}.title`]: {
|
|
39
|
-
message: doc.title,
|
|
40
|
-
description: `The title for doc with id=${doc.unversionedId}`,
|
|
41
|
-
},
|
|
42
|
-
...(doc.sidebar_label
|
|
43
|
-
? {
|
|
44
|
-
[`${doc.unversionedId}.sidebar_label`]: {
|
|
45
|
-
message: doc.sidebar_label,
|
|
46
|
-
description:
|
|
47
|
-
`The sidebar label for doc with id=${doc.unversionedId}`,
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
: undefined),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function translateDoc(
|
|
54
|
-
doc: DocMetadata,
|
|
55
|
-
docsTranslations: TranslationFileContent,
|
|
56
|
-
): DocMetadata {
|
|
57
|
-
return {
|
|
58
|
-
...doc,
|
|
59
|
-
title: docsTranslations[`${doc.unversionedId}.title`]?.message ?? doc.title,
|
|
60
|
-
sidebar_label:
|
|
61
|
-
docsTranslations[`${doc.unversionedId}.sidebar_label`]?.message ??
|
|
62
|
-
doc.sidebar_label,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getDocsTranslations(version: LoadedVersion): TranslationFileContent {
|
|
67
|
-
return mergeTranslations(version.docs.map(getDocTranslations));
|
|
68
|
-
}
|
|
69
|
-
function translateDocs(
|
|
70
|
-
docs: DocMetadata[],
|
|
71
|
-
docsTranslations: TranslationFileContent,
|
|
72
|
-
): DocMetadata[] {
|
|
73
|
-
return docs.map((doc) => translateDoc(doc, docsTranslations));
|
|
74
|
-
}
|
|
75
|
-
*/
|
|
76
33
|
function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
77
34
|
const categories = (0, utils_1.collectSidebarCategories)(sidebar);
|
|
78
35
|
const categoryContent = Object.fromEntries(categories.flatMap((category) => {
|
|
@@ -84,26 +41,24 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
84
41
|
description: `The label for category ${category.label} in sidebar ${sidebarName}`,
|
|
85
42
|
},
|
|
86
43
|
]);
|
|
87
|
-
if (category.link) {
|
|
88
|
-
if (category.link.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
]);
|
|
106
|
-
}
|
|
44
|
+
if (category.link?.type === 'generated-index') {
|
|
45
|
+
if (category.link.title) {
|
|
46
|
+
entries.push([
|
|
47
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`,
|
|
48
|
+
{
|
|
49
|
+
message: category.link.title,
|
|
50
|
+
description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
if (category.link.description) {
|
|
55
|
+
entries.push([
|
|
56
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`,
|
|
57
|
+
{
|
|
58
|
+
message: category.link.description,
|
|
59
|
+
description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
|
|
60
|
+
},
|
|
61
|
+
]);
|
|
107
62
|
}
|
|
108
63
|
}
|
|
109
64
|
return entries;
|
|
@@ -120,13 +75,12 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
120
75
|
}
|
|
121
76
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
122
77
|
function transformSidebarCategoryLink(category) {
|
|
123
|
-
var _a, _b, _c, _d;
|
|
124
78
|
if (!category.link) {
|
|
125
79
|
return undefined;
|
|
126
80
|
}
|
|
127
81
|
if (category.link.type === 'generated-index') {
|
|
128
|
-
const title =
|
|
129
|
-
const description =
|
|
82
|
+
const title = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`]?.message ?? category.link.title;
|
|
83
|
+
const description = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`]?.message ?? category.link.description;
|
|
130
84
|
return {
|
|
131
85
|
...category.link,
|
|
132
86
|
title,
|
|
@@ -136,19 +90,20 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
|
136
90
|
return category.link;
|
|
137
91
|
}
|
|
138
92
|
return (0, utils_1.transformSidebarItems)(sidebar, (item) => {
|
|
139
|
-
var _a, _b, _c, _d;
|
|
140
93
|
if (item.type === 'category') {
|
|
141
94
|
const link = transformSidebarCategoryLink(item);
|
|
142
95
|
return {
|
|
143
96
|
...item,
|
|
144
|
-
label:
|
|
97
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.category.${item.label}`]
|
|
98
|
+
?.message ?? item.label,
|
|
145
99
|
...(link && { link }),
|
|
146
100
|
};
|
|
147
101
|
}
|
|
148
102
|
if (item.type === 'link') {
|
|
149
103
|
return {
|
|
150
104
|
...item,
|
|
151
|
-
label:
|
|
105
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.link.${item.label}`]
|
|
106
|
+
?.message ?? item.label,
|
|
152
107
|
};
|
|
153
108
|
}
|
|
154
109
|
return item;
|
|
@@ -176,32 +131,24 @@ function translateSidebars(version, sidebarsTranslations) {
|
|
|
176
131
|
function getVersionTranslationFiles(version) {
|
|
177
132
|
const versionTranslations = {
|
|
178
133
|
'version.label': {
|
|
179
|
-
message: version.
|
|
134
|
+
message: version.label,
|
|
180
135
|
description: `The label for version ${version.versionName}`,
|
|
181
136
|
},
|
|
182
137
|
};
|
|
183
138
|
const sidebarsTranslations = getSidebarsTranslations(version);
|
|
184
|
-
// const docsTranslations: TranslationFileContent =
|
|
185
|
-
// getDocsTranslations(version);
|
|
186
139
|
return [
|
|
187
140
|
{
|
|
188
141
|
path: getVersionFileName(version.versionName),
|
|
189
|
-
content: (0, utils_2.mergeTranslations)([
|
|
190
|
-
versionTranslations,
|
|
191
|
-
sidebarsTranslations,
|
|
192
|
-
// docsTranslations,
|
|
193
|
-
]),
|
|
142
|
+
content: (0, utils_2.mergeTranslations)([versionTranslations, sidebarsTranslations]),
|
|
194
143
|
},
|
|
195
144
|
];
|
|
196
145
|
}
|
|
197
146
|
function translateVersion(version, translationFiles) {
|
|
198
|
-
var _a;
|
|
199
147
|
const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
|
|
200
148
|
return {
|
|
201
149
|
...version,
|
|
202
|
-
|
|
150
|
+
label: versionTranslations['version.label']?.message ?? version.label,
|
|
203
151
|
sidebars: translateSidebars(version, versionTranslations),
|
|
204
|
-
// docs: translateDocs(version.docs, versionTranslations),
|
|
205
152
|
};
|
|
206
153
|
}
|
|
207
154
|
function getVersionsTranslationFiles(versions) {
|