@docusaurus/plugin-content-docs 0.0.0-4071 → 0.0.0-4075
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/cli.d.ts +1 -1
- package/lib/cli.js +12 -16
- package/lib/index.js +12 -16
- package/lib/options.js +2 -2
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -1
- package/lib/sidebars/generator.js +174 -0
- package/lib/sidebars/index.d.ts +14 -0
- package/lib/sidebars/index.js +64 -0
- package/lib/sidebars/normalization.d.ts +9 -0
- package/lib/sidebars/normalization.js +58 -0
- package/lib/sidebars/processor.d.ts +16 -0
- package/lib/sidebars/processor.js +70 -0
- package/lib/sidebars/types.d.ts +87 -0
- package/lib/sidebars/types.js +13 -0
- package/lib/sidebars/utils.d.ts +22 -0
- package/lib/sidebars/utils.js +101 -0
- package/lib/sidebars/validation.d.ts +8 -0
- package/lib/sidebars/validation.js +102 -0
- package/lib/translations.d.ts +1 -1
- package/lib/translations.js +9 -9
- package/lib/types.d.ts +1 -58
- package/package.json +10 -9
- package/src/__tests__/index.test.ts +4 -5
- package/src/__tests__/options.test.ts +1 -1
- package/src/cli.ts +23 -29
- package/src/index.ts +19 -27
- package/src/options.ts +1 -1
- package/src/plugin-content-docs.d.ts +6 -24
- package/src/props.ts +3 -5
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
- package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +6 -6
- package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +2 -2
- package/src/sidebars/__tests__/index.test.ts +202 -0
- package/src/sidebars/__tests__/processor.test.ts +148 -0
- package/src/sidebars/__tests__/utils.test.ts +395 -0
- package/src/sidebars/generator.ts +253 -0
- package/src/sidebars/index.ts +84 -0
- package/src/sidebars/normalization.ts +88 -0
- package/src/sidebars/processor.ts +124 -0
- package/src/sidebars/types.ts +156 -0
- package/src/sidebars/utils.ts +146 -0
- package/src/sidebars/validation.ts +124 -0
- package/src/translations.ts +7 -12
- package/src/types.ts +1 -94
- package/lib/sidebarItemsGenerator.js +0 -222
- package/lib/sidebars.d.ts +0 -45
- package/lib/sidebars.js +0 -365
- package/src/__tests__/sidebars.test.ts +0 -741
- package/src/sidebarItemsGenerator.ts +0 -322
- package/src/sidebars.ts +0 -609
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateSidebars = void 0;
|
|
10
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
const sidebarItemBaseSchema = utils_validation_1.Joi.object({
|
|
13
|
+
className: utils_validation_1.Joi.string(),
|
|
14
|
+
customProps: utils_validation_1.Joi.object().unknown(),
|
|
15
|
+
});
|
|
16
|
+
const sidebarItemAutogeneratedSchema = sidebarItemBaseSchema.append({
|
|
17
|
+
type: 'autogenerated',
|
|
18
|
+
dirName: utils_validation_1.Joi.string()
|
|
19
|
+
.required()
|
|
20
|
+
.pattern(/^[^/](.*[^/])?$/)
|
|
21
|
+
.message('"dirName" must be a dir path relative to the docs folder root, and should not start or end with slash'),
|
|
22
|
+
});
|
|
23
|
+
const sidebarItemDocSchema = sidebarItemBaseSchema.append({
|
|
24
|
+
type: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
|
|
25
|
+
id: utils_validation_1.Joi.string().required(),
|
|
26
|
+
label: utils_validation_1.Joi.string(),
|
|
27
|
+
});
|
|
28
|
+
const sidebarItemLinkSchema = sidebarItemBaseSchema.append({
|
|
29
|
+
type: 'link',
|
|
30
|
+
href: utils_validation_1.URISchema.required(),
|
|
31
|
+
label: utils_validation_1.Joi.string()
|
|
32
|
+
.required()
|
|
33
|
+
.messages({ 'any.unknown': '"label" must be a string' }),
|
|
34
|
+
});
|
|
35
|
+
const sidebarItemCategorySchema = sidebarItemBaseSchema.append({
|
|
36
|
+
type: 'category',
|
|
37
|
+
label: utils_validation_1.Joi.string()
|
|
38
|
+
.required()
|
|
39
|
+
.messages({ 'any.unknown': '"label" must be a string' }),
|
|
40
|
+
// TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
|
|
41
|
+
items: utils_validation_1.Joi.array()
|
|
42
|
+
.required()
|
|
43
|
+
.messages({ 'any.unknown': '"items" must be an array' }),
|
|
44
|
+
collapsed: utils_validation_1.Joi.boolean().messages({
|
|
45
|
+
'any.unknown': '"collapsed" must be a boolean',
|
|
46
|
+
}),
|
|
47
|
+
collapsible: utils_validation_1.Joi.boolean().messages({
|
|
48
|
+
'any.unknown': '"collapsible" must be a boolean',
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
const sidebarItemSchema = utils_validation_1.Joi.object()
|
|
52
|
+
.when('.type', {
|
|
53
|
+
switch: [
|
|
54
|
+
{ is: 'link', then: sidebarItemLinkSchema },
|
|
55
|
+
{
|
|
56
|
+
is: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
|
|
57
|
+
then: sidebarItemDocSchema,
|
|
58
|
+
},
|
|
59
|
+
{ is: 'autogenerated', then: sidebarItemAutogeneratedSchema },
|
|
60
|
+
{ is: 'category', then: sidebarItemCategorySchema },
|
|
61
|
+
{
|
|
62
|
+
is: 'subcategory',
|
|
63
|
+
then: utils_validation_1.Joi.forbidden().messages({
|
|
64
|
+
'any.unknown': 'Docusaurus v2: "subcategory" has been renamed as "category".',
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
is: utils_validation_1.Joi.string().required(),
|
|
69
|
+
then: utils_validation_1.Joi.forbidden().messages({
|
|
70
|
+
'any.unknown': 'Unknown sidebar item type "{.type}".',
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
})
|
|
75
|
+
.id('sidebarItemSchema');
|
|
76
|
+
function validateSidebarItem(item) {
|
|
77
|
+
if (typeof item === 'string') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// TODO: remove once with proper Joi support
|
|
81
|
+
// Because we can't use Joi to validate nested items (see above), we do it manually
|
|
82
|
+
if ((0, types_1.isCategoriesShorthand)(item)) {
|
|
83
|
+
Object.values(item).forEach((category) => category.forEach(validateSidebarItem));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
utils_validation_1.Joi.assert(item, sidebarItemSchema);
|
|
87
|
+
if (item.type === 'category') {
|
|
88
|
+
item.items.forEach(validateSidebarItem);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function validateSidebars(sidebars) {
|
|
93
|
+
Object.values(sidebars).forEach((sidebar) => {
|
|
94
|
+
if (Array.isArray(sidebar)) {
|
|
95
|
+
sidebar.forEach(validateSidebarItem);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
validateSidebarItem(sidebar);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
exports.validateSidebars = validateSidebars;
|
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 { LoadedContent } from './types';
|
|
7
|
+
import type { LoadedContent } from './types';
|
|
8
8
|
import { TranslationFile, TranslationFiles } from '@docusaurus/types';
|
|
9
9
|
export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent): TranslationFiles;
|
|
10
10
|
export declare function translateLoadedContent(loadedContent: LoadedContent, translationFiles: TranslationFile[]): LoadedContent;
|
package/lib/translations.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const utils_1 = require("./sidebars/utils");
|
|
12
|
+
const utils_2 = require("@docusaurus/utils");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
14
|
function getVersionFileName(versionName) {
|
|
15
15
|
if (versionName === constants_1.CURRENT_VERSION_NAME) {
|
|
@@ -74,7 +74,7 @@ function translateDocs(
|
|
|
74
74
|
}
|
|
75
75
|
*/
|
|
76
76
|
function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
77
|
-
const categories = (0,
|
|
77
|
+
const categories = (0, utils_1.collectSidebarCategories)(sidebar);
|
|
78
78
|
const categoryContent = (0, lodash_1.chain)(categories)
|
|
79
79
|
.keyBy((category) => `sidebar.${sidebarName}.category.${category.label}`)
|
|
80
80
|
.mapValues((category) => ({
|
|
@@ -82,7 +82,7 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
82
82
|
description: `The label for category ${category.label} in sidebar ${sidebarName}`,
|
|
83
83
|
}))
|
|
84
84
|
.value();
|
|
85
|
-
const links = (0,
|
|
85
|
+
const links = (0, utils_1.collectSidebarLinks)(sidebar);
|
|
86
86
|
const linksContent = (0, lodash_1.chain)(links)
|
|
87
87
|
.keyBy((link) => `sidebar.${sidebarName}.link.${link.label}`)
|
|
88
88
|
.mapValues((link) => ({
|
|
@@ -90,10 +90,10 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
90
90
|
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
91
91
|
}))
|
|
92
92
|
.value();
|
|
93
|
-
return (0,
|
|
93
|
+
return (0, utils_2.mergeTranslations)([categoryContent, linksContent]);
|
|
94
94
|
}
|
|
95
95
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
96
|
-
return (0,
|
|
96
|
+
return (0, utils_1.transformSidebarItems)(sidebar, (item) => {
|
|
97
97
|
var _a, _b, _c, _d;
|
|
98
98
|
if (item.type === 'category') {
|
|
99
99
|
return {
|
|
@@ -111,7 +111,7 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
function getSidebarsTranslations(version) {
|
|
114
|
-
return (0,
|
|
114
|
+
return (0, utils_2.mergeTranslations)(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
|
|
115
115
|
const normalizedSidebarName = getNormalizedSidebarName({
|
|
116
116
|
sidebarName,
|
|
117
117
|
versionName: version.versionName,
|
|
@@ -143,7 +143,7 @@ function getVersionTranslationFiles(version) {
|
|
|
143
143
|
return [
|
|
144
144
|
{
|
|
145
145
|
path: getVersionFileName(version.versionName),
|
|
146
|
-
content: (0,
|
|
146
|
+
content: (0, utils_2.mergeTranslations)([
|
|
147
147
|
versionTranslations,
|
|
148
148
|
sidebarsTranslations,
|
|
149
149
|
// docsTranslations,
|
|
@@ -162,7 +162,7 @@ function translateVersion(version, translationFiles) {
|
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
function getVersionsTranslationFiles(versions) {
|
|
165
|
-
return
|
|
165
|
+
return versions.flatMap(getVersionTranslationFiles);
|
|
166
166
|
}
|
|
167
167
|
function translateVersions(versions, translationFiles) {
|
|
168
168
|
return versions.map((version) => translateVersion(version, translationFiles));
|
package/lib/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type { RemarkAndRehypePluginOptions } from '@docusaurus/mdx-loader';
|
|
8
8
|
import type { Tag, FrontMatterTag } from '@docusaurus/utils';
|
|
9
9
|
import type { BrokenMarkdownLink as IBrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
|
|
10
|
+
import type { SidebarItemsGeneratorOption, Sidebars } from './sidebars/types';
|
|
10
11
|
export declare type DocFile = {
|
|
11
12
|
contentPath: string;
|
|
12
13
|
filePath: string;
|
|
@@ -81,64 +82,6 @@ export declare type PluginOptions = MetadataOptions & PathOptions & VersionsOpti
|
|
|
81
82
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
82
83
|
tagsBasePath: string;
|
|
83
84
|
};
|
|
84
|
-
export declare type SidebarItemBase = {
|
|
85
|
-
className?: string;
|
|
86
|
-
customProps?: Record<string, unknown>;
|
|
87
|
-
};
|
|
88
|
-
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
89
|
-
type: 'doc' | 'ref';
|
|
90
|
-
label?: string;
|
|
91
|
-
id: string;
|
|
92
|
-
};
|
|
93
|
-
export declare type SidebarItemLink = SidebarItemBase & {
|
|
94
|
-
type: 'link';
|
|
95
|
-
href: string;
|
|
96
|
-
label: string;
|
|
97
|
-
};
|
|
98
|
-
export declare type SidebarItemCategory = SidebarItemBase & {
|
|
99
|
-
type: 'category';
|
|
100
|
-
label: string;
|
|
101
|
-
items: SidebarItem[];
|
|
102
|
-
collapsed: boolean;
|
|
103
|
-
collapsible: boolean;
|
|
104
|
-
};
|
|
105
|
-
export declare type UnprocessedSidebarItemAutogenerated = {
|
|
106
|
-
type: 'autogenerated';
|
|
107
|
-
dirName: string;
|
|
108
|
-
};
|
|
109
|
-
export declare type UnprocessedSidebarItemCategory = SidebarItemBase & {
|
|
110
|
-
type: 'category';
|
|
111
|
-
label: string;
|
|
112
|
-
items: UnprocessedSidebarItem[];
|
|
113
|
-
collapsed: boolean;
|
|
114
|
-
collapsible: boolean;
|
|
115
|
-
};
|
|
116
|
-
export declare type UnprocessedSidebarItem = SidebarItemDoc | SidebarItemLink | UnprocessedSidebarItemCategory | UnprocessedSidebarItemAutogenerated;
|
|
117
|
-
export declare type UnprocessedSidebar = UnprocessedSidebarItem[];
|
|
118
|
-
export declare type UnprocessedSidebars = Record<string, UnprocessedSidebar>;
|
|
119
|
-
export declare type SidebarItem = SidebarItemDoc | SidebarItemLink | SidebarItemCategory;
|
|
120
|
-
export declare type Sidebar = SidebarItem[];
|
|
121
|
-
export declare type SidebarItemType = SidebarItem['type'];
|
|
122
|
-
export declare type Sidebars = Record<string, Sidebar>;
|
|
123
|
-
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
124
|
-
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
125
|
-
export declare type SidebarItemsGeneratorArgs = {
|
|
126
|
-
item: UnprocessedSidebarItemAutogenerated;
|
|
127
|
-
version: SidebarItemsGeneratorVersion;
|
|
128
|
-
docs: SidebarItemsGeneratorDoc[];
|
|
129
|
-
numberPrefixParser: NumberPrefixParser;
|
|
130
|
-
options: SidebarOptions;
|
|
131
|
-
};
|
|
132
|
-
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
|
|
133
|
-
export declare type SidebarItemsGeneratorOptionArgs = {
|
|
134
|
-
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
135
|
-
} & SidebarItemsGeneratorArgs;
|
|
136
|
-
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<SidebarItem[]>;
|
|
137
|
-
export declare type OrderMetadata = {
|
|
138
|
-
previous?: string;
|
|
139
|
-
next?: string;
|
|
140
|
-
sidebar?: string;
|
|
141
|
-
};
|
|
142
85
|
export declare type LastUpdateData = {
|
|
143
86
|
lastUpdatedAt?: number;
|
|
144
87
|
formattedLastUpdatedAt?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4075",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-docs.d.ts",
|
|
@@ -18,18 +18,19 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
21
|
+
"@docusaurus/module-type-aliases": "0.0.0-4075",
|
|
22
22
|
"@types/js-yaml": "^4.0.0",
|
|
23
23
|
"@types/picomatch": "^2.2.1",
|
|
24
24
|
"commander": "^5.1.0",
|
|
25
|
-
"picomatch": "^2.1.1"
|
|
25
|
+
"picomatch": "^2.1.1",
|
|
26
|
+
"utility-types": "^3.10.0"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@docusaurus/core": "0.0.0-
|
|
29
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
30
|
-
"@docusaurus/types": "0.0.0-
|
|
31
|
-
"@docusaurus/utils": "0.0.0-
|
|
32
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
29
|
+
"@docusaurus/core": "0.0.0-4075",
|
|
30
|
+
"@docusaurus/mdx-loader": "0.0.0-4075",
|
|
31
|
+
"@docusaurus/types": "0.0.0-4075",
|
|
32
|
+
"@docusaurus/utils": "0.0.0-4075",
|
|
33
|
+
"@docusaurus/utils-validation": "0.0.0-4075",
|
|
33
34
|
"chalk": "^4.1.2",
|
|
34
35
|
"combine-promises": "^1.1.0",
|
|
35
36
|
"escape-string-regexp": "^4.0.0",
|
|
@@ -53,5 +54,5 @@
|
|
|
53
54
|
"engines": {
|
|
54
55
|
"node": ">=12.13.0"
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "8a2dfe320e0bfe6a6833d610c824846f649986e3"
|
|
57
58
|
}
|
|
@@ -22,17 +22,16 @@ import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
|
|
|
22
22
|
import * as cliDocs from '../cli';
|
|
23
23
|
import {OptionsSchema} from '../options';
|
|
24
24
|
import {normalizePluginOptions} from '@docusaurus/utils-validation';
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
LoadedVersion,
|
|
25
|
+
import type {DocMetadata, LoadedVersion} from '../types';
|
|
26
|
+
import type {
|
|
28
27
|
SidebarItem,
|
|
29
28
|
SidebarItemsGeneratorOption,
|
|
30
29
|
SidebarItemsGeneratorOptionArgs,
|
|
31
|
-
} from '../types';
|
|
30
|
+
} from '../sidebars/types';
|
|
32
31
|
import {toSidebarsProp} from '../props';
|
|
33
32
|
|
|
34
33
|
import {validate} from 'webpack';
|
|
35
|
-
import {DefaultSidebarItemsGenerator} from '../
|
|
34
|
+
import {DefaultSidebarItemsGenerator} from '../sidebars/generator';
|
|
36
35
|
import {DisabledSidebars} from '../sidebars';
|
|
37
36
|
|
|
38
37
|
function findDocById(version: LoadedVersion, unversionedId: string) {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {OptionsSchema, DEFAULT_OPTIONS, validateOptions} from '../options';
|
|
9
9
|
import {normalizePluginOptions} from '@docusaurus/utils-validation';
|
|
10
|
-
import {DefaultSidebarItemsGenerator} from '../
|
|
10
|
+
import {DefaultSidebarItemsGenerator} from '../sidebars/generator';
|
|
11
11
|
import {
|
|
12
12
|
DefaultNumberPrefixParser,
|
|
13
13
|
DisabledNumberPrefixParser,
|
package/src/cli.ts
CHANGED
|
@@ -12,13 +12,10 @@ import {
|
|
|
12
12
|
} from './versions';
|
|
13
13
|
import fs from 'fs-extra';
|
|
14
14
|
import path from 'path';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
SidebarOptions,
|
|
20
|
-
} from './types';
|
|
21
|
-
import {loadSidebars, resolveSidebarPathOption} from './sidebars';
|
|
15
|
+
import type {PathOptions, SidebarOptions} from './types';
|
|
16
|
+
import {transformSidebarItems} from './sidebars/utils';
|
|
17
|
+
import type {SidebarItem, NormalizedSidebars, Sidebar} from './sidebars/types';
|
|
18
|
+
import {loadUnprocessedSidebars, resolveSidebarPathOption} from './sidebars';
|
|
22
19
|
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
|
|
23
20
|
|
|
24
21
|
function createVersionedSidebarFile({
|
|
@@ -35,7 +32,7 @@ function createVersionedSidebarFile({
|
|
|
35
32
|
options: SidebarOptions;
|
|
36
33
|
}) {
|
|
37
34
|
// Load current sidebar and create a new versioned sidebars file (if needed).
|
|
38
|
-
const loadedSidebars =
|
|
35
|
+
const loadedSidebars = loadUnprocessedSidebars(sidebarPath, options);
|
|
39
36
|
|
|
40
37
|
// Do not create a useless versioned sidebars file if sidebars file is empty or sidebars are disabled/false)
|
|
41
38
|
const shouldCreateVersionedSidebarFile =
|
|
@@ -45,30 +42,27 @@ function createVersionedSidebarFile({
|
|
|
45
42
|
// TODO @slorber: this "version prefix" in versioned sidebars looks like a bad idea to me
|
|
46
43
|
// TODO try to get rid of it
|
|
47
44
|
// Transform id in original sidebar to versioned id.
|
|
48
|
-
const
|
|
49
|
-
item
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
case 'ref':
|
|
55
|
-
case 'doc':
|
|
56
|
-
return {
|
|
57
|
-
type: item.type,
|
|
58
|
-
id: `version-${version}/${item.id}`,
|
|
59
|
-
};
|
|
60
|
-
default:
|
|
61
|
-
return item;
|
|
45
|
+
const prependVersion = (item: SidebarItem): SidebarItem => {
|
|
46
|
+
if (item.type === 'ref' || item.type === 'doc') {
|
|
47
|
+
return {
|
|
48
|
+
type: item.type,
|
|
49
|
+
id: `version-${version}/${item.id}`,
|
|
50
|
+
};
|
|
62
51
|
}
|
|
52
|
+
return item;
|
|
63
53
|
};
|
|
64
54
|
|
|
65
|
-
const versionedSidebar
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
const versionedSidebar = Object.entries(loadedSidebars).reduce(
|
|
56
|
+
(acc: NormalizedSidebars, [sidebarId, sidebar]) => {
|
|
57
|
+
const versionedId = `version-${version}/${sidebarId}`;
|
|
58
|
+
acc[versionedId] = transformSidebarItems(
|
|
59
|
+
sidebar as Sidebar,
|
|
60
|
+
prependVersion,
|
|
61
|
+
);
|
|
62
|
+
return acc;
|
|
63
|
+
},
|
|
64
|
+
{},
|
|
65
|
+
);
|
|
72
66
|
|
|
73
67
|
const versionedSidebarsDir = getVersionedSidebarsDirPath(siteDir, pluginId);
|
|
74
68
|
const newSidebarFile = path.join(
|
package/src/index.ts
CHANGED
|
@@ -21,7 +21,9 @@ import {
|
|
|
21
21
|
createAbsoluteFilePathMatcher,
|
|
22
22
|
} from '@docusaurus/utils';
|
|
23
23
|
import {LoadContext, Plugin, RouteConfig} from '@docusaurus/types';
|
|
24
|
-
import {loadSidebars
|
|
24
|
+
import {loadSidebars} from './sidebars';
|
|
25
|
+
import {createSidebarsUtils} from './sidebars/utils';
|
|
26
|
+
import {CategoryMetadataFilenamePattern} from './sidebars/generator';
|
|
25
27
|
import {readVersionDocs, processDocMetadata} from './docs';
|
|
26
28
|
import {getDocsDirPaths, readVersionsMetadata} from './versions';
|
|
27
29
|
|
|
@@ -42,14 +44,13 @@ import {
|
|
|
42
44
|
import {RuleSetRule} from 'webpack';
|
|
43
45
|
import {cliDocsVersionCommand} from './cli';
|
|
44
46
|
import {VERSIONS_JSON_FILE} from './constants';
|
|
45
|
-
import {
|
|
47
|
+
import {keyBy, compact, mapValues} from 'lodash';
|
|
46
48
|
import {toGlobalDataVersion} from './globalData';
|
|
47
49
|
import {toTagDocListProp, toVersionMetadataProp} from './props';
|
|
48
50
|
import {
|
|
49
51
|
translateLoadedContent,
|
|
50
52
|
getLoadedContentTranslationFiles,
|
|
51
53
|
} from './translations';
|
|
52
|
-
import {CategoryMetadataFilenamePattern} from './sidebarItemsGenerator';
|
|
53
54
|
import chalk from 'chalk';
|
|
54
55
|
import {getVersionTags} from './tags';
|
|
55
56
|
import {PropTagsListPage} from '@docusaurus/plugin-content-docs-types';
|
|
@@ -116,11 +117,9 @@ export default function pluginContentDocs(
|
|
|
116
117
|
getPathsToWatch() {
|
|
117
118
|
function getVersionPathsToWatch(version: VersionMetadata): string[] {
|
|
118
119
|
const result = [
|
|
119
|
-
...
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
(docsDirPath) => `${docsDirPath}/${pattern}`,
|
|
123
|
-
),
|
|
120
|
+
...options.include.flatMap((pattern) =>
|
|
121
|
+
getDocsDirPaths(version).map(
|
|
122
|
+
(docsDirPath) => `${docsDirPath}/${pattern}`,
|
|
124
123
|
),
|
|
125
124
|
),
|
|
126
125
|
`${version.contentPath}/**/${CategoryMetadataFilenamePattern}`,
|
|
@@ -131,7 +130,7 @@ export default function pluginContentDocs(
|
|
|
131
130
|
return result;
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
return
|
|
133
|
+
return versionsMetadata.flatMap(getVersionPathsToWatch);
|
|
135
134
|
},
|
|
136
135
|
|
|
137
136
|
async loadContent() {
|
|
@@ -163,14 +162,6 @@ export default function pluginContentDocs(
|
|
|
163
162
|
async function doLoadVersion(
|
|
164
163
|
versionMetadata: VersionMetadata,
|
|
165
164
|
): Promise<LoadedVersion> {
|
|
166
|
-
const unprocessedSidebars = loadSidebars(
|
|
167
|
-
versionMetadata.sidebarFilePath,
|
|
168
|
-
{
|
|
169
|
-
sidebarCollapsed: options.sidebarCollapsed,
|
|
170
|
-
sidebarCollapsible: options.sidebarCollapsible,
|
|
171
|
-
},
|
|
172
|
-
);
|
|
173
|
-
|
|
174
165
|
const docsBase: DocMetadataBase[] = await loadVersionDocsBase(
|
|
175
166
|
versionMetadata,
|
|
176
167
|
);
|
|
@@ -179,10 +170,9 @@ export default function pluginContentDocs(
|
|
|
179
170
|
(doc) => doc.id,
|
|
180
171
|
);
|
|
181
172
|
|
|
182
|
-
const sidebars = await
|
|
173
|
+
const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, {
|
|
183
174
|
sidebarItemsGenerator: options.sidebarItemsGenerator,
|
|
184
175
|
numberPrefixParser: options.numberPrefixParser,
|
|
185
|
-
unprocessedSidebars,
|
|
186
176
|
docs: docsBase,
|
|
187
177
|
version: versionMetadata,
|
|
188
178
|
options: {
|
|
@@ -191,18 +181,21 @@ export default function pluginContentDocs(
|
|
|
191
181
|
},
|
|
192
182
|
});
|
|
193
183
|
|
|
194
|
-
const
|
|
184
|
+
const {
|
|
185
|
+
checkSidebarsDocIds,
|
|
186
|
+
getDocNavigation,
|
|
187
|
+
getFirstDocIdOfFirstSidebar,
|
|
188
|
+
} = createSidebarsUtils(sidebars);
|
|
195
189
|
|
|
196
190
|
const validDocIds = Object.keys(docsBaseById);
|
|
197
|
-
|
|
191
|
+
checkSidebarsDocIds(
|
|
198
192
|
validDocIds,
|
|
199
193
|
versionMetadata.sidebarFilePath as string,
|
|
200
194
|
);
|
|
201
195
|
|
|
202
196
|
// Add sidebar/next/previous to the docs
|
|
203
197
|
function addNavData(doc: DocMetadataBase): DocMetadata {
|
|
204
|
-
const {sidebarName, previousId, nextId} =
|
|
205
|
-
sidebarsUtils.getDocNavigation(doc.id);
|
|
198
|
+
const {sidebarName, previousId, nextId} = getDocNavigation(doc.id);
|
|
206
199
|
const toDocNavLink = (navDocId: string): DocNavLink => {
|
|
207
200
|
const {title, permalink, frontMatter} = docsBaseById[navDocId];
|
|
208
201
|
return {
|
|
@@ -236,8 +229,7 @@ export default function pluginContentDocs(
|
|
|
236
229
|
(doc) =>
|
|
237
230
|
doc.unversionedId === options.homePageId || doc.slug === '/',
|
|
238
231
|
);
|
|
239
|
-
const firstDocIdOfFirstSidebar =
|
|
240
|
-
sidebarsUtils.getFirstDocIdOfFirstSidebar();
|
|
232
|
+
const firstDocIdOfFirstSidebar = getFirstDocIdOfFirstSidebar();
|
|
241
233
|
if (versionHomeDoc) {
|
|
242
234
|
return versionHomeDoc;
|
|
243
235
|
} else if (firstDocIdOfFirstSidebar) {
|
|
@@ -429,7 +421,7 @@ export default function pluginContentDocs(
|
|
|
429
421
|
} = options;
|
|
430
422
|
|
|
431
423
|
function getSourceToPermalink(): SourceToPermalink {
|
|
432
|
-
const allDocs =
|
|
424
|
+
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
433
425
|
return mapValues(
|
|
434
426
|
keyBy(allDocs, (d) => d.source),
|
|
435
427
|
(d) => d.permalink,
|
|
@@ -452,7 +444,7 @@ export default function pluginContentDocs(
|
|
|
452
444
|
};
|
|
453
445
|
|
|
454
446
|
function createMDXLoaderRule(): RuleSetRule {
|
|
455
|
-
const contentDirs =
|
|
447
|
+
const contentDirs = versionsMetadata.flatMap(getDocsDirPaths);
|
|
456
448
|
return {
|
|
457
449
|
test: /(\.mdx?)$/,
|
|
458
450
|
include: contentDirs
|
package/src/options.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {GlobExcludeDefault} from '@docusaurus/utils';
|
|
|
17
17
|
import {OptionValidationContext, ValidationResult} from '@docusaurus/types';
|
|
18
18
|
import chalk from 'chalk';
|
|
19
19
|
import admonitions from 'remark-admonitions';
|
|
20
|
-
import {DefaultSidebarItemsGenerator} from './
|
|
20
|
+
import {DefaultSidebarItemsGenerator} from './sidebars/generator';
|
|
21
21
|
import {
|
|
22
22
|
DefaultNumberPrefixParser,
|
|
23
23
|
DisabledNumberPrefixParser,
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
declare module '@docusaurus/plugin-content-docs' {
|
|
9
9
|
export type Options = Partial<import('./types').PluginOptions>;
|
|
10
|
+
export type SidebarsConfig = import('./sidebars/types').SidebarsConfig;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
// TODO public api surface types should rather be exposed as "@docusaurus/plugin-content-docs"
|
|
@@ -29,30 +30,11 @@ declare module '@docusaurus/plugin-content-docs-types' {
|
|
|
29
30
|
docsSidebars: PropSidebars;
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
type
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export type PropSidebarItemLink = PropsSidebarItemBase & {
|
|
38
|
-
type: 'link';
|
|
39
|
-
href: string;
|
|
40
|
-
label: string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type PropSidebarItemCategory = PropsSidebarItemBase & {
|
|
44
|
-
type: 'category';
|
|
45
|
-
label: string;
|
|
46
|
-
items: PropSidebarItem[];
|
|
47
|
-
collapsed: boolean;
|
|
48
|
-
collapsible: boolean;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory;
|
|
52
|
-
|
|
53
|
-
export type PropSidebars = {
|
|
54
|
-
[sidebarId: string]: PropSidebarItem[];
|
|
55
|
-
};
|
|
33
|
+
export type PropSidebarItemLink = import('./sidebars/types').SidebarItemLink;
|
|
34
|
+
export type PropSidebarItemCategory =
|
|
35
|
+
import('./sidebars/types').PropSidebarItemCategory;
|
|
36
|
+
export type PropSidebarItem = import('./sidebars/types').PropSidebarItem;
|
|
37
|
+
export type PropSidebars = import('./sidebars/types').PropSidebars;
|
|
56
38
|
|
|
57
39
|
export type PropTagDocListDoc = {
|
|
58
40
|
id: string;
|
package/src/props.ts
CHANGED
|
@@ -5,14 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {LoadedVersion, VersionTag, DocMetadata} from './types';
|
|
9
|
+
import type {
|
|
10
10
|
SidebarItemDoc,
|
|
11
11
|
SidebarItemLink,
|
|
12
12
|
SidebarItem,
|
|
13
|
-
|
|
14
|
-
DocMetadata,
|
|
15
|
-
} from './types';
|
|
13
|
+
} from './sidebars/types';
|
|
16
14
|
import type {
|
|
17
15
|
PropSidebars,
|
|
18
16
|
PropVersionMetadata,
|
package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json
RENAMED
|
File without changes
|
|
File without changes
|
package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json
RENAMED
|
File without changes
|
package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json
RENAMED
|
File without changes
|
|
File without changes
|
package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json
RENAMED
|
File without changes
|
package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json
RENAMED
|
File without changes
|
|
File without changes
|