@docusaurus/plugin-content-docs 2.0.0-beta.2 → 2.0.0-beta.20
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 +12 -0
- package/lib/categoryGeneratedIndex.js +37 -0
- package/lib/cli.d.ts +3 -2
- package/lib/cli.js +60 -69
- package/lib/client/docsClientUtils.d.ts +9 -28
- package/lib/client/docsClientUtils.js +33 -34
- package/lib/client/index.d.ts +22 -0
- package/lib/client/index.js +72 -0
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +32 -3
- package/lib/docs.js +164 -63
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js → lib/frontMatter.d.ts} +4 -8
- package/lib/{docFrontMatter.js → frontMatter.js} +13 -4
- package/lib/globalData.d.ts +3 -3
- package/lib/globalData.js +35 -6
- package/lib/index.d.ts +3 -3
- package/lib/index.js +122 -148
- package/lib/lastUpdate.d.ts +4 -6
- package/lib/lastUpdate.js +22 -26
- package/lib/markdown/index.d.ts +3 -6
- package/lib/markdown/index.js +3 -3
- package/lib/markdown/linkify.d.ts +1 -1
- package/lib/markdown/linkify.js +6 -3
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/numberPrefix.js +16 -21
- package/lib/options.d.ts +3 -5
- package/lib/options.js +54 -13
- package/lib/props.d.ts +7 -2
- package/lib/props.js +69 -13
- package/lib/routes.d.ts +29 -0
- package/lib/routes.js +96 -0
- package/lib/server-export.d.ts +9 -0
- package/lib/server-export.js +22 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -6
- package/lib/sidebars/generator.js +209 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +92 -0
- package/lib/sidebars/normalization.d.ts +13 -0
- package/lib/sidebars/normalization.js +55 -0
- package/lib/sidebars/postProcessor.d.ts +8 -0
- package/lib/sidebars/postProcessor.js +65 -0
- package/lib/sidebars/processor.d.ts +10 -0
- package/lib/sidebars/processor.js +90 -0
- package/lib/sidebars/types.d.ts +178 -0
- package/lib/{docFrontMatter.d.ts → sidebars/types.js} +2 -2
- package/lib/sidebars/utils.d.ts +54 -0
- package/lib/sidebars/utils.js +255 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +138 -0
- package/lib/slug.d.ts +5 -4
- package/lib/slug.js +28 -18
- package/{src/__tests__/__fixtures__/sidebars/sidebars-first-level-not-category.js → lib/tags.d.ts} +3 -14
- package/lib/tags.js +21 -0
- package/lib/translations.d.ts +3 -3
- package/lib/translations.js +84 -94
- package/lib/types.d.ts +13 -184
- 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 +32 -27
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +84 -109
- package/src/client/docsClientUtils.ts +43 -70
- package/src/client/index.ts +103 -0
- package/src/constants.ts +4 -2
- package/{types.d.ts → src/deps.d.ts} +1 -1
- package/src/docs.ts +228 -65
- package/src/{docFrontMatter.ts → frontMatter.ts} +21 -11
- package/src/globalData.ts +57 -7
- package/src/index.ts +169 -210
- package/src/lastUpdate.ts +26 -37
- package/src/markdown/index.ts +10 -16
- package/src/markdown/linkify.ts +7 -4
- package/src/numberPrefix.ts +19 -26
- package/src/options.ts +60 -18
- package/src/plugin-content-docs.d.ts +625 -89
- package/src/props.ts +102 -20
- package/src/routes.ts +159 -0
- package/src/server-export.ts +22 -0
- package/src/sidebars/README.md +9 -0
- package/src/sidebars/generator.ts +292 -0
- package/src/sidebars/index.ts +118 -0
- package/src/sidebars/normalization.ts +85 -0
- package/src/sidebars/postProcessor.ts +89 -0
- package/src/sidebars/processor.ts +139 -0
- package/src/sidebars/types.ts +275 -0
- package/src/sidebars/utils.ts +391 -0
- package/src/sidebars/validation.ts +174 -0
- package/src/slug.ts +41 -22
- package/src/tags.ts +20 -0
- package/src/translations.ts +124 -117
- package/src/types.ts +18 -247
- package/src/versions/files.ts +220 -0
- package/src/versions/index.ts +247 -0
- package/src/versions/validation.ts +113 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -43
- package/lib/sidebars.js +0 -320
- package/lib/theme/hooks/useDocs.d.ts +0 -20
- package/lib/theme/hooks/useDocs.js +0 -72
- package/lib/versions.d.ts +0 -16
- package/lib/versions.js +0 -319
- package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
- package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
- package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
- package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
- package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
- package/src/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
- package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
- package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -70
- package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -53
- package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
- package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
- package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js +0 -16
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -7
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
- package/src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
- package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
- package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -90
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1916
- package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -218
- package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -487
- package/src/__tests__/cli.test.ts +0 -333
- package/src/__tests__/docFrontMatter.test.ts +0 -244
- package/src/__tests__/docs.test.ts +0 -878
- package/src/__tests__/index.test.ts +0 -1871
- package/src/__tests__/lastUpdate.test.ts +0 -69
- package/src/__tests__/numberPrefix.test.ts +0 -199
- package/src/__tests__/options.test.ts +0 -231
- package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
- package/src/__tests__/sidebars.test.ts +0 -639
- package/src/__tests__/slug.test.ts +0 -109
- package/src/__tests__/translations.test.ts +0 -159
- package/src/__tests__/versions.test.ts +0 -741
- package/src/client/__tests__/docsClientUtils.test.ts +0 -371
- package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
- package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
- package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
- package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
- package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
- package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
- package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
- package/src/markdown/__tests__/linkify.test.ts +0 -190
- package/src/sidebarItemsGenerator.ts +0 -307
- package/src/sidebars.ts +0 -522
- package/src/theme/hooks/useDocs.ts +0 -99
- package/src/versions.ts +0 -572
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,92 @@
|
|
|
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.loadSidebars = exports.loadSidebarsFileUnsafe = exports.resolveSidebarPathOption = exports.DisabledSidebars = exports.DefaultSidebars = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
13
|
+
const validation_1 = require("./validation");
|
|
14
|
+
const normalization_1 = require("./normalization");
|
|
15
|
+
const processor_1 = require("./processor");
|
|
16
|
+
const postProcessor_1 = require("./postProcessor");
|
|
17
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
18
|
+
const utils_1 = require("@docusaurus/utils");
|
|
19
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
20
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
21
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
22
|
+
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
23
|
+
exports.DefaultSidebars = {
|
|
24
|
+
defaultSidebar: [
|
|
25
|
+
{
|
|
26
|
+
type: 'autogenerated',
|
|
27
|
+
dirName: '.',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
exports.DisabledSidebars = {};
|
|
32
|
+
// If a path is provided, make it absolute
|
|
33
|
+
function resolveSidebarPathOption(siteDir, sidebarPathOption) {
|
|
34
|
+
return sidebarPathOption
|
|
35
|
+
? path_1.default.resolve(siteDir, sidebarPathOption)
|
|
36
|
+
: sidebarPathOption;
|
|
37
|
+
}
|
|
38
|
+
exports.resolveSidebarPathOption = resolveSidebarPathOption;
|
|
39
|
+
async function readCategoriesMetadata(contentPath) {
|
|
40
|
+
const categoryFiles = await (0, utils_1.Globby)('**/_category_.{json,yml,yaml}', {
|
|
41
|
+
cwd: contentPath,
|
|
42
|
+
});
|
|
43
|
+
const categoryToFile = lodash_1.default.groupBy(categoryFiles, path_1.default.dirname);
|
|
44
|
+
return (0, combine_promises_1.default)(lodash_1.default.mapValues(categoryToFile, async (files, folder) => {
|
|
45
|
+
const filePath = files[0];
|
|
46
|
+
if (files.length > 1) {
|
|
47
|
+
logger_1.default.warn `There are more than one category metadata files for path=${folder}: ${files.join(', ')}. The behavior is undetermined.`;
|
|
48
|
+
}
|
|
49
|
+
const content = await fs_extra_1.default.readFile(path_1.default.join(contentPath, filePath), 'utf-8');
|
|
50
|
+
try {
|
|
51
|
+
return (0, validation_1.validateCategoryMetadataFile)(js_yaml_1.default.load(content));
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
logger_1.default.error `The docs sidebar category metadata file path=${filePath} looks invalid!`;
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
async function loadSidebarsFileUnsafe(sidebarFilePath) {
|
|
60
|
+
// false => no sidebars
|
|
61
|
+
if (sidebarFilePath === false) {
|
|
62
|
+
return exports.DisabledSidebars;
|
|
63
|
+
}
|
|
64
|
+
// undefined => defaults to autogenerated sidebars
|
|
65
|
+
if (typeof sidebarFilePath === 'undefined') {
|
|
66
|
+
return exports.DefaultSidebars;
|
|
67
|
+
}
|
|
68
|
+
// Non-existent sidebars file: no sidebars
|
|
69
|
+
// Note: this edge case can happen on versioned docs, not current version
|
|
70
|
+
// We avoid creating empty versioned sidebars file with the CLI
|
|
71
|
+
if (!(await fs_extra_1.default.pathExists(sidebarFilePath))) {
|
|
72
|
+
return exports.DisabledSidebars;
|
|
73
|
+
}
|
|
74
|
+
// We don't want sidebars to be cached because of hot reloading.
|
|
75
|
+
return (0, import_fresh_1.default)(sidebarFilePath);
|
|
76
|
+
}
|
|
77
|
+
exports.loadSidebarsFileUnsafe = loadSidebarsFileUnsafe;
|
|
78
|
+
async function loadSidebars(sidebarFilePath, options) {
|
|
79
|
+
try {
|
|
80
|
+
const sidebarsConfig = await loadSidebarsFileUnsafe(sidebarFilePath);
|
|
81
|
+
const normalizedSidebars = (0, normalization_1.normalizeSidebars)(sidebarsConfig);
|
|
82
|
+
(0, validation_1.validateSidebars)(normalizedSidebars);
|
|
83
|
+
const categoriesMetadata = await readCategoriesMetadata(options.version.contentPath);
|
|
84
|
+
const processedSidebars = await (0, processor_1.processSidebars)(normalizedSidebars, categoriesMetadata, options);
|
|
85
|
+
return (0, postProcessor_1.postProcessSidebars)(processedSidebars, options);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
logger_1.default.error `Sidebars file at path=${sidebarFilePath} failed to be loaded.`;
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.loadSidebars = loadSidebars;
|
|
@@ -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,55 @@
|
|
|
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.normalizeSidebars = exports.normalizeItem = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
function normalizeCategoriesShorthand(sidebar) {
|
|
15
|
+
return Object.entries(sidebar).map(([label, items]) => ({
|
|
16
|
+
type: 'category',
|
|
17
|
+
label,
|
|
18
|
+
items,
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Normalizes recursively item and all its children. Ensures that at the end
|
|
23
|
+
* each item will be an object with the corresponding type.
|
|
24
|
+
*/
|
|
25
|
+
function normalizeItem(item) {
|
|
26
|
+
if (typeof item === 'string') {
|
|
27
|
+
return [{ type: 'doc', id: item }];
|
|
28
|
+
}
|
|
29
|
+
if ((0, utils_1.isCategoriesShorthand)(item)) {
|
|
30
|
+
// This will never throw anyways
|
|
31
|
+
return normalizeSidebar(item, 'sidebar items slice');
|
|
32
|
+
}
|
|
33
|
+
if (item.type === 'category') {
|
|
34
|
+
const normalizedCategory = {
|
|
35
|
+
...item,
|
|
36
|
+
items: normalizeSidebar(item.items, logger_1.default.interpolate `code=${'items'} of the category name=${item.label}`),
|
|
37
|
+
};
|
|
38
|
+
return [normalizedCategory];
|
|
39
|
+
}
|
|
40
|
+
return [item];
|
|
41
|
+
}
|
|
42
|
+
exports.normalizeItem = normalizeItem;
|
|
43
|
+
function normalizeSidebar(sidebar, place) {
|
|
44
|
+
if (!Array.isArray(sidebar) && !(0, utils_1.isCategoriesShorthand)(sidebar)) {
|
|
45
|
+
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.`);
|
|
46
|
+
}
|
|
47
|
+
const normalizedSidebar = Array.isArray(sidebar)
|
|
48
|
+
? sidebar
|
|
49
|
+
: normalizeCategoriesShorthand(sidebar);
|
|
50
|
+
return normalizedSidebar.flatMap((subItem) => normalizeItem(subItem));
|
|
51
|
+
}
|
|
52
|
+
function normalizeSidebars(sidebars) {
|
|
53
|
+
return lodash_1.default.mapValues(sidebars, (sidebar, id) => normalizeSidebar(sidebar, logger_1.default.interpolate `sidebar name=${id}`));
|
|
54
|
+
}
|
|
55
|
+
exports.normalizeSidebars = normalizeSidebars;
|
|
@@ -0,0 +1,8 @@
|
|
|
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 declare function postProcessSidebars(sidebars: ProcessedSidebars, params: SidebarProcessorParams): Sidebars;
|
|
@@ -0,0 +1,65 @@
|
|
|
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.postProcessSidebars = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
function normalizeCategoryLink(category, params) {
|
|
14
|
+
if (category.link?.type === 'generated-index') {
|
|
15
|
+
// Default slug logic can be improved
|
|
16
|
+
const getDefaultSlug = () => `/category/${params.categoryLabelSlugger.slug(category.label)}`;
|
|
17
|
+
const slug = category.link.slug ?? getDefaultSlug();
|
|
18
|
+
const permalink = (0, utils_1.normalizeUrl)([params.version.path, slug]);
|
|
19
|
+
return {
|
|
20
|
+
...category.link,
|
|
21
|
+
slug,
|
|
22
|
+
permalink,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return category.link;
|
|
26
|
+
}
|
|
27
|
+
function postProcessSidebarItem(item, params) {
|
|
28
|
+
if (item.type === 'category') {
|
|
29
|
+
const category = {
|
|
30
|
+
...item,
|
|
31
|
+
collapsed: item.collapsed ?? params.sidebarOptions.sidebarCollapsed,
|
|
32
|
+
collapsible: item.collapsible ?? params.sidebarOptions.sidebarCollapsible,
|
|
33
|
+
link: normalizeCategoryLink(item, params),
|
|
34
|
+
items: item.items.map((subItem) => postProcessSidebarItem(subItem, params)),
|
|
35
|
+
};
|
|
36
|
+
// If the current category doesn't have subitems, we render a normal link
|
|
37
|
+
// instead.
|
|
38
|
+
if (category.items.length === 0) {
|
|
39
|
+
if (!category.link) {
|
|
40
|
+
throw new Error(`Sidebar category ${item.label} has neither any subitem nor a link. This makes this item not able to link to anything.`);
|
|
41
|
+
}
|
|
42
|
+
return category.link.type === 'doc'
|
|
43
|
+
? {
|
|
44
|
+
type: 'doc',
|
|
45
|
+
label: category.label,
|
|
46
|
+
id: category.link.id,
|
|
47
|
+
}
|
|
48
|
+
: {
|
|
49
|
+
type: 'link',
|
|
50
|
+
label: category.label,
|
|
51
|
+
href: category.link.permalink,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// A non-collapsible category can't be collapsed!
|
|
55
|
+
if (category.collapsible === false) {
|
|
56
|
+
category.collapsed = false;
|
|
57
|
+
}
|
|
58
|
+
return category;
|
|
59
|
+
}
|
|
60
|
+
return item;
|
|
61
|
+
}
|
|
62
|
+
function postProcessSidebars(sidebars, params) {
|
|
63
|
+
return lodash_1.default.mapValues(sidebars, (sidebar) => sidebar.map((item) => postProcessSidebarItem(item, params)));
|
|
64
|
+
}
|
|
65
|
+
exports.postProcessSidebars = postProcessSidebars;
|
|
@@ -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 { NormalizedSidebars, ProcessedSidebars, SidebarProcessorParams, CategoryMetadataFile } from './types';
|
|
8
|
+
export declare function processSidebars(unprocessedSidebars: NormalizedSidebars, categoriesMetadata: {
|
|
9
|
+
[filePath: string]: CategoryMetadataFile;
|
|
10
|
+
}, params: SidebarProcessorParams): Promise<ProcessedSidebars>;
|
|
@@ -0,0 +1,90 @@
|
|
|
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.processSidebars = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const generator_1 = require("./generator");
|
|
12
|
+
const validation_1 = require("./validation");
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
+
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
15
|
+
const docs_1 = require("../docs");
|
|
16
|
+
function toSidebarItemsGeneratorDoc(doc) {
|
|
17
|
+
return lodash_1.default.pick(doc, [
|
|
18
|
+
'id',
|
|
19
|
+
'unversionedId',
|
|
20
|
+
'title',
|
|
21
|
+
'frontMatter',
|
|
22
|
+
'source',
|
|
23
|
+
'sourceDirName',
|
|
24
|
+
'sidebarPosition',
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
function toSidebarItemsGeneratorVersion(version) {
|
|
28
|
+
return lodash_1.default.pick(version, ['versionName', 'contentPath']);
|
|
29
|
+
}
|
|
30
|
+
// Handle the generation of autogenerated sidebar items and other
|
|
31
|
+
// post-processing checks
|
|
32
|
+
async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
33
|
+
const { sidebarItemsGenerator, numberPrefixParser, docs, drafts, version } = params;
|
|
34
|
+
// Just a minor lazy transformation optimization
|
|
35
|
+
const getSidebarItemsGeneratorDocsAndVersion = lodash_1.default.memoize(() => ({
|
|
36
|
+
docs: docs.map(toSidebarItemsGeneratorDoc),
|
|
37
|
+
version: toSidebarItemsGeneratorVersion(version),
|
|
38
|
+
}));
|
|
39
|
+
async function processAutoGeneratedItem(item) {
|
|
40
|
+
const generatedItems = await sidebarItemsGenerator({
|
|
41
|
+
item,
|
|
42
|
+
numberPrefixParser,
|
|
43
|
+
defaultSidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
|
|
44
|
+
isCategoryIndex: docs_1.isCategoryIndex,
|
|
45
|
+
...getSidebarItemsGeneratorDocsAndVersion(),
|
|
46
|
+
categoriesMetadata,
|
|
47
|
+
});
|
|
48
|
+
// Process again... weird but sidebar item generated might generate some
|
|
49
|
+
// auto-generated items?
|
|
50
|
+
// TODO repeatedly process & unwrap autogenerated items until there are no
|
|
51
|
+
// more autogenerated items, or when loop count (e.g. 10) is reached
|
|
52
|
+
return processItems(generatedItems);
|
|
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
|
+
};
|
|
65
|
+
async function processItem(item) {
|
|
66
|
+
if (item.type === 'category') {
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
...item,
|
|
70
|
+
items: await processItems(item.items),
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
if (item.type === 'autogenerated') {
|
|
75
|
+
return processAutoGeneratedItem(item);
|
|
76
|
+
}
|
|
77
|
+
return [item];
|
|
78
|
+
}
|
|
79
|
+
async function processItems(items) {
|
|
80
|
+
return (await Promise.all(items.filter((i) => !isDraftItem(i)).map(processItem))).flat();
|
|
81
|
+
}
|
|
82
|
+
const processedSidebar = await processItems(unprocessedSidebar);
|
|
83
|
+
return processedSidebar;
|
|
84
|
+
}
|
|
85
|
+
async function processSidebars(unprocessedSidebars, categoriesMetadata, params) {
|
|
86
|
+
const processedSidebars = await (0, combine_promises_1.default)(lodash_1.default.mapValues(unprocessedSidebars, (unprocessedSidebar) => processSidebar(unprocessedSidebar, categoriesMetadata, params)));
|
|
87
|
+
(0, validation_1.validateSidebars)(processedSidebars);
|
|
88
|
+
return processedSidebars;
|
|
89
|
+
}
|
|
90
|
+
exports.processSidebars = processSidebars;
|
|
@@ -0,0 +1,178 @@
|
|
|
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 { Optional, Required } from 'utility-types';
|
|
8
|
+
import type { NumberPrefixParser, SidebarOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
import type { Slugger } from '@docusaurus/utils';
|
|
10
|
+
declare type Expand<T extends {
|
|
11
|
+
[x: string]: unknown;
|
|
12
|
+
}> = {
|
|
13
|
+
[P in keyof T]: T[P];
|
|
14
|
+
};
|
|
15
|
+
export declare type SidebarItemBase = {
|
|
16
|
+
className?: string;
|
|
17
|
+
customProps?: {
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
22
|
+
type: 'doc' | 'ref';
|
|
23
|
+
label?: string;
|
|
24
|
+
id: string;
|
|
25
|
+
};
|
|
26
|
+
export declare type SidebarItemHtml = SidebarItemBase & {
|
|
27
|
+
type: 'html';
|
|
28
|
+
value: string;
|
|
29
|
+
defaultStyle?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare type SidebarItemLink = SidebarItemBase & {
|
|
32
|
+
type: 'link';
|
|
33
|
+
href: string;
|
|
34
|
+
label: string;
|
|
35
|
+
};
|
|
36
|
+
export declare type SidebarItemAutogenerated = SidebarItemBase & {
|
|
37
|
+
type: 'autogenerated';
|
|
38
|
+
dirName: string;
|
|
39
|
+
};
|
|
40
|
+
declare type SidebarItemCategoryBase = SidebarItemBase & {
|
|
41
|
+
type: 'category';
|
|
42
|
+
label: string;
|
|
43
|
+
collapsed: boolean;
|
|
44
|
+
collapsible: boolean;
|
|
45
|
+
};
|
|
46
|
+
export declare type SidebarItemCategoryLinkDoc = {
|
|
47
|
+
type: 'doc';
|
|
48
|
+
id: string;
|
|
49
|
+
};
|
|
50
|
+
export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
|
|
51
|
+
type: 'generated-index';
|
|
52
|
+
slug?: string;
|
|
53
|
+
title?: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
image?: string;
|
|
56
|
+
keywords?: string | readonly string[];
|
|
57
|
+
};
|
|
58
|
+
export declare type SidebarItemCategoryLinkGeneratedIndex = {
|
|
59
|
+
type: 'generated-index';
|
|
60
|
+
slug: string;
|
|
61
|
+
permalink: string;
|
|
62
|
+
title?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
image?: string;
|
|
65
|
+
keywords?: string | readonly string[];
|
|
66
|
+
};
|
|
67
|
+
export declare type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
|
|
68
|
+
export declare type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
|
|
69
|
+
export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
70
|
+
items: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
71
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
72
|
+
}>;
|
|
73
|
+
export declare type SidebarCategoriesShorthand = {
|
|
74
|
+
[sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
75
|
+
};
|
|
76
|
+
export declare type SidebarItemConfig = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
|
|
77
|
+
export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
78
|
+
export declare type SidebarsConfig = {
|
|
79
|
+
[sidebarId: string]: SidebarConfig;
|
|
80
|
+
};
|
|
81
|
+
export declare type NormalizedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
82
|
+
items: NormalizedSidebarItem[];
|
|
83
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
84
|
+
}>;
|
|
85
|
+
export declare type NormalizedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
|
|
86
|
+
export declare type NormalizedSidebar = NormalizedSidebarItem[];
|
|
87
|
+
export declare type NormalizedSidebars = {
|
|
88
|
+
[sidebarId: string]: NormalizedSidebar;
|
|
89
|
+
};
|
|
90
|
+
export declare type ProcessedSidebarItemCategory = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
91
|
+
items: ProcessedSidebarItem[];
|
|
92
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
93
|
+
}>;
|
|
94
|
+
export declare type ProcessedSidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | ProcessedSidebarItemCategory;
|
|
95
|
+
export declare type ProcessedSidebar = ProcessedSidebarItem[];
|
|
96
|
+
export declare type ProcessedSidebars = {
|
|
97
|
+
[sidebarId: string]: ProcessedSidebar;
|
|
98
|
+
};
|
|
99
|
+
export declare type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
100
|
+
items: SidebarItem[];
|
|
101
|
+
link?: SidebarItemCategoryLink;
|
|
102
|
+
}>;
|
|
103
|
+
export declare type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
|
|
104
|
+
export declare type SidebarItemCategoryWithGeneratedIndex = SidebarItemCategoryWithLink & {
|
|
105
|
+
link: SidebarItemCategoryLinkGeneratedIndex;
|
|
106
|
+
};
|
|
107
|
+
export declare type SidebarItem = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemCategory;
|
|
108
|
+
export declare type SidebarNavigationItem = SidebarItemDoc | SidebarItemCategoryWithLink;
|
|
109
|
+
export declare type Sidebar = SidebarItem[];
|
|
110
|
+
export declare type SidebarItemType = SidebarItem['type'];
|
|
111
|
+
export declare type Sidebars = {
|
|
112
|
+
[sidebarId: string]: Sidebar;
|
|
113
|
+
};
|
|
114
|
+
export declare type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
115
|
+
items: PropSidebarItem[];
|
|
116
|
+
href?: string;
|
|
117
|
+
}>;
|
|
118
|
+
export declare type PropSidebarItemLink = SidebarItemLink & {
|
|
119
|
+
docId?: string;
|
|
120
|
+
};
|
|
121
|
+
export declare type PropSidebarItemHtml = SidebarItemHtml;
|
|
122
|
+
export declare type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory | PropSidebarItemHtml;
|
|
123
|
+
export declare type PropSidebar = PropSidebarItem[];
|
|
124
|
+
export declare type PropSidebars = {
|
|
125
|
+
[sidebarId: string]: PropSidebar;
|
|
126
|
+
};
|
|
127
|
+
export declare type PropSidebarBreadcrumbsItem = PropSidebarItemLink | PropSidebarItemCategory;
|
|
128
|
+
export declare type CategoryMetadataFile = {
|
|
129
|
+
label?: string;
|
|
130
|
+
position?: number;
|
|
131
|
+
collapsed?: boolean;
|
|
132
|
+
collapsible?: boolean;
|
|
133
|
+
className?: string;
|
|
134
|
+
link?: SidebarItemCategoryLinkConfig | null;
|
|
135
|
+
customProps?: {
|
|
136
|
+
[key: string]: unknown;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'title' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
140
|
+
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
141
|
+
export declare type SidebarItemsGeneratorArgs = {
|
|
142
|
+
/** The sidebar item with type "autogenerated" to be transformed. */
|
|
143
|
+
item: SidebarItemAutogenerated;
|
|
144
|
+
/** Useful metadata for the version this sidebar belongs to. */
|
|
145
|
+
version: SidebarItemsGeneratorVersion;
|
|
146
|
+
/** All the docs of that version (unfiltered). */
|
|
147
|
+
docs: SidebarItemsGeneratorDoc[];
|
|
148
|
+
/** Number prefix parser configured for this plugin. */
|
|
149
|
+
numberPrefixParser: NumberPrefixParser;
|
|
150
|
+
/** The default category index matcher which you can override. */
|
|
151
|
+
isCategoryIndex: CategoryIndexMatcher;
|
|
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
|
+
};
|
|
159
|
+
};
|
|
160
|
+
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
|
|
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
|
+
*/
|
|
167
|
+
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
168
|
+
} & SidebarItemsGeneratorArgs) => Promise<NormalizedSidebarItem[]>;
|
|
169
|
+
export declare type SidebarProcessorParams = {
|
|
170
|
+
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
171
|
+
numberPrefixParser: NumberPrefixParser;
|
|
172
|
+
docs: DocMetadataBase[];
|
|
173
|
+
drafts: DocMetadataBase[];
|
|
174
|
+
version: VersionMetadata;
|
|
175
|
+
categoryLabelSlugger: Slugger;
|
|
176
|
+
sidebarOptions: SidebarOptions;
|
|
177
|
+
};
|
|
178
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
4
|
*
|
|
4
5
|
* This source code is licensed under the MIT license found in the
|
|
5
6
|
* LICENSE file in the root directory of this source tree.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
export declare function validateDocFrontMatter(frontMatter: Record<string, unknown>): DocFrontMatter;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,54 @@
|
|
|
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, Sidebar, SidebarItem, SidebarItemCategory, SidebarItemLink, SidebarItemDoc, SidebarCategoriesShorthand, SidebarItemConfig, SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
|
|
8
|
+
import type { DocMetadataBase, PropNavigationLink } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
|
|
10
|
+
export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
|
|
11
|
+
export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
|
|
12
|
+
export declare function collectSidebarCategories(sidebar: Sidebar): SidebarItemCategory[];
|
|
13
|
+
export declare function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[];
|
|
14
|
+
export declare function collectSidebarDocIds(sidebar: Sidebar): string[];
|
|
15
|
+
export declare function collectSidebarNavigation(sidebar: Sidebar): SidebarNavigationItem[];
|
|
16
|
+
export declare function collectSidebarsDocIds(sidebars: Sidebars): {
|
|
17
|
+
[sidebarId: string]: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare function collectSidebarsNavigations(sidebars: Sidebars): {
|
|
20
|
+
[sidebarId: string]: SidebarNavigationItem[];
|
|
21
|
+
};
|
|
22
|
+
export declare type SidebarNavigation = {
|
|
23
|
+
sidebarName: string | undefined;
|
|
24
|
+
previous: SidebarNavigationItem | undefined;
|
|
25
|
+
next: SidebarNavigationItem | undefined;
|
|
26
|
+
};
|
|
27
|
+
export declare type SidebarsUtils = {
|
|
28
|
+
sidebars: Sidebars;
|
|
29
|
+
getFirstDocIdOfFirstSidebar: () => string | undefined;
|
|
30
|
+
getSidebarNameByDocId: (docId: string) => string | undefined;
|
|
31
|
+
getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
|
|
32
|
+
getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
|
|
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
|
+
*/
|
|
39
|
+
getFirstLink: (sidebarId: string) => {
|
|
40
|
+
type: 'doc';
|
|
41
|
+
id: string;
|
|
42
|
+
label: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: 'generated-index';
|
|
45
|
+
permalink: string;
|
|
46
|
+
label: string;
|
|
47
|
+
} | undefined;
|
|
48
|
+
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
|
49
|
+
};
|
|
50
|
+
export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
|
|
51
|
+
export declare function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink;
|
|
52
|
+
export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: {
|
|
53
|
+
[docId: string]: DocMetadataBase;
|
|
54
|
+
}): PropNavigationLink | undefined;
|