@azerion/bunosaurus-plugin-content-docs 0.0.0-stage → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/lib/categoryGeneratedIndex.d.ts +12 -0
- package/lib/categoryGeneratedIndex.js +36 -0
- package/lib/cli.d.ts +13 -0
- package/lib/cli.js +124 -0
- package/lib/client/doc.d.ts +29 -0
- package/lib/client/doc.js +47 -0
- package/lib/client/docSidebarItemsExpandedState.d.ts +30 -0
- package/lib/client/docSidebarItemsExpandedState.js +27 -0
- package/lib/client/docsClientUtils.d.ts +15 -0
- package/lib/client/docsClientUtils.js +86 -0
- package/lib/client/docsPreferredVersion.d.ts +29 -0
- package/lib/client/docsPreferredVersion.js +124 -0
- package/lib/client/docsSearch.d.ts +19 -0
- package/lib/client/docsSearch.js +39 -0
- package/lib/client/docsSidebar.d.ts +25 -0
- package/lib/client/docsSidebar.js +29 -0
- package/lib/client/docsUtils.d.ts +112 -0
- package/lib/client/docsUtils.js +299 -0
- package/lib/client/docsVersion.d.ts +19 -0
- package/lib/client/docsVersion.js +25 -0
- package/lib/client/index.d.ts +91 -0
- package/lib/client/index.js +83 -0
- package/lib/client/structuredDataUtils.d.ts +11 -0
- package/lib/client/structuredDataUtils.js +35 -0
- package/lib/constants.d.ts +14 -0
- package/lib/constants.js +17 -0
- package/lib/contentHelpers.d.ts +12 -0
- package/lib/contentHelpers.js +31 -0
- package/lib/docs.d.ts +48 -0
- package/lib/docs.js +252 -0
- package/lib/frontMatter.d.ts +10 -0
- package/lib/frontMatter.js +46 -0
- package/lib/globalData.d.ts +9 -0
- package/lib/globalData.js +59 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +198 -0
- package/lib/numberPrefix.d.ts +11 -0
- package/lib/numberPrefix.js +50 -0
- package/lib/options.d.ts +10 -0
- package/lib/options.js +138 -0
- package/lib/props.d.ts +21 -0
- package/lib/props.js +156 -0
- package/lib/routes.d.ts +22 -0
- package/lib/routes.js +184 -0
- package/lib/server-export.d.ts +9 -0
- package/lib/server-export.js +25 -0
- package/lib/sidebars/generator.d.ts +10 -0
- package/lib/sidebars/generator.js +217 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +99 -0
- package/lib/sidebars/normalization.d.ts +13 -0
- package/lib/sidebars/normalization.js +58 -0
- package/lib/sidebars/postProcessor.d.ts +11 -0
- package/lib/sidebars/postProcessor.js +82 -0
- package/lib/sidebars/processor.d.ts +10 -0
- package/lib/sidebars/processor.js +77 -0
- package/lib/sidebars/types.d.ts +192 -0
- package/lib/sidebars/types.js +8 -0
- package/lib/sidebars/utils.d.ts +69 -0
- package/lib/sidebars/utils.js +327 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +152 -0
- package/lib/slug.d.ts +15 -0
- package/lib/slug.js +51 -0
- package/lib/translations.d.ts +10 -0
- package/lib/translations.js +243 -0
- package/lib/types.d.ts +27 -0
- package/lib/types.js +8 -0
- package/lib/versions/files.d.ts +54 -0
- package/lib/versions/files.js +152 -0
- package/lib/versions/loadVersion.d.ts +17 -0
- package/lib/versions/loadVersion.js +126 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +70 -0
- package/lib/versions/version.d.ts +40 -0
- package/lib/versions/version.js +189 -0
- package/package.json +70 -4
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +180 -0
- package/src/client/doc.tsx +71 -0
- package/src/client/docSidebarItemsExpandedState.tsx +55 -0
- package/src/client/docsClientUtils.ts +140 -0
- package/src/client/docsPreferredVersion.tsx +245 -0
- package/src/client/docsSearch.test.ts +15 -0
- package/src/client/docsSearch.ts +57 -0
- package/src/client/docsSidebar.tsx +50 -0
- package/src/client/docsUtils.tsx +442 -0
- package/src/client/docsVersion.tsx +36 -0
- package/src/client/index.ts +211 -0
- package/src/client/structuredDataUtils.ts +54 -0
- package/src/constants.ts +15 -0
- package/src/contentHelpers.ts +34 -0
- package/src/docs.ts +402 -0
- package/src/frontMatter.ts +57 -0
- package/src/globalData.ts +79 -0
- package/src/index.ts +289 -0
- package/src/numberPrefix.ts +62 -0
- package/src/options.ts +185 -0
- package/src/plugin-content-docs.d.ts +667 -0
- package/src/props.ts +223 -0
- package/src/routes.ts +263 -0
- package/src/server-export.ts +26 -0
- package/src/sidebars/README.md +10 -0
- package/src/sidebars/generator.ts +307 -0
- package/src/sidebars/index.ts +130 -0
- package/src/sidebars/normalization.ts +91 -0
- package/src/sidebars/postProcessor.ts +115 -0
- package/src/sidebars/processor.ts +122 -0
- package/src/sidebars/types.ts +293 -0
- package/src/sidebars/utils.ts +529 -0
- package/src/sidebars/validation.ts +189 -0
- package/src/slug.ts +79 -0
- package/src/translations.ts +365 -0
- package/src/types.ts +34 -0
- package/src/versions/files.ts +240 -0
- package/src/versions/loadVersion.ts +185 -0
- package/src/versions/validation.ts +115 -0
- package/src/versions/version.ts +300 -0
package/lib/routes.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
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.buildAllRoutes = buildAllRoutes;
|
|
10
|
+
exports.createAllRoutes = createAllRoutes;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
const props_1 = require("./props");
|
|
16
|
+
function createDocRouteMetadata(docMeta) {
|
|
17
|
+
return {
|
|
18
|
+
sourceFilePath: (0, utils_1.aliasedSitePathToRelativePath)(docMeta.source),
|
|
19
|
+
lastUpdatedAt: docMeta.lastUpdatedAt,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async function buildVersionCategoryGeneratedIndexRoutes({ version, options, }) {
|
|
23
|
+
async function buildCategoryGeneratedIndexRoute(categoryGeneratedIndex) {
|
|
24
|
+
return {
|
|
25
|
+
path: categoryGeneratedIndex.permalink,
|
|
26
|
+
component: options.docCategoryGeneratedIndexComponent,
|
|
27
|
+
exact: true,
|
|
28
|
+
props: {
|
|
29
|
+
categoryGeneratedIndex,
|
|
30
|
+
},
|
|
31
|
+
// Same as doc, this sidebar route attribute permits to associate this
|
|
32
|
+
// subpage to the given sidebar
|
|
33
|
+
...(categoryGeneratedIndex.sidebar && {
|
|
34
|
+
sidebar: categoryGeneratedIndex.sidebar,
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return Promise.all(version.categoryGeneratedIndices.map(buildCategoryGeneratedIndexRoute));
|
|
39
|
+
}
|
|
40
|
+
async function buildVersionDocRoutes({ version, actions, options, }) {
|
|
41
|
+
return Promise.all(version.docs.map(async (doc) => {
|
|
42
|
+
await actions.createData(
|
|
43
|
+
// Note that this created data path must be in sync with
|
|
44
|
+
// metadataPath provided to mdx-loader.
|
|
45
|
+
`${(0, utils_1.docuHash)(doc.source)}.json`, doc);
|
|
46
|
+
const docRoute = {
|
|
47
|
+
path: doc.permalink,
|
|
48
|
+
component: options.docItemComponent,
|
|
49
|
+
exact: true,
|
|
50
|
+
modules: {
|
|
51
|
+
content: doc.source,
|
|
52
|
+
},
|
|
53
|
+
metadata: createDocRouteMetadata(doc),
|
|
54
|
+
// Because the parent (DocRoot) comp need to access it easily
|
|
55
|
+
// This permits to render the sidebar once without unmount/remount when
|
|
56
|
+
// navigating (and preserve sidebar state)
|
|
57
|
+
...(doc.sidebar && {
|
|
58
|
+
sidebar: doc.sidebar,
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
return docRoute;
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
async function buildVersionSidebarRoute(param) {
|
|
65
|
+
const [docRoutes, categoryGeneratedIndexRoutes] = await Promise.all([
|
|
66
|
+
buildVersionDocRoutes(param),
|
|
67
|
+
buildVersionCategoryGeneratedIndexRoutes(param),
|
|
68
|
+
]);
|
|
69
|
+
const subRoutes = [...docRoutes, ...categoryGeneratedIndexRoutes];
|
|
70
|
+
return {
|
|
71
|
+
path: param.version.path,
|
|
72
|
+
exact: false,
|
|
73
|
+
component: param.options.docRootComponent,
|
|
74
|
+
routes: subRoutes,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function getVersionTags(docs) {
|
|
78
|
+
const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
|
|
79
|
+
return lodash_1.default.mapValues(groups, ({ tag, items: tagDocs }) => {
|
|
80
|
+
const tagVisibility = (0, utils_1.getTagVisibility)({
|
|
81
|
+
items: tagDocs,
|
|
82
|
+
isUnlisted: (item) => item.unlisted,
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
inline: tag.inline,
|
|
86
|
+
label: tag.label,
|
|
87
|
+
permalink: tag.permalink,
|
|
88
|
+
description: tag.description,
|
|
89
|
+
docIds: tagVisibility.listedItems.map((item) => item.id),
|
|
90
|
+
unlisted: tagVisibility.unlisted,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async function buildVersionTagsRoutes(param) {
|
|
95
|
+
const { version, options } = param;
|
|
96
|
+
const versionTags = getVersionTags(version.docs);
|
|
97
|
+
async function buildTagsListRoute() {
|
|
98
|
+
const tags = (0, props_1.toTagsListTagsProp)(versionTags);
|
|
99
|
+
// Don't create a tags list page if there's no tag
|
|
100
|
+
if (tags.length === 0) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
path: version.tagsPath,
|
|
105
|
+
exact: true,
|
|
106
|
+
component: options.docTagsListComponent,
|
|
107
|
+
props: {
|
|
108
|
+
tags,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async function buildTagDocListRoute(tag) {
|
|
113
|
+
return {
|
|
114
|
+
path: tag.permalink,
|
|
115
|
+
component: options.docTagDocListComponent,
|
|
116
|
+
exact: true,
|
|
117
|
+
props: {
|
|
118
|
+
tag: (0, props_1.toTagDocListProp)({
|
|
119
|
+
allTagsPath: version.tagsPath,
|
|
120
|
+
tag,
|
|
121
|
+
docs: version.docs,
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const [tagsListRoute, allTagsDocListRoutes] = await Promise.all([
|
|
127
|
+
buildTagsListRoute(),
|
|
128
|
+
Promise.all(Object.values(versionTags).map(buildTagDocListRoute)),
|
|
129
|
+
]);
|
|
130
|
+
return lodash_1.default.compact([tagsListRoute, ...allTagsDocListRoutes]);
|
|
131
|
+
}
|
|
132
|
+
async function buildVersionRoutes(param) {
|
|
133
|
+
const { version, options } = param;
|
|
134
|
+
async function buildVersionSubRoutes() {
|
|
135
|
+
const [sidebarRoute, tagsRoutes] = await Promise.all([
|
|
136
|
+
buildVersionSidebarRoute(param),
|
|
137
|
+
buildVersionTagsRoutes(param),
|
|
138
|
+
]);
|
|
139
|
+
return [sidebarRoute, ...tagsRoutes];
|
|
140
|
+
}
|
|
141
|
+
async function doBuildVersionRoutes() {
|
|
142
|
+
return {
|
|
143
|
+
path: version.path,
|
|
144
|
+
exact: false,
|
|
145
|
+
component: options.docVersionRootComponent,
|
|
146
|
+
routes: await buildVersionSubRoutes(),
|
|
147
|
+
props: {
|
|
148
|
+
// TODO Docusaurus v4 breaking change?
|
|
149
|
+
// expose version metadata as route context instead of props
|
|
150
|
+
version: (0, props_1.toVersionMetadataProp)(options.id, version),
|
|
151
|
+
},
|
|
152
|
+
priority: version.routePriority,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return await doBuildVersionRoutes();
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
logger_1.default.error `Can't create version routes for version name=${version.versionName}`;
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// TODO we want this buildAllRoutes function to be easily testable
|
|
164
|
+
// Ideally, we should avoid side effects here (ie not injecting actions)
|
|
165
|
+
async function buildAllRoutes(param) {
|
|
166
|
+
const subRoutes = await Promise.all(param.versions.map((version) => buildVersionRoutes({
|
|
167
|
+
...param,
|
|
168
|
+
version,
|
|
169
|
+
})));
|
|
170
|
+
// all docs routes are wrapped under a single parent route, this ensures
|
|
171
|
+
// the theme layout never unmounts/remounts when navigating between versions
|
|
172
|
+
return [
|
|
173
|
+
{
|
|
174
|
+
path: (0, utils_1.normalizeUrl)([param.baseUrl, param.options.routeBasePath]),
|
|
175
|
+
exact: false,
|
|
176
|
+
component: param.options.docsRootComponent,
|
|
177
|
+
routes: subRoutes,
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
async function createAllRoutes(param) {
|
|
182
|
+
const routes = await buildAllRoutes(param);
|
|
183
|
+
routes.forEach(param.actions.addRoute);
|
|
184
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
export { CURRENT_VERSION_NAME, VERSIONED_DOCS_DIR, VERSIONED_SIDEBARS_DIR, VERSIONS_JSON_FILE, } from './constants';
|
|
8
|
+
export { filterVersions, getDefaultVersionBanner, getVersionBadge, getVersionBanner, } from './versions/version';
|
|
9
|
+
export { readVersionNames } from './versions/files';
|
|
@@ -0,0 +1,25 @@
|
|
|
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.readVersionNames = exports.getVersionBanner = exports.getVersionBadge = exports.getDefaultVersionBanner = exports.filterVersions = exports.VERSIONS_JSON_FILE = exports.VERSIONED_SIDEBARS_DIR = exports.VERSIONED_DOCS_DIR = exports.CURRENT_VERSION_NAME = void 0;
|
|
10
|
+
// APIs available to Node.js
|
|
11
|
+
// Those are undocumented but used by some third-party plugins
|
|
12
|
+
// For this reason it's preferable to avoid doing breaking changes
|
|
13
|
+
// See also https://github.com/facebook/docusaurus/pull/6477
|
|
14
|
+
var constants_1 = require("./constants");
|
|
15
|
+
Object.defineProperty(exports, "CURRENT_VERSION_NAME", { enumerable: true, get: function () { return constants_1.CURRENT_VERSION_NAME; } });
|
|
16
|
+
Object.defineProperty(exports, "VERSIONED_DOCS_DIR", { enumerable: true, get: function () { return constants_1.VERSIONED_DOCS_DIR; } });
|
|
17
|
+
Object.defineProperty(exports, "VERSIONED_SIDEBARS_DIR", { enumerable: true, get: function () { return constants_1.VERSIONED_SIDEBARS_DIR; } });
|
|
18
|
+
Object.defineProperty(exports, "VERSIONS_JSON_FILE", { enumerable: true, get: function () { return constants_1.VERSIONS_JSON_FILE; } });
|
|
19
|
+
var version_1 = require("./versions/version");
|
|
20
|
+
Object.defineProperty(exports, "filterVersions", { enumerable: true, get: function () { return version_1.filterVersions; } });
|
|
21
|
+
Object.defineProperty(exports, "getDefaultVersionBanner", { enumerable: true, get: function () { return version_1.getDefaultVersionBanner; } });
|
|
22
|
+
Object.defineProperty(exports, "getVersionBadge", { enumerable: true, get: function () { return version_1.getVersionBadge; } });
|
|
23
|
+
Object.defineProperty(exports, "getVersionBanner", { enumerable: true, get: function () { return version_1.getVersionBanner; } });
|
|
24
|
+
var files_1 = require("./versions/files");
|
|
25
|
+
Object.defineProperty(exports, "readVersionNames", { enumerable: true, get: function () { return files_1.readVersionNames; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { SidebarItemsGenerator } from './types';
|
|
8
|
+
export declare const CategoryMetadataFilenameBase = "_category_";
|
|
9
|
+
export declare const CategoryMetadataFilenamePattern = "_category_.{json,yml,yaml}";
|
|
10
|
+
export declare const DefaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
@@ -0,0 +1,217 @@
|
|
|
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.DefaultSidebarItemsGenerator = exports.CategoryMetadataFilenamePattern = exports.CategoryMetadataFilenameBase = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const utils_common_1 = require("@docusaurus/utils-common");
|
|
15
|
+
const docs_1 = require("../docs");
|
|
16
|
+
const BreadcrumbSeparator = '/';
|
|
17
|
+
// Just an alias to the make code more explicit
|
|
18
|
+
function getLocalDocId(docId) {
|
|
19
|
+
return lodash_1.default.last(docId.split('/'));
|
|
20
|
+
}
|
|
21
|
+
exports.CategoryMetadataFilenameBase = '_category_';
|
|
22
|
+
exports.CategoryMetadataFilenamePattern = '_category_.{json,yml,yaml}';
|
|
23
|
+
// Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
|
|
24
|
+
const DefaultSidebarItemsGenerator = ({ numberPrefixParser, isCategoryIndex, docs: allDocs, item: { dirName: autogenDir }, categoriesMetadata, }) => {
|
|
25
|
+
const docsById = (0, docs_1.createDocsByIdIndex)(allDocs);
|
|
26
|
+
const findDoc = (docId) => docsById[docId];
|
|
27
|
+
const getDoc = (docId) => {
|
|
28
|
+
const doc = findDoc(docId);
|
|
29
|
+
if (!doc) {
|
|
30
|
+
throw new Error(`Can't find any doc with ID ${docId}.
|
|
31
|
+
Available doc IDs:
|
|
32
|
+
- ${Object.keys(docsById).join('\n- ')}`);
|
|
33
|
+
}
|
|
34
|
+
return doc;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Step 1. Extract the docs that are in the autogen dir.
|
|
38
|
+
*/
|
|
39
|
+
function getAutogenDocs() {
|
|
40
|
+
function isInAutogeneratedDir(doc) {
|
|
41
|
+
return (
|
|
42
|
+
// Doc at the root of the autogenerated sidebar dir
|
|
43
|
+
doc.sourceDirName === autogenDir ||
|
|
44
|
+
// Autogen dir is . and doc is in subfolder
|
|
45
|
+
autogenDir === '.' ||
|
|
46
|
+
// Autogen dir is not . and doc is in subfolder
|
|
47
|
+
// "api/myDoc" startsWith "api/" (note "api2/myDoc" is not included)
|
|
48
|
+
doc.sourceDirName.startsWith((0, utils_common_1.addTrailingSlash)(autogenDir)));
|
|
49
|
+
}
|
|
50
|
+
const docs = allDocs.filter(isInAutogeneratedDir);
|
|
51
|
+
if (docs.length === 0) {
|
|
52
|
+
logger_1.default.warn `No docs found in path=${autogenDir}: can't auto-generate a sidebar.`;
|
|
53
|
+
}
|
|
54
|
+
return docs;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Step 2. Turn the linear file list into a tree structure.
|
|
58
|
+
*/
|
|
59
|
+
function treeify(docs) {
|
|
60
|
+
// Get the category breadcrumb of a doc (relative to the dir of the
|
|
61
|
+
// autogenerated sidebar item)
|
|
62
|
+
// autogenDir=a/b and docDir=a/b/c/d => returns [c, d]
|
|
63
|
+
// autogenDir=a/b and docDir=a/b => returns []
|
|
64
|
+
// TODO: try to use path.relative()
|
|
65
|
+
function getRelativeBreadcrumb(doc) {
|
|
66
|
+
return autogenDir === doc.sourceDirName
|
|
67
|
+
? []
|
|
68
|
+
: doc.sourceDirName
|
|
69
|
+
.replace((0, utils_common_1.addTrailingSlash)(autogenDir), '')
|
|
70
|
+
.split(BreadcrumbSeparator);
|
|
71
|
+
}
|
|
72
|
+
const treeRoot = {};
|
|
73
|
+
docs.forEach((doc) => {
|
|
74
|
+
const breadcrumb = getRelativeBreadcrumb(doc);
|
|
75
|
+
// We walk down the file's path to generate the fs structure
|
|
76
|
+
let currentDir = treeRoot;
|
|
77
|
+
breadcrumb.forEach((dir) => {
|
|
78
|
+
if (typeof currentDir[dir] === 'undefined') {
|
|
79
|
+
currentDir[dir] = {}; // Create new folder.
|
|
80
|
+
}
|
|
81
|
+
currentDir = currentDir[dir]; // Go into the subdirectory.
|
|
82
|
+
});
|
|
83
|
+
// We've walked through the path. Register the file in this directory.
|
|
84
|
+
currentDir[node_path_1.default.basename(doc.source)] = doc.id;
|
|
85
|
+
});
|
|
86
|
+
return treeRoot;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Step 3. Recursively transform the tree-like structure to sidebar items.
|
|
90
|
+
* (From a record to an array of items, akin to normalizing shorthand)
|
|
91
|
+
*/
|
|
92
|
+
function generateSidebar(fsModel) {
|
|
93
|
+
function createDocItem(id, fullPath, fileName) {
|
|
94
|
+
const { sidebarPosition: position, frontMatter: { sidebar_key: key, sidebar_label: label, sidebar_class_name: className, sidebar_custom_props: customProps, }, } = getDoc(id);
|
|
95
|
+
return {
|
|
96
|
+
type: 'doc',
|
|
97
|
+
id,
|
|
98
|
+
position,
|
|
99
|
+
source: fileName,
|
|
100
|
+
// We don't want these fields to magically appear in the generated
|
|
101
|
+
// sidebar
|
|
102
|
+
...(key !== undefined && { key }),
|
|
103
|
+
...(label !== undefined && { label }),
|
|
104
|
+
...(className !== undefined && { className }),
|
|
105
|
+
...(customProps !== undefined && { customProps }),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function createCategoryItem(dir, fullPath, folderName) {
|
|
109
|
+
const categoryMetadata = categoriesMetadata[node_path_1.default.posix.join(autogenDir, fullPath)];
|
|
110
|
+
const allItems = Object.entries(dir).map(([key, content]) => dirToItem(content, key, `${fullPath}/${key}`));
|
|
111
|
+
// Try to match a doc inside the category folder,
|
|
112
|
+
// using the "local id" (myDoc) or "qualified id" (dirName/myDoc)
|
|
113
|
+
function findDocByLocalId(localId) {
|
|
114
|
+
return allItems.find((item) => item.type === 'doc' && getLocalDocId(item.id) === localId);
|
|
115
|
+
}
|
|
116
|
+
function findConventionalCategoryDocLink() {
|
|
117
|
+
return allItems.find((item) => {
|
|
118
|
+
if (item.type !== 'doc') {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
const doc = getDoc(item.id);
|
|
122
|
+
return isCategoryIndex((0, docs_1.toCategoryIndexMatcherParam)(doc));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// In addition to the ID, this function also retrieves metadata of the
|
|
126
|
+
// linked doc that could be used as fallback values for category metadata
|
|
127
|
+
function getCategoryLinkedDocMetadata() {
|
|
128
|
+
const link = categoryMetadata?.link;
|
|
129
|
+
if (link !== undefined && link?.type !== 'doc') {
|
|
130
|
+
// If a link is explicitly specified, we won't apply conventions
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
const id = link
|
|
134
|
+
? (findDocByLocalId(link.id)?.id ?? getDoc(link.id).id)
|
|
135
|
+
: findConventionalCategoryDocLink()?.id;
|
|
136
|
+
if (!id) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
const doc = getDoc(id);
|
|
140
|
+
return {
|
|
141
|
+
id,
|
|
142
|
+
position: doc.sidebarPosition,
|
|
143
|
+
key: doc.frontMatter.sidebar_key,
|
|
144
|
+
label: doc.frontMatter.sidebar_label ?? doc.title,
|
|
145
|
+
customProps: doc.frontMatter.sidebar_custom_props,
|
|
146
|
+
className: doc.frontMatter.sidebar_class_name,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const categoryLinkedDoc = getCategoryLinkedDocMetadata();
|
|
150
|
+
const link = categoryLinkedDoc
|
|
151
|
+
? {
|
|
152
|
+
type: 'doc',
|
|
153
|
+
id: categoryLinkedDoc.id, // We "remap" a potentially "local id" to a "qualified id"
|
|
154
|
+
}
|
|
155
|
+
: categoryMetadata?.link;
|
|
156
|
+
// If a doc is linked, remove it from the category subItems
|
|
157
|
+
const items = allItems.filter((item) => !(item.type === 'doc' && item.id === categoryLinkedDoc?.id));
|
|
158
|
+
const className = categoryMetadata?.className ?? categoryLinkedDoc?.className;
|
|
159
|
+
const customProps = categoryMetadata?.customProps ?? categoryLinkedDoc?.customProps;
|
|
160
|
+
const { filename, numberPrefix } = numberPrefixParser(folderName);
|
|
161
|
+
const key = categoryMetadata?.key ?? categoryLinkedDoc?.key;
|
|
162
|
+
return {
|
|
163
|
+
type: 'category',
|
|
164
|
+
label: categoryMetadata?.label ?? categoryLinkedDoc?.label ?? filename,
|
|
165
|
+
collapsible: categoryMetadata?.collapsible,
|
|
166
|
+
collapsed: categoryMetadata?.collapsed,
|
|
167
|
+
position: categoryMetadata?.position ??
|
|
168
|
+
categoryLinkedDoc?.position ??
|
|
169
|
+
numberPrefix,
|
|
170
|
+
source: folderName,
|
|
171
|
+
...(customProps !== undefined && { customProps }),
|
|
172
|
+
...(className !== undefined && { className }),
|
|
173
|
+
items,
|
|
174
|
+
...(categoryMetadata?.description && {
|
|
175
|
+
description: categoryMetadata?.description,
|
|
176
|
+
}),
|
|
177
|
+
...(key && { key }),
|
|
178
|
+
...(link && { link }),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function dirToItem(dir, // The directory item to be transformed.
|
|
182
|
+
itemKey, // File/folder name; for categories, it's used to generate the next `relativePath`.
|
|
183
|
+
fullPath) {
|
|
184
|
+
return typeof dir === 'object'
|
|
185
|
+
? createCategoryItem(dir, fullPath, itemKey)
|
|
186
|
+
: createDocItem(dir, fullPath, itemKey);
|
|
187
|
+
}
|
|
188
|
+
return Object.entries(fsModel).map(([key, content]) => dirToItem(content, key, key));
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Step 4. Recursively sort the categories/docs + remove the "position"
|
|
192
|
+
* attribute from final output. Note: the "position" is only used to sort
|
|
193
|
+
* "inside" a sidebar slice. It is not used to sort across multiple
|
|
194
|
+
* consecutive sidebar slices (i.e. a whole category composed of multiple
|
|
195
|
+
* autogenerated items)
|
|
196
|
+
*/
|
|
197
|
+
function sortItems(sidebarItems) {
|
|
198
|
+
const processedSidebarItems = sidebarItems.map((item) => {
|
|
199
|
+
if (item.type === 'category') {
|
|
200
|
+
return { ...item, items: sortItems(item.items) };
|
|
201
|
+
}
|
|
202
|
+
return item;
|
|
203
|
+
});
|
|
204
|
+
const sortedSidebarItems = lodash_1.default.sortBy(processedSidebarItems, [
|
|
205
|
+
'position',
|
|
206
|
+
'source',
|
|
207
|
+
]);
|
|
208
|
+
return sortedSidebarItems.map(({ position, source, ...item }) => item);
|
|
209
|
+
}
|
|
210
|
+
// TODO: the whole code is designed for pipeline operator
|
|
211
|
+
const docs = getAutogenDocs();
|
|
212
|
+
const fsModel = treeify(docs);
|
|
213
|
+
const sidebarWithPosition = generateSidebar(fsModel);
|
|
214
|
+
const sortedSidebar = sortItems(sidebarWithPosition);
|
|
215
|
+
return sortedSidebar;
|
|
216
|
+
};
|
|
217
|
+
exports.DefaultSidebarItemsGenerator = DefaultSidebarItemsGenerator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { SidebarsConfig, Sidebars, SidebarProcessorParams } from './types';
|
|
9
|
+
export declare const DefaultSidebars: SidebarsConfig;
|
|
10
|
+
export declare const DisabledSidebars: SidebarsConfig;
|
|
11
|
+
export declare function resolveSidebarPathOption(siteDir: string, sidebarPathOption: PluginOptions['sidebarPath']): PluginOptions['sidebarPath'];
|
|
12
|
+
export declare function loadSidebarsFile(sidebarFilePath: string | false | undefined): Promise<SidebarsConfig>;
|
|
13
|
+
export declare function loadSidebars(sidebarFilePath: string | false | undefined, options: SidebarProcessorParams): Promise<Sidebars>;
|
|
@@ -0,0 +1,99 @@
|
|
|
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.DisabledSidebars = exports.DefaultSidebars = void 0;
|
|
10
|
+
exports.resolveSidebarPathOption = resolveSidebarPathOption;
|
|
11
|
+
exports.loadSidebarsFile = loadSidebarsFile;
|
|
12
|
+
exports.loadSidebars = loadSidebars;
|
|
13
|
+
const tslib_1 = require("tslib");
|
|
14
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
15
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
16
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
17
|
+
const utils_1 = require("@docusaurus/utils");
|
|
18
|
+
const glob_1 = require("@docusaurus/glob");
|
|
19
|
+
const Yaml = tslib_1.__importStar(require("js-yaml"));
|
|
20
|
+
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
21
|
+
const fs_1 = require("@docusaurus/fs");
|
|
22
|
+
const validation_1 = require("./validation");
|
|
23
|
+
const normalization_1 = require("./normalization");
|
|
24
|
+
const processor_1 = require("./processor");
|
|
25
|
+
const postProcessor_1 = require("./postProcessor");
|
|
26
|
+
exports.DefaultSidebars = {
|
|
27
|
+
defaultSidebar: [
|
|
28
|
+
{
|
|
29
|
+
type: 'autogenerated',
|
|
30
|
+
dirName: '.',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
exports.DisabledSidebars = {};
|
|
35
|
+
// If a path is provided, make it absolute
|
|
36
|
+
function resolveSidebarPathOption(siteDir, sidebarPathOption) {
|
|
37
|
+
return sidebarPathOption
|
|
38
|
+
? node_path_1.default.resolve(siteDir, sidebarPathOption)
|
|
39
|
+
: sidebarPathOption;
|
|
40
|
+
}
|
|
41
|
+
async function readCategoriesMetadata(contentPath) {
|
|
42
|
+
const categoryFiles = await (0, glob_1.glob)('**/_category_.{json,yml,yaml}', {
|
|
43
|
+
cwd: contentPath,
|
|
44
|
+
});
|
|
45
|
+
const categoryToFile = lodash_1.default.groupBy(categoryFiles, node_path_1.default.dirname);
|
|
46
|
+
return (0, combine_promises_1.default)(lodash_1.default.mapValues(categoryToFile, async (files, folder) => {
|
|
47
|
+
const filePath = files[0];
|
|
48
|
+
if (files.length > 1) {
|
|
49
|
+
logger_1.default.warn `There are more than one category metadata files for path=${folder}: ${files.join(', ')}. The behavior is undetermined.`;
|
|
50
|
+
}
|
|
51
|
+
const content = await fs_1.fs.readFile(node_path_1.default.join(contentPath, filePath), 'utf-8');
|
|
52
|
+
try {
|
|
53
|
+
return (0, validation_1.validateCategoryMetadataFile)(Yaml.load(content));
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
logger_1.default.error `The docs sidebar category metadata file path=${filePath} looks invalid!`;
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
async function loadSidebarsFileUnsafe(sidebarFilePath) {
|
|
62
|
+
// false => no sidebars
|
|
63
|
+
if (sidebarFilePath === false) {
|
|
64
|
+
return exports.DisabledSidebars;
|
|
65
|
+
}
|
|
66
|
+
// undefined => defaults to autogenerated sidebars
|
|
67
|
+
if (typeof sidebarFilePath === 'undefined') {
|
|
68
|
+
return exports.DefaultSidebars;
|
|
69
|
+
}
|
|
70
|
+
// Non-existent sidebars file: no sidebars
|
|
71
|
+
// Note: this edge case can happen on versioned docs, not current version
|
|
72
|
+
// We avoid creating empty versioned sidebars file with the CLI
|
|
73
|
+
if (!(await (0, fs_1.pathExists)(sidebarFilePath))) {
|
|
74
|
+
return exports.DisabledSidebars;
|
|
75
|
+
}
|
|
76
|
+
// We don't want sidebars to be cached because of hot reloading.
|
|
77
|
+
const module = await (0, utils_1.loadFreshModule)(sidebarFilePath, { default: true });
|
|
78
|
+
// TODO unsafe, need to refactor and improve validation
|
|
79
|
+
return module;
|
|
80
|
+
}
|
|
81
|
+
async function loadSidebarsFile(sidebarFilePath) {
|
|
82
|
+
const sidebars = await loadSidebarsFileUnsafe(sidebarFilePath);
|
|
83
|
+
// TODO unsafe, need to refactor and improve validation
|
|
84
|
+
return sidebars;
|
|
85
|
+
}
|
|
86
|
+
async function loadSidebars(sidebarFilePath, options) {
|
|
87
|
+
try {
|
|
88
|
+
const sidebarsConfig = await loadSidebarsFileUnsafe(sidebarFilePath);
|
|
89
|
+
const normalizedSidebars = (0, normalization_1.normalizeSidebars)(sidebarsConfig);
|
|
90
|
+
(0, validation_1.validateSidebars)(normalizedSidebars);
|
|
91
|
+
const categoriesMetadata = await readCategoriesMetadata(options.version.contentPath);
|
|
92
|
+
const processedSidebars = await (0, processor_1.processSidebars)(normalizedSidebars, categoriesMetadata, options);
|
|
93
|
+
return (0, postProcessor_1.postProcessSidebars)(processedSidebars, options);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
logger_1.default.error `Sidebars file at path=${sidebarFilePath} failed to be loaded.`;
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { NormalizedSidebarItem, NormalizedSidebars, SidebarItemConfig, SidebarsConfig } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes recursively item and all its children. Ensures that at the end
|
|
10
|
+
* each item will be an object with the corresponding type.
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeItem(item: SidebarItemConfig): NormalizedSidebarItem[];
|
|
13
|
+
export declare function normalizeSidebars(sidebars: SidebarsConfig): NormalizedSidebars;
|
|
@@ -0,0 +1,58 @@
|
|
|
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.normalizeItem = normalizeItem;
|
|
10
|
+
exports.normalizeSidebars = normalizeSidebars;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
function normalizeCategoriesShorthand(sidebar) {
|
|
16
|
+
return Object.entries(sidebar).map(([label, items]) => ({
|
|
17
|
+
type: 'category',
|
|
18
|
+
label,
|
|
19
|
+
items,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes recursively item and all its children. Ensures that at the end
|
|
24
|
+
* each item will be an object with the corresponding type.
|
|
25
|
+
*/
|
|
26
|
+
function normalizeItem(item) {
|
|
27
|
+
if (typeof item === 'string') {
|
|
28
|
+
return [{ type: 'doc', id: item }];
|
|
29
|
+
}
|
|
30
|
+
if ((0, utils_1.isCategoriesShorthand)(item)) {
|
|
31
|
+
// This will never throw anyways
|
|
32
|
+
return normalizeSidebar(item, 'sidebar items slice');
|
|
33
|
+
}
|
|
34
|
+
if ((item.type === 'doc' || item.type === 'ref') &&
|
|
35
|
+
typeof item.label === 'string') {
|
|
36
|
+
return [{ ...item, translatable: true }];
|
|
37
|
+
}
|
|
38
|
+
if (item.type === 'category') {
|
|
39
|
+
const normalizedCategory = {
|
|
40
|
+
...item,
|
|
41
|
+
items: normalizeSidebar(item.items, logger_1.default.interpolate `code=${'items'} of the category name=${item.label}`),
|
|
42
|
+
};
|
|
43
|
+
return [normalizedCategory];
|
|
44
|
+
}
|
|
45
|
+
return [item];
|
|
46
|
+
}
|
|
47
|
+
function normalizeSidebar(sidebar, place) {
|
|
48
|
+
if (!Array.isArray(sidebar) && !(0, utils_1.isCategoriesShorthand)(sidebar)) {
|
|
49
|
+
throw new Error(logger_1.default.interpolate `Invalid sidebar items collection code=${JSON.stringify(sidebar)} in ${place}: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a code=${'type'} property). See url=${'https://docusaurus.io/docs/sidebar/items'} for all valid syntaxes.`);
|
|
50
|
+
}
|
|
51
|
+
const normalizedSidebar = Array.isArray(sidebar)
|
|
52
|
+
? sidebar
|
|
53
|
+
: normalizeCategoriesShorthand(sidebar);
|
|
54
|
+
return normalizedSidebar.flatMap((subItem) => normalizeItem(subItem));
|
|
55
|
+
}
|
|
56
|
+
function normalizeSidebars(sidebars) {
|
|
57
|
+
return lodash_1.default.mapValues(sidebars, (sidebar, id) => normalizeSidebar(sidebar, logger_1.default.interpolate `sidebar name=${id}`));
|
|
58
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Sidebars, SidebarProcessorParams, ProcessedSidebars } from './types';
|
|
8
|
+
export type SidebarPostProcessorParams = SidebarProcessorParams & {
|
|
9
|
+
draftIds: Set<string>;
|
|
10
|
+
};
|
|
11
|
+
export declare function postProcessSidebars(sidebars: ProcessedSidebars, params: SidebarProcessorParams): Sidebars;
|