@docusaurus/plugin-content-docs 2.0.0-beta.138b4c997 → 2.0.0-beta.14
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 +2 -2
- package/lib/cli.js +14 -35
- package/lib/client/docsClientUtils.d.ts +0 -3
- package/lib/client/docsClientUtils.js +19 -22
- package/lib/docFrontMatter.d.ts +1 -1
- package/lib/docFrontMatter.js +8 -4
- package/lib/docs.d.ts +25 -3
- package/lib/docs.js +126 -41
- package/lib/globalData.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +101 -133
- package/lib/lastUpdate.js +12 -12
- package/lib/markdown/index.d.ts +3 -6
- package/lib/markdown/index.js +3 -3
- package/lib/markdown/linkify.js +2 -2
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/options.d.ts +3 -3
- package/lib/options.js +48 -11
- package/lib/props.d.ts +7 -2
- package/lib/props.js +60 -9
- package/lib/routes.d.ts +27 -0
- package/lib/routes.js +105 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +5 -2
- package/lib/sidebars/generator.js +216 -0
- package/lib/sidebars/index.d.ts +15 -0
- package/lib/sidebars/index.js +73 -0
- package/lib/sidebars/normalization.d.ts +14 -0
- package/lib/sidebars/normalization.js +77 -0
- package/lib/sidebars/processor.d.ts +18 -0
- package/lib/sidebars/processor.js +85 -0
- package/lib/sidebars/types.d.ts +127 -0
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → lib/sidebars/types.js} +2 -10
- package/lib/sidebars/utils.d.ts +35 -0
- package/lib/sidebars/utils.js +228 -0
- package/lib/sidebars/validation.d.ts +10 -0
- package/lib/sidebars/validation.js +138 -0
- package/lib/slug.d.ts +4 -3
- package/lib/slug.js +27 -15
- package/{src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js → lib/tags.d.ts} +2 -8
- package/lib/tags.js +20 -0
- package/lib/theme/hooks/useDocs.js +24 -21
- package/lib/translations.d.ts +2 -2
- package/lib/translations.js +71 -29
- package/lib/types.d.ts +52 -64
- package/lib/versions.d.ts +3 -3
- package/lib/versions.js +41 -22
- package/package.json +20 -20
- package/src/categoryGeneratedIndex.ts +57 -0
- package/src/cli.ts +10 -42
- package/src/client/docsClientUtils.ts +14 -26
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/docFrontMatter.ts +10 -5
- package/src/docs.ts +164 -36
- package/src/globalData.ts +6 -1
- package/src/index.ts +127 -177
- package/src/lastUpdate.ts +14 -16
- package/src/markdown/index.ts +8 -12
- package/src/numberPrefix.ts +5 -3
- package/src/options.ts +56 -15
- package/src/plugin-content-docs.d.ts +172 -43
- package/src/props.ts +90 -16
- package/src/routes.ts +169 -0
- package/src/sidebars/generator.ts +302 -0
- package/src/sidebars/index.ts +94 -0
- package/src/sidebars/normalization.ts +112 -0
- package/src/sidebars/processor.ts +154 -0
- package/src/sidebars/types.ts +211 -0
- package/src/sidebars/utils.ts +329 -0
- package/src/sidebars/validation.ts +168 -0
- package/src/slug.ts +32 -17
- package/src/tags.ts +19 -0
- package/src/theme/hooks/useDocs.ts +5 -1
- package/src/translations.ts +103 -47
- package/src/types.ts +64 -108
- package/src/versions.ts +59 -25
- 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/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-first-level-not-category.js +0 -20
- 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/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
- 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/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/tsconfig.json +0 -9
|
@@ -0,0 +1,18 @@
|
|
|
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 { NumberPrefixParser, DocMetadataBase, VersionMetadata, SidebarOptions } from '../types';
|
|
8
|
+
import type { Sidebars, NormalizedSidebars, SidebarItemsGeneratorOption } from './types';
|
|
9
|
+
import { Slugger } from '@docusaurus/utils';
|
|
10
|
+
export declare type SidebarProcessorParams = {
|
|
11
|
+
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
12
|
+
numberPrefixParser: NumberPrefixParser;
|
|
13
|
+
docs: DocMetadataBase[];
|
|
14
|
+
version: VersionMetadata;
|
|
15
|
+
categoryLabelSlugger: Slugger;
|
|
16
|
+
sidebarOptions: SidebarOptions;
|
|
17
|
+
};
|
|
18
|
+
export declare function processSidebars(unprocessedSidebars: NormalizedSidebars, params: SidebarProcessorParams): Promise<Sidebars>;
|
|
@@ -0,0 +1,85 @@
|
|
|
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 utils_1 = require("./utils");
|
|
12
|
+
const generator_1 = require("./generator");
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
14
|
+
const combine_promises_1 = (0, tslib_1.__importDefault)(require("combine-promises"));
|
|
15
|
+
const normalization_1 = require("./normalization");
|
|
16
|
+
function toSidebarItemsGeneratorDoc(doc) {
|
|
17
|
+
return (0, lodash_1.pick)(doc, [
|
|
18
|
+
'id',
|
|
19
|
+
'unversionedId',
|
|
20
|
+
'frontMatter',
|
|
21
|
+
'source',
|
|
22
|
+
'sourceDirName',
|
|
23
|
+
'sidebarPosition',
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
function toSidebarItemsGeneratorVersion(version) {
|
|
27
|
+
return (0, lodash_1.pick)(version, ['versionName', 'contentPath']);
|
|
28
|
+
}
|
|
29
|
+
// Handle the generation of autogenerated sidebar items and other post-processing checks
|
|
30
|
+
async function processSidebar(unprocessedSidebar, params) {
|
|
31
|
+
const { sidebarItemsGenerator, numberPrefixParser, docs, version, sidebarOptions, } = params;
|
|
32
|
+
// Just a minor lazy transformation optimization
|
|
33
|
+
const getSidebarItemsGeneratorDocsAndVersion = (0, lodash_1.memoize)(() => ({
|
|
34
|
+
docs: docs.map(toSidebarItemsGeneratorDoc),
|
|
35
|
+
version: toSidebarItemsGeneratorVersion(version),
|
|
36
|
+
}));
|
|
37
|
+
async function processCategoryItem(item) {
|
|
38
|
+
return {
|
|
39
|
+
...item,
|
|
40
|
+
items: (await Promise.all(item.items.map(processItem))).flat(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function processAutoGeneratedItem(item) {
|
|
44
|
+
// TODO the returned type can't be trusted in practice (generator can be user-provided)
|
|
45
|
+
const generatedItems = await sidebarItemsGenerator({
|
|
46
|
+
item,
|
|
47
|
+
numberPrefixParser,
|
|
48
|
+
defaultSidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
|
|
49
|
+
...getSidebarItemsGeneratorDocsAndVersion(),
|
|
50
|
+
options: sidebarOptions,
|
|
51
|
+
});
|
|
52
|
+
// TODO validate generated items: user can generate bad items
|
|
53
|
+
const generatedItemsNormalized = generatedItems.flatMap((generatedItem) => (0, normalization_1.normalizeItem)(generatedItem, { ...params, ...sidebarOptions }));
|
|
54
|
+
// Process again... weird but sidebar item generated might generate some auto-generated items?
|
|
55
|
+
return processItems(generatedItemsNormalized);
|
|
56
|
+
}
|
|
57
|
+
async function processItem(item) {
|
|
58
|
+
if (item.type === 'category') {
|
|
59
|
+
return [await processCategoryItem(item)];
|
|
60
|
+
}
|
|
61
|
+
if (item.type === 'autogenerated') {
|
|
62
|
+
return processAutoGeneratedItem(item);
|
|
63
|
+
}
|
|
64
|
+
return [item];
|
|
65
|
+
}
|
|
66
|
+
async function processItems(items) {
|
|
67
|
+
return (await Promise.all(items.map(processItem))).flat();
|
|
68
|
+
}
|
|
69
|
+
const processedSidebar = await processItems(unprocessedSidebar);
|
|
70
|
+
const fixSidebarItemInconsistencies = (item) => {
|
|
71
|
+
// A non-collapsible category can't be collapsed!
|
|
72
|
+
if (item.type === 'category' && !item.collapsible && item.collapsed) {
|
|
73
|
+
return {
|
|
74
|
+
...item,
|
|
75
|
+
collapsed: false,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return item;
|
|
79
|
+
};
|
|
80
|
+
return (0, utils_1.transformSidebarItems)(processedSidebar, fixSidebarItemInconsistencies);
|
|
81
|
+
}
|
|
82
|
+
async function processSidebars(unprocessedSidebars, params) {
|
|
83
|
+
return (0, combine_promises_1.default)((0, lodash_1.mapValues)(unprocessedSidebars, (unprocessedSidebar) => processSidebar(unprocessedSidebar, params)));
|
|
84
|
+
}
|
|
85
|
+
exports.processSidebars = processSidebars;
|
|
@@ -0,0 +1,127 @@
|
|
|
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 } from 'utility-types';
|
|
8
|
+
import type { DocMetadataBase, VersionMetadata, NumberPrefixParser, SidebarOptions } from '../types';
|
|
9
|
+
import { Required } from 'utility-types';
|
|
10
|
+
declare type Expand<T extends Record<string, unknown>> = {
|
|
11
|
+
[P in keyof T]: T[P];
|
|
12
|
+
};
|
|
13
|
+
export declare type SidebarItemBase = {
|
|
14
|
+
className?: string;
|
|
15
|
+
customProps?: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
18
|
+
type: 'doc' | 'ref';
|
|
19
|
+
label?: string;
|
|
20
|
+
id: string;
|
|
21
|
+
};
|
|
22
|
+
export declare type SidebarItemLink = SidebarItemBase & {
|
|
23
|
+
type: 'link';
|
|
24
|
+
href: string;
|
|
25
|
+
label: string;
|
|
26
|
+
};
|
|
27
|
+
export declare type SidebarItemAutogenerated = SidebarItemBase & {
|
|
28
|
+
type: 'autogenerated';
|
|
29
|
+
dirName: string;
|
|
30
|
+
};
|
|
31
|
+
declare type SidebarItemCategoryBase = SidebarItemBase & {
|
|
32
|
+
type: 'category';
|
|
33
|
+
label: string;
|
|
34
|
+
collapsed: boolean;
|
|
35
|
+
collapsible: boolean;
|
|
36
|
+
};
|
|
37
|
+
export declare type SidebarItemCategoryLinkDoc = {
|
|
38
|
+
type: 'doc';
|
|
39
|
+
id: string;
|
|
40
|
+
};
|
|
41
|
+
export declare type SidebarItemCategoryLinkGeneratedIndexConfig = {
|
|
42
|
+
type: 'generated-index';
|
|
43
|
+
slug?: string;
|
|
44
|
+
title?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
};
|
|
47
|
+
export declare type SidebarItemCategoryLinkGeneratedIndex = {
|
|
48
|
+
type: 'generated-index';
|
|
49
|
+
slug: string;
|
|
50
|
+
permalink: string;
|
|
51
|
+
title?: string;
|
|
52
|
+
description?: string;
|
|
53
|
+
};
|
|
54
|
+
export declare type SidebarItemCategoryLinkConfig = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndexConfig;
|
|
55
|
+
export declare type SidebarItemCategoryLink = SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
|
|
56
|
+
export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
|
|
57
|
+
items: SidebarItemConfig[];
|
|
58
|
+
link?: SidebarItemCategoryLinkConfig;
|
|
59
|
+
}>;
|
|
60
|
+
export declare type SidebarCategoriesShorthand = {
|
|
61
|
+
[sidebarCategory: string]: SidebarItemConfig[];
|
|
62
|
+
};
|
|
63
|
+
export declare type SidebarItemConfig = SidebarItemDoc | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
|
|
64
|
+
export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
|
|
65
|
+
export declare type SidebarsConfig = {
|
|
66
|
+
[sidebarId: string]: SidebarConfig;
|
|
67
|
+
};
|
|
68
|
+
export declare type NormalizedSidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
69
|
+
items: NormalizedSidebarItem[];
|
|
70
|
+
link?: SidebarItemCategoryLink;
|
|
71
|
+
}>;
|
|
72
|
+
export declare type NormalizedSidebarItem = SidebarItemDoc | SidebarItemLink | NormalizedSidebarItemCategory | SidebarItemAutogenerated;
|
|
73
|
+
export declare type NormalizedSidebar = NormalizedSidebarItem[];
|
|
74
|
+
export declare type NormalizedSidebars = {
|
|
75
|
+
[sidebarId: string]: NormalizedSidebar;
|
|
76
|
+
};
|
|
77
|
+
export declare type SidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
78
|
+
items: SidebarItem[];
|
|
79
|
+
link?: SidebarItemCategoryLink;
|
|
80
|
+
}>;
|
|
81
|
+
export declare type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
|
|
82
|
+
export declare type SidebarItemCategoryWithGeneratedIndex = SidebarItemCategoryWithLink & {
|
|
83
|
+
link: SidebarItemCategoryLinkGeneratedIndex;
|
|
84
|
+
};
|
|
85
|
+
export declare type SidebarItem = SidebarItemDoc | SidebarItemLink | SidebarItemCategory;
|
|
86
|
+
export declare type SidebarNavigationItem = SidebarItemDoc | SidebarItemCategoryWithLink;
|
|
87
|
+
export declare type Sidebar = SidebarItem[];
|
|
88
|
+
export declare type SidebarItemType = SidebarItem['type'];
|
|
89
|
+
export declare type Sidebars = {
|
|
90
|
+
[sidebarId: string]: Sidebar;
|
|
91
|
+
};
|
|
92
|
+
export declare type PropSidebarItemCategory = Expand<SidebarItemCategoryBase & {
|
|
93
|
+
items: PropSidebarItem[];
|
|
94
|
+
href?: string;
|
|
95
|
+
}>;
|
|
96
|
+
export declare type PropSidebarItemLink = SidebarItemLink & {
|
|
97
|
+
docId?: string;
|
|
98
|
+
};
|
|
99
|
+
export declare type PropSidebarItem = PropSidebarItemLink | PropSidebarItemCategory;
|
|
100
|
+
export declare type PropSidebar = PropSidebarItem[];
|
|
101
|
+
export declare type PropSidebars = {
|
|
102
|
+
[sidebarId: string]: PropSidebar;
|
|
103
|
+
};
|
|
104
|
+
export declare type PropVersionDoc = {
|
|
105
|
+
id: string;
|
|
106
|
+
title: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
sidebar?: string;
|
|
109
|
+
};
|
|
110
|
+
export declare type PropVersionDocs = {
|
|
111
|
+
[docId: string]: PropVersionDoc;
|
|
112
|
+
};
|
|
113
|
+
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'unversionedId' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
114
|
+
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
115
|
+
export declare type SidebarItemsGeneratorArgs = {
|
|
116
|
+
item: SidebarItemAutogenerated;
|
|
117
|
+
version: SidebarItemsGeneratorVersion;
|
|
118
|
+
docs: SidebarItemsGeneratorDoc[];
|
|
119
|
+
numberPrefixParser: NumberPrefixParser;
|
|
120
|
+
options: SidebarOptions;
|
|
121
|
+
};
|
|
122
|
+
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
|
|
123
|
+
export declare type SidebarItemsGeneratorOptionArgs = {
|
|
124
|
+
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
125
|
+
} & SidebarItemsGeneratorArgs;
|
|
126
|
+
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<SidebarItem[]>;
|
|
127
|
+
export {};
|
|
@@ -1,16 +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
|
-
module.exports = {
|
|
9
|
-
someSidebar: [
|
|
10
|
-
{type: 'doc', id: 'API/api-end'},
|
|
11
|
-
{
|
|
12
|
-
type: 'autogenerated',
|
|
13
|
-
dirName: '3-API',
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,35 @@
|
|
|
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 } from './types';
|
|
8
|
+
import { DocMetadataBase, DocNavLink } from '../types';
|
|
9
|
+
import { SidebarItemCategoryWithGeneratedIndex, SidebarNavigationItem } from './types';
|
|
10
|
+
export declare function isCategoriesShorthand(item: SidebarItemConfig): item is SidebarCategoriesShorthand;
|
|
11
|
+
export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item: SidebarItem) => SidebarItem): Sidebar;
|
|
12
|
+
export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
|
|
13
|
+
export declare function collectSidebarCategories(sidebar: Sidebar): SidebarItemCategory[];
|
|
14
|
+
export declare function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[];
|
|
15
|
+
export declare function collectSidebarDocIds(sidebar: Sidebar): string[];
|
|
16
|
+
export declare function collectSidebarNavigation(sidebar: Sidebar): SidebarNavigationItem[];
|
|
17
|
+
export declare function collectSidebarsDocIds(sidebars: Sidebars): Record<string, string[]>;
|
|
18
|
+
export declare function collectSidebarsNavigations(sidebars: Sidebars): Record<string, SidebarNavigationItem[]>;
|
|
19
|
+
export declare type SidebarNavigation = {
|
|
20
|
+
sidebarName: string | undefined;
|
|
21
|
+
previous: SidebarNavigationItem | undefined;
|
|
22
|
+
next: SidebarNavigationItem | undefined;
|
|
23
|
+
};
|
|
24
|
+
export declare type SidebarsUtils = {
|
|
25
|
+
sidebars: Sidebars;
|
|
26
|
+
getFirstDocIdOfFirstSidebar: () => string | undefined;
|
|
27
|
+
getSidebarNameByDocId: (docId: string) => string | undefined;
|
|
28
|
+
getDocNavigation: (unversionedId: string, versionedId: string) => SidebarNavigation;
|
|
29
|
+
getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
|
|
30
|
+
getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
|
|
31
|
+
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
|
32
|
+
};
|
|
33
|
+
export declare function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils;
|
|
34
|
+
export declare function toDocNavigationLink(doc: DocMetadataBase): DocNavLink;
|
|
35
|
+
export declare function toNavigationLink(navigationItem: SidebarNavigationItem | undefined, docsById: Record<string, DocMetadataBase>): DocNavLink | undefined;
|
|
@@ -0,0 +1,228 @@
|
|
|
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.toNavigationLink = exports.toDocNavigationLink = exports.createSidebarsUtils = exports.collectSidebarsNavigations = exports.collectSidebarsDocIds = exports.collectSidebarNavigation = exports.collectSidebarDocIds = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = exports.isCategoriesShorthand = void 0;
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
|
+
function isCategoriesShorthand(item) {
|
|
13
|
+
return typeof item !== 'string' && !item.type;
|
|
14
|
+
}
|
|
15
|
+
exports.isCategoriesShorthand = isCategoriesShorthand;
|
|
16
|
+
function transformSidebarItems(sidebar, updateFn) {
|
|
17
|
+
function transformRecursive(item) {
|
|
18
|
+
if (item.type === 'category') {
|
|
19
|
+
return updateFn({
|
|
20
|
+
...item,
|
|
21
|
+
items: item.items.map(transformRecursive),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return updateFn(item);
|
|
25
|
+
}
|
|
26
|
+
return sidebar.map(transformRecursive);
|
|
27
|
+
}
|
|
28
|
+
exports.transformSidebarItems = transformSidebarItems;
|
|
29
|
+
// Flatten sidebar items into a single flat array (containing categories/docs on the same level)
|
|
30
|
+
// /!\ order matters (useful for next/prev nav), top categories appear before their child elements
|
|
31
|
+
function flattenSidebarItems(items) {
|
|
32
|
+
function flattenRecursive(item) {
|
|
33
|
+
return item.type === 'category'
|
|
34
|
+
? [item, ...item.items.flatMap(flattenRecursive)]
|
|
35
|
+
: [item];
|
|
36
|
+
}
|
|
37
|
+
return items.flatMap(flattenRecursive);
|
|
38
|
+
}
|
|
39
|
+
function collectSidebarItemsOfType(type, sidebar) {
|
|
40
|
+
return flattenSidebarItems(sidebar).filter((item) => item.type === type);
|
|
41
|
+
}
|
|
42
|
+
function collectSidebarDocItems(sidebar) {
|
|
43
|
+
return collectSidebarItemsOfType('doc', sidebar);
|
|
44
|
+
}
|
|
45
|
+
exports.collectSidebarDocItems = collectSidebarDocItems;
|
|
46
|
+
function collectSidebarCategories(sidebar) {
|
|
47
|
+
return collectSidebarItemsOfType('category', sidebar);
|
|
48
|
+
}
|
|
49
|
+
exports.collectSidebarCategories = collectSidebarCategories;
|
|
50
|
+
function collectSidebarLinks(sidebar) {
|
|
51
|
+
return collectSidebarItemsOfType('link', sidebar);
|
|
52
|
+
}
|
|
53
|
+
exports.collectSidebarLinks = collectSidebarLinks;
|
|
54
|
+
// /!\ docId order matters for navigation!
|
|
55
|
+
function collectSidebarDocIds(sidebar) {
|
|
56
|
+
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
57
|
+
var _a;
|
|
58
|
+
if (item.type === 'category') {
|
|
59
|
+
return ((_a = item.link) === null || _a === void 0 ? void 0 : _a.type) === 'doc' ? [item.link.id] : [];
|
|
60
|
+
}
|
|
61
|
+
if (item.type === 'doc') {
|
|
62
|
+
return [item.id];
|
|
63
|
+
}
|
|
64
|
+
return [];
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
exports.collectSidebarDocIds = collectSidebarDocIds;
|
|
68
|
+
function collectSidebarNavigation(sidebar) {
|
|
69
|
+
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
70
|
+
if (item.type === 'category' && item.link) {
|
|
71
|
+
return [item];
|
|
72
|
+
}
|
|
73
|
+
if (item.type === 'doc') {
|
|
74
|
+
return [item];
|
|
75
|
+
}
|
|
76
|
+
return [];
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.collectSidebarNavigation = collectSidebarNavigation;
|
|
80
|
+
function collectSidebarsDocIds(sidebars) {
|
|
81
|
+
return (0, lodash_1.mapValues)(sidebars, collectSidebarDocIds);
|
|
82
|
+
}
|
|
83
|
+
exports.collectSidebarsDocIds = collectSidebarsDocIds;
|
|
84
|
+
function collectSidebarsNavigations(sidebars) {
|
|
85
|
+
return (0, lodash_1.mapValues)(sidebars, collectSidebarNavigation);
|
|
86
|
+
}
|
|
87
|
+
exports.collectSidebarsNavigations = collectSidebarsNavigations;
|
|
88
|
+
function createSidebarsUtils(sidebars) {
|
|
89
|
+
const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
|
|
90
|
+
const sidebarNameToNavigationItems = collectSidebarsNavigations(sidebars);
|
|
91
|
+
// Reverse mapping
|
|
92
|
+
const docIdToSidebarName = Object.fromEntries(Object.entries(sidebarNameToDocIds).flatMap(([sidebarName, docIds]) => docIds.map((docId) => [docId, sidebarName])));
|
|
93
|
+
function getFirstDocIdOfFirstSidebar() {
|
|
94
|
+
var _a;
|
|
95
|
+
return (_a = Object.values(sidebarNameToDocIds)[0]) === null || _a === void 0 ? void 0 : _a[0];
|
|
96
|
+
}
|
|
97
|
+
function getSidebarNameByDocId(docId) {
|
|
98
|
+
return docIdToSidebarName[docId];
|
|
99
|
+
}
|
|
100
|
+
function emptySidebarNavigation() {
|
|
101
|
+
return {
|
|
102
|
+
sidebarName: undefined,
|
|
103
|
+
previous: undefined,
|
|
104
|
+
next: undefined,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function getDocNavigation(unversionedId, versionedId) {
|
|
108
|
+
// TODO legacy id retro-compatibility!
|
|
109
|
+
let docId = unversionedId;
|
|
110
|
+
let sidebarName = getSidebarNameByDocId(docId);
|
|
111
|
+
if (!sidebarName) {
|
|
112
|
+
docId = versionedId;
|
|
113
|
+
sidebarName = getSidebarNameByDocId(docId);
|
|
114
|
+
}
|
|
115
|
+
if (sidebarName) {
|
|
116
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
117
|
+
const currentItemIndex = navigationItems.findIndex((item) => {
|
|
118
|
+
if (item.type === 'doc') {
|
|
119
|
+
return item.id === docId;
|
|
120
|
+
}
|
|
121
|
+
if (item.type === 'category' && item.link.type === 'doc') {
|
|
122
|
+
return item.link.id === docId;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
});
|
|
126
|
+
const { previous, next } = (0, utils_1.getElementsAround)(navigationItems, currentItemIndex);
|
|
127
|
+
return { sidebarName, previous, next };
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
return emptySidebarNavigation();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function getCategoryGeneratedIndexList() {
|
|
134
|
+
return Object.values(sidebarNameToNavigationItems)
|
|
135
|
+
.flat()
|
|
136
|
+
.flatMap((item) => {
|
|
137
|
+
if (item.type === 'category' && item.link.type === 'generated-index') {
|
|
138
|
+
return [item];
|
|
139
|
+
}
|
|
140
|
+
return [];
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// We identity the category generated index by its permalink (should be unique)
|
|
144
|
+
// More reliable than using object identity
|
|
145
|
+
function getCategoryGeneratedIndexNavigation(categoryGeneratedIndexPermalink) {
|
|
146
|
+
var _a;
|
|
147
|
+
function isCurrentCategoryGeneratedIndexItem(item) {
|
|
148
|
+
var _a;
|
|
149
|
+
return (item.type === 'category' &&
|
|
150
|
+
((_a = item.link) === null || _a === void 0 ? void 0 : _a.type) === 'generated-index' &&
|
|
151
|
+
item.link.permalink === categoryGeneratedIndexPermalink);
|
|
152
|
+
}
|
|
153
|
+
const sidebarName = (_a = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))) === null || _a === void 0 ? void 0 : _a[0];
|
|
154
|
+
if (sidebarName) {
|
|
155
|
+
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
|
156
|
+
const currentItemIndex = navigationItems.findIndex(isCurrentCategoryGeneratedIndexItem);
|
|
157
|
+
const { previous, next } = (0, utils_1.getElementsAround)(navigationItems, currentItemIndex);
|
|
158
|
+
return { sidebarName, previous, next };
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
return emptySidebarNavigation();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function checkSidebarsDocIds(validDocIds, sidebarFilePath) {
|
|
165
|
+
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
166
|
+
const invalidSidebarDocIds = (0, lodash_1.difference)(allSidebarDocIds, validDocIds);
|
|
167
|
+
if (invalidSidebarDocIds.length > 0) {
|
|
168
|
+
throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
|
|
169
|
+
These sidebar document ids do not exist:
|
|
170
|
+
- ${invalidSidebarDocIds.sort().join('\n- ')}
|
|
171
|
+
|
|
172
|
+
Available document ids are:
|
|
173
|
+
- ${(0, lodash_1.uniq)(validDocIds).sort().join('\n- ')}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
sidebars,
|
|
178
|
+
getFirstDocIdOfFirstSidebar,
|
|
179
|
+
getSidebarNameByDocId,
|
|
180
|
+
getDocNavigation,
|
|
181
|
+
getCategoryGeneratedIndexList,
|
|
182
|
+
getCategoryGeneratedIndexNavigation,
|
|
183
|
+
checkSidebarsDocIds,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
exports.createSidebarsUtils = createSidebarsUtils;
|
|
187
|
+
function toDocNavigationLink(doc) {
|
|
188
|
+
var _a;
|
|
189
|
+
const { title, permalink, frontMatter: { pagination_label: paginationLabel, sidebar_label: sidebarLabel, }, } = doc;
|
|
190
|
+
return { title: (_a = paginationLabel !== null && paginationLabel !== void 0 ? paginationLabel : sidebarLabel) !== null && _a !== void 0 ? _a : title, permalink };
|
|
191
|
+
}
|
|
192
|
+
exports.toDocNavigationLink = toDocNavigationLink;
|
|
193
|
+
function toNavigationLink(navigationItem, docsById) {
|
|
194
|
+
function getDocById(docId) {
|
|
195
|
+
const doc = docsById[docId];
|
|
196
|
+
if (!doc) {
|
|
197
|
+
throw new Error(`Can't create navigation link: no doc found with id=${docId}`);
|
|
198
|
+
}
|
|
199
|
+
return doc;
|
|
200
|
+
}
|
|
201
|
+
function handleCategory(category) {
|
|
202
|
+
if (category.link.type === 'doc') {
|
|
203
|
+
return toDocNavigationLink(getDocById(category.link.id));
|
|
204
|
+
}
|
|
205
|
+
else if (category.link.type === 'generated-index') {
|
|
206
|
+
return {
|
|
207
|
+
title: category.label,
|
|
208
|
+
permalink: category.link.permalink,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
throw new Error('unexpected category link type');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (!navigationItem) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
if (navigationItem.type === 'doc') {
|
|
219
|
+
return toDocNavigationLink(getDocById(navigationItem.id));
|
|
220
|
+
}
|
|
221
|
+
else if (navigationItem.type === 'category') {
|
|
222
|
+
return handleCategory(navigationItem);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
throw new Error('unexpected navigation item');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.toNavigationLink = toNavigationLink;
|
|
@@ -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 { SidebarsConfig } from './types';
|
|
8
|
+
import { CategoryMetadataFile } from './generator';
|
|
9
|
+
export declare function validateSidebars(sidebars: unknown): asserts sidebars is SidebarsConfig;
|
|
10
|
+
export declare function validateCategoryMetadataFile(unsafeContent: unknown): CategoryMetadataFile;
|
|
@@ -0,0 +1,138 @@
|
|
|
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.validateCategoryMetadataFile = exports.validateSidebars = void 0;
|
|
10
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
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 sidebarItemCategoryLinkSchema = utils_validation_1.Joi.object()
|
|
36
|
+
.when('.type', {
|
|
37
|
+
switch: [
|
|
38
|
+
{
|
|
39
|
+
is: 'doc',
|
|
40
|
+
then: utils_validation_1.Joi.object({
|
|
41
|
+
type: 'doc',
|
|
42
|
+
id: utils_validation_1.Joi.string().required(),
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
is: 'generated-index',
|
|
47
|
+
then: utils_validation_1.Joi.object({
|
|
48
|
+
type: 'generated-index',
|
|
49
|
+
slug: utils_validation_1.Joi.string().optional(),
|
|
50
|
+
// permalink: Joi.string().optional(), // No, this one is not in the user config, only in the normalized version
|
|
51
|
+
title: utils_validation_1.Joi.string().optional(),
|
|
52
|
+
description: utils_validation_1.Joi.string().optional(),
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
is: utils_validation_1.Joi.string().required(),
|
|
57
|
+
then: utils_validation_1.Joi.forbidden().messages({
|
|
58
|
+
'any.unknown': 'Unknown sidebar category link type "{.type}".',
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
})
|
|
63
|
+
.id('sidebarCategoryLinkSchema');
|
|
64
|
+
const sidebarItemCategorySchema = sidebarItemBaseSchema.append({
|
|
65
|
+
type: 'category',
|
|
66
|
+
label: utils_validation_1.Joi.string()
|
|
67
|
+
.required()
|
|
68
|
+
.messages({ 'any.unknown': '"label" must be a string' }),
|
|
69
|
+
// TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
|
|
70
|
+
items: utils_validation_1.Joi.array()
|
|
71
|
+
.required()
|
|
72
|
+
.messages({ 'any.unknown': '"items" must be an array' }),
|
|
73
|
+
link: sidebarItemCategoryLinkSchema,
|
|
74
|
+
collapsed: utils_validation_1.Joi.boolean().messages({
|
|
75
|
+
'any.unknown': '"collapsed" must be a boolean',
|
|
76
|
+
}),
|
|
77
|
+
collapsible: utils_validation_1.Joi.boolean().messages({
|
|
78
|
+
'any.unknown': '"collapsible" must be a boolean',
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
const sidebarItemSchema = utils_validation_1.Joi.object()
|
|
82
|
+
.when('.type', {
|
|
83
|
+
switch: [
|
|
84
|
+
{ is: 'link', then: sidebarItemLinkSchema },
|
|
85
|
+
{
|
|
86
|
+
is: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
|
|
87
|
+
then: sidebarItemDocSchema,
|
|
88
|
+
},
|
|
89
|
+
{ is: 'autogenerated', then: sidebarItemAutogeneratedSchema },
|
|
90
|
+
{ is: 'category', then: sidebarItemCategorySchema },
|
|
91
|
+
{
|
|
92
|
+
is: utils_validation_1.Joi.any().required(),
|
|
93
|
+
then: utils_validation_1.Joi.forbidden().messages({
|
|
94
|
+
'any.unknown': 'Unknown sidebar item type "{.type}".',
|
|
95
|
+
}),
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
})
|
|
99
|
+
.id('sidebarItemSchema');
|
|
100
|
+
function validateSidebarItem(item) {
|
|
101
|
+
if (typeof item === 'string') {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// TODO: remove once with proper Joi support
|
|
105
|
+
// Because we can't use Joi to validate nested items (see above), we do it manually
|
|
106
|
+
if ((0, utils_1.isCategoriesShorthand)(item)) {
|
|
107
|
+
Object.values(item).forEach((category) => category.forEach(validateSidebarItem));
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
utils_validation_1.Joi.assert(item, sidebarItemSchema);
|
|
111
|
+
if (item.type === 'category') {
|
|
112
|
+
item.items.forEach(validateSidebarItem);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function validateSidebars(sidebars) {
|
|
117
|
+
Object.values(sidebars).forEach((sidebar) => {
|
|
118
|
+
if (Array.isArray(sidebar)) {
|
|
119
|
+
sidebar.forEach(validateSidebarItem);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
validateSidebarItem(sidebar);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
exports.validateSidebars = validateSidebars;
|
|
127
|
+
const categoryMetadataFileSchema = utils_validation_1.Joi.object({
|
|
128
|
+
label: utils_validation_1.Joi.string(),
|
|
129
|
+
position: utils_validation_1.Joi.number(),
|
|
130
|
+
collapsed: utils_validation_1.Joi.boolean(),
|
|
131
|
+
collapsible: utils_validation_1.Joi.boolean(),
|
|
132
|
+
className: utils_validation_1.Joi.string(),
|
|
133
|
+
link: sidebarItemCategoryLinkSchema,
|
|
134
|
+
});
|
|
135
|
+
function validateCategoryMetadataFile(unsafeContent) {
|
|
136
|
+
return utils_validation_1.Joi.attempt(unsafeContent, categoryMetadataFileSchema);
|
|
137
|
+
}
|
|
138
|
+
exports.validateCategoryMetadataFile = validateCategoryMetadataFile;
|
package/lib/slug.d.ts
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
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 { NumberPrefixParser } from './types';
|
|
8
|
-
export default function getSlug({ baseID, frontmatterSlug,
|
|
7
|
+
import type { DocMetadataBase, NumberPrefixParser } from './types';
|
|
8
|
+
export default function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
|
|
9
9
|
baseID: string;
|
|
10
10
|
frontmatterSlug?: string;
|
|
11
|
-
|
|
11
|
+
source: DocMetadataBase['slug'];
|
|
12
|
+
sourceDirName: DocMetadataBase['sourceDirName'];
|
|
12
13
|
stripDirNumberPrefixes?: boolean;
|
|
13
14
|
numberPrefixParser?: NumberPrefixParser;
|
|
14
15
|
}): string;
|