@docusaurus/plugin-content-docs 2.0.0-beta.15d451942 → 2.0.0-beta.16
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 +39 -0
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +40 -52
- package/lib/client/docsClientUtils.d.ts +3 -25
- package/lib/client/docsClientUtils.js +27 -33
- package/lib/{theme/hooks/useDocs.d.ts → client/index.d.ts} +1 -2
- package/lib/client/index.js +75 -0
- package/lib/docFrontMatter.d.ts +1 -14
- package/lib/docFrontMatter.js +13 -6
- package/lib/docs.d.ts +40 -4
- package/lib/docs.js +170 -54
- package/lib/globalData.d.ts +5 -1
- package/lib/globalData.js +35 -2
- package/lib/index.d.ts +4 -3
- package/lib/index.js +124 -136
- package/lib/lastUpdate.js +16 -29
- 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 +3 -3
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/numberPrefix.js +7 -6
- package/lib/options.d.ts +3 -3
- package/lib/options.js +52 -17
- package/lib/props.d.ts +7 -2
- package/lib/props.js +71 -14
- package/lib/routes.d.ts +28 -0
- package/lib/routes.js +110 -0
- package/lib/server-export.d.ts +8 -0
- package/lib/server-export.js +23 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -6
- package/lib/sidebars/generator.js +190 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +88 -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 +72 -0
- package/lib/sidebars/processor.d.ts +8 -0
- package/lib/sidebars/processor.js +79 -0
- package/lib/sidebars/types.d.ts +166 -0
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → lib/sidebars/types.js} +2 -10
- package/lib/sidebars/utils.d.ts +43 -0
- package/lib/sidebars/utils.js +265 -0
- package/lib/sidebars/validation.d.ts +9 -0
- package/lib/sidebars/validation.js +137 -0
- package/lib/slug.d.ts +6 -4
- package/lib/slug.js +29 -18
- package/{src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js → lib/tags.d.ts} +2 -8
- package/lib/tags.js +21 -0
- package/lib/translations.d.ts +2 -2
- package/lib/translations.js +87 -44
- package/lib/types.d.ts +55 -128
- package/lib/versions.d.ts +29 -4
- package/lib/versions.js +131 -89
- package/package.json +30 -26
- package/src/categoryGeneratedIndex.ts +59 -0
- package/src/cli.ts +48 -62
- package/src/client/docsClientUtils.ts +36 -71
- package/src/{theme/hooks/useDocs.ts → client/index.ts} +15 -10
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/docFrontMatter.ts +17 -22
- package/src/docs.ts +229 -45
- package/src/globalData.ts +53 -2
- package/src/index.ts +168 -177
- package/src/lastUpdate.ts +14 -33
- package/src/markdown/index.ts +9 -13
- package/src/markdown/linkify.ts +2 -2
- package/src/numberPrefix.ts +11 -8
- package/src/options.ts +59 -29
- package/src/plugin-content-docs.d.ts +256 -40
- package/src/props.ts +105 -21
- package/src/routes.ts +185 -0
- package/src/server-export.ts +24 -0
- package/src/sidebars/README.md +9 -0
- package/src/sidebars/generator.ts +263 -0
- package/src/sidebars/index.ts +113 -0
- package/src/sidebars/normalization.ts +85 -0
- package/src/sidebars/postProcessor.ts +94 -0
- package/src/sidebars/processor.ts +126 -0
- package/src/sidebars/types.ts +273 -0
- package/src/sidebars/utils.ts +392 -0
- package/src/sidebars/validation.ts +173 -0
- package/src/slug.ts +40 -22
- package/src/tags.ts +19 -0
- package/src/translations.ts +121 -62
- package/src/types.ts +62 -183
- package/src/versions.ts +202 -107
- package/lib/.tsbuildinfo +0 -4717
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -42
- package/lib/sidebars.js +0 -309
- package/lib/theme/hooks/useDocs.js +0 -72
- 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 -67
- package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -52
- 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 -1907
- 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 -204
- package/src/__tests__/docs.test.ts +0 -875
- package/src/__tests__/index.test.ts +0 -1831
- package/src/__tests__/lastUpdate.test.ts +0 -68
- package/src/__tests__/numberPrefix.test.ts +0 -199
- package/src/__tests__/options.test.ts +0 -232
- package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
- package/src/__tests__/sidebars.test.ts +0 -638
- package/src/__tests__/slug.test.ts +0 -109
- package/src/__tests__/translations.test.ts +0 -159
- package/src/__tests__/versions.test.ts +0 -718
- package/src/client/__tests__/docsClientUtils.test.ts +0 -372
- 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 -489
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,12 @@
|
|
|
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 { CategoryGeneratedIndexMetadata, DocMetadataBase } from './types';
|
|
8
|
+
import { type SidebarsUtils } from './sidebars/utils';
|
|
9
|
+
export declare function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }: {
|
|
10
|
+
sidebarsUtils: SidebarsUtils;
|
|
11
|
+
docs: DocMetadataBase[];
|
|
12
|
+
}): CategoryGeneratedIndexMetadata[];
|
|
@@ -0,0 +1,39 @@
|
|
|
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.getCategoryGeneratedIndexMetadataList = void 0;
|
|
10
|
+
const utils_1 = require("./sidebars/utils");
|
|
11
|
+
const docs_1 = require("./docs");
|
|
12
|
+
function getCategoryGeneratedIndexMetadata({ category, sidebarsUtils, docsById, }) {
|
|
13
|
+
var _a;
|
|
14
|
+
const { sidebarName, previous, next } = sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
|
15
|
+
if (!sidebarName) {
|
|
16
|
+
throw new Error('unexpected');
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
title: (_a = category.link.title) !== null && _a !== void 0 ? _a : category.label,
|
|
20
|
+
description: category.link.description,
|
|
21
|
+
image: category.link.image,
|
|
22
|
+
keywords: category.link.keywords,
|
|
23
|
+
slug: category.link.slug,
|
|
24
|
+
permalink: category.link.permalink,
|
|
25
|
+
sidebar: sidebarName,
|
|
26
|
+
previous: (0, utils_1.toNavigationLink)(previous, docsById),
|
|
27
|
+
next: (0, utils_1.toNavigationLink)(next, docsById),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }) {
|
|
31
|
+
const docsById = (0, docs_1.createDocsByIdIndex)(docs);
|
|
32
|
+
const categoryGeneratedIndexItems = sidebarsUtils.getCategoryGeneratedIndexList();
|
|
33
|
+
return categoryGeneratedIndexItems.map((category) => getCategoryGeneratedIndexMetadata({
|
|
34
|
+
category,
|
|
35
|
+
sidebarsUtils,
|
|
36
|
+
docsById,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
exports.getCategoryGeneratedIndexMetadataList = getCategoryGeneratedIndexMetadataList;
|
package/lib/cli.d.ts
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
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 { PathOptions } from '
|
|
8
|
-
export declare function cliDocsVersionCommand(version: string | null | undefined, siteDir: string, pluginId: string, options: PathOptions): void
|
|
7
|
+
import type { PathOptions, SidebarOptions } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
export declare function cliDocsVersionCommand(version: string | null | undefined, siteDir: string, pluginId: string, options: PathOptions & SidebarOptions): Promise<void>;
|
package/lib/cli.js
CHANGED
|
@@ -9,94 +9,82 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.cliDocsVersionCommand = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const versions_1 = require("./versions");
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
14
|
const sidebars_1 = require("./sidebars");
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
17
|
+
async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, version, }) {
|
|
17
18
|
// Load current sidebar and create a new versioned sidebars file (if needed).
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
19
|
+
// Note: we don't need the sidebars file to be normalized: it's ok to let
|
|
20
|
+
// plugin option changes to impact older, versioned sidebars
|
|
21
|
+
// We don't validate here, assuming the user has already built the version
|
|
22
|
+
const sidebars = await (0, sidebars_1.loadSidebarsFileUnsafe)(sidebarPath);
|
|
23
|
+
// Do not create a useless versioned sidebars file if sidebars file is empty
|
|
24
|
+
// or sidebars are disabled/false)
|
|
25
|
+
const shouldCreateVersionedSidebarFile = Object.keys(sidebars).length > 0;
|
|
21
26
|
if (shouldCreateVersionedSidebarFile) {
|
|
22
|
-
|
|
23
|
-
// TODO try to get rid of it
|
|
24
|
-
// Transform id in original sidebar to versioned id.
|
|
25
|
-
const normalizeItem = (item) => {
|
|
26
|
-
switch (item.type) {
|
|
27
|
-
case 'category':
|
|
28
|
-
return { ...item, items: item.items.map(normalizeItem) };
|
|
29
|
-
case 'ref':
|
|
30
|
-
case 'doc':
|
|
31
|
-
return {
|
|
32
|
-
type: item.type,
|
|
33
|
-
id: `version-${version}/${item.id}`,
|
|
34
|
-
};
|
|
35
|
-
default:
|
|
36
|
-
return item;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const versionedSidebar = Object.entries(loadedSidebars).reduce((acc, [sidebarId, sidebarItems]) => {
|
|
40
|
-
const newVersionedSidebarId = `version-${version}/${sidebarId}`;
|
|
41
|
-
acc[newVersionedSidebarId] = sidebarItems.map(normalizeItem);
|
|
42
|
-
return acc;
|
|
43
|
-
}, {});
|
|
44
|
-
const versionedSidebarsDir = versions_1.getVersionedSidebarsDirPath(siteDir, pluginId);
|
|
27
|
+
const versionedSidebarsDir = (0, versions_1.getVersionedSidebarsDirPath)(siteDir, pluginId);
|
|
45
28
|
const newSidebarFile = path_1.default.join(versionedSidebarsDir, `version-${version}-sidebars.json`);
|
|
46
|
-
fs_extra_1.default.
|
|
47
|
-
fs_extra_1.default.
|
|
29
|
+
await fs_extra_1.default.ensureDir(path_1.default.dirname(newSidebarFile));
|
|
30
|
+
await fs_extra_1.default.writeFile(newSidebarFile, `${JSON.stringify(sidebars, null, 2)}\n`, 'utf8');
|
|
48
31
|
}
|
|
49
32
|
}
|
|
50
33
|
// Tests depend on non-default export for mocking.
|
|
51
|
-
|
|
52
|
-
function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
34
|
+
async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
53
35
|
// It wouldn't be very user-friendly to show a [default] log prefix,
|
|
54
36
|
// so we use [docs] instead of [default]
|
|
55
|
-
const pluginIdLogPrefix = pluginId ===
|
|
37
|
+
const pluginIdLogPrefix = pluginId === utils_1.DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;
|
|
56
38
|
if (!version) {
|
|
57
|
-
throw new Error(`${pluginIdLogPrefix}
|
|
39
|
+
throw new Error(`${pluginIdLogPrefix}: no version tag specified! Pass the version you wish to create as an argument, for example: 1.0.0.`);
|
|
58
40
|
}
|
|
59
41
|
if (version.includes('/') || version.includes('\\')) {
|
|
60
|
-
throw new Error(`${pluginIdLogPrefix}
|
|
42
|
+
throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Do not include slash (/) or backslash (\\). Try something like: 1.0.0.`);
|
|
61
43
|
}
|
|
62
44
|
if (version.length > 32) {
|
|
63
|
-
throw new Error(`${pluginIdLogPrefix}
|
|
45
|
+
throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Length cannot exceed 32 characters. Try something like: 1.0.0.`);
|
|
64
46
|
}
|
|
65
47
|
// Since we are going to create `version-${version}` folder, we need to make
|
|
66
48
|
// sure it's a valid pathname.
|
|
67
49
|
// eslint-disable-next-line no-control-regex
|
|
68
50
|
if (/[<>:"|?*\x00-\x1F]/g.test(version)) {
|
|
69
|
-
throw new Error(`${pluginIdLogPrefix}
|
|
51
|
+
throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`);
|
|
70
52
|
}
|
|
71
53
|
if (/^\.\.?$/.test(version)) {
|
|
72
|
-
throw new Error(`${pluginIdLogPrefix}
|
|
54
|
+
throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Do not name your version "." or "..". Try something like: 1.0.0.`);
|
|
73
55
|
}
|
|
74
56
|
// Load existing versions.
|
|
75
57
|
let versions = [];
|
|
76
|
-
const versionsJSONFile = versions_1.getVersionsFilePath(siteDir, pluginId);
|
|
77
|
-
if (fs_extra_1.default.
|
|
78
|
-
versions = JSON.parse(fs_extra_1.default.
|
|
58
|
+
const versionsJSONFile = (0, versions_1.getVersionsFilePath)(siteDir, pluginId);
|
|
59
|
+
if (await fs_extra_1.default.pathExists(versionsJSONFile)) {
|
|
60
|
+
versions = JSON.parse(await fs_extra_1.default.readFile(versionsJSONFile, 'utf8'));
|
|
79
61
|
}
|
|
80
62
|
// Check if version already exists.
|
|
81
63
|
if (versions.includes(version)) {
|
|
82
|
-
throw new Error(`${pluginIdLogPrefix}
|
|
64
|
+
throw new Error(`${pluginIdLogPrefix}: this version already exists! Use a version tag that does not already exist.`);
|
|
83
65
|
}
|
|
84
66
|
const { path: docsPath, sidebarPath } = options;
|
|
85
67
|
// Copy docs files.
|
|
86
68
|
const docsDir = path_1.default.join(siteDir, docsPath);
|
|
87
|
-
if (
|
|
88
|
-
|
|
69
|
+
if ((await fs_extra_1.default.pathExists(docsDir)) &&
|
|
70
|
+
(await fs_extra_1.default.readdir(docsDir)).length > 0) {
|
|
71
|
+
const versionedDir = (0, versions_1.getVersionedDocsDirPath)(siteDir, pluginId);
|
|
89
72
|
const newVersionDir = path_1.default.join(versionedDir, `version-${version}`);
|
|
90
|
-
fs_extra_1.default.
|
|
73
|
+
await fs_extra_1.default.copy(docsDir, newVersionDir);
|
|
91
74
|
}
|
|
92
75
|
else {
|
|
93
|
-
throw new Error(`${pluginIdLogPrefix}
|
|
76
|
+
throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
|
|
94
77
|
}
|
|
95
|
-
createVersionedSidebarFile({
|
|
78
|
+
await createVersionedSidebarFile({
|
|
79
|
+
siteDir,
|
|
80
|
+
pluginId,
|
|
81
|
+
version,
|
|
82
|
+
sidebarPath: (0, sidebars_1.resolveSidebarPathOption)(siteDir, sidebarPath),
|
|
83
|
+
});
|
|
96
84
|
// Update versions.json file.
|
|
97
85
|
versions.unshift(version);
|
|
98
|
-
fs_extra_1.default.
|
|
99
|
-
fs_extra_1.default.
|
|
100
|
-
|
|
86
|
+
await fs_extra_1.default.ensureDir(path_1.default.dirname(versionsJSONFile));
|
|
87
|
+
await fs_extra_1.default.writeFile(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
|
|
88
|
+
logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
|
|
101
89
|
}
|
|
102
90
|
exports.cliDocsVersionCommand = cliDocsVersionCommand;
|
|
@@ -4,31 +4,9 @@
|
|
|
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 { GlobalPluginData, GlobalVersion,
|
|
8
|
-
declare type Version = GlobalVersion;
|
|
9
|
-
declare type Doc = GlobalDoc;
|
|
10
|
-
export declare type ActivePlugin = {
|
|
11
|
-
pluginId: string;
|
|
12
|
-
pluginData: GlobalPluginData;
|
|
13
|
-
};
|
|
14
|
-
export declare type GetActivePluginOptions = {
|
|
15
|
-
failfast?: boolean;
|
|
16
|
-
};
|
|
17
|
-
export declare function getActivePlugin(allPluginDatas: Record<string, GlobalPluginData>, pathname: string, options: {
|
|
18
|
-
failfast: true;
|
|
19
|
-
}): ActivePlugin;
|
|
7
|
+
import type { GlobalPluginData, GlobalVersion, GetActivePluginOptions, ActivePlugin, ActiveDocContext, DocVersionSuggestions } from '@docusaurus/plugin-content-docs/client';
|
|
20
8
|
export declare function getActivePlugin(allPluginDatas: Record<string, GlobalPluginData>, pathname: string, options?: GetActivePluginOptions): ActivePlugin | undefined;
|
|
21
|
-
export declare
|
|
22
|
-
|
|
23
|
-
activeDoc?: Doc;
|
|
24
|
-
alternateDocVersions: Record<string, Doc>;
|
|
25
|
-
};
|
|
26
|
-
export declare const getLatestVersion: (data: GlobalPluginData) => Version;
|
|
27
|
-
export declare const getActiveVersion: (data: GlobalPluginData, pathname: string) => Version | undefined;
|
|
9
|
+
export declare const getLatestVersion: (data: GlobalPluginData) => GlobalVersion;
|
|
10
|
+
export declare const getActiveVersion: (data: GlobalPluginData, pathname: string) => GlobalVersion | undefined;
|
|
28
11
|
export declare const getActiveDocContext: (data: GlobalPluginData, pathname: string) => ActiveDocContext;
|
|
29
|
-
export declare type DocVersionSuggestions = {
|
|
30
|
-
latestDocSuggestion?: GlobalDoc;
|
|
31
|
-
latestVersionSuggestion?: GlobalVersion;
|
|
32
|
-
};
|
|
33
12
|
export declare const getDocVersionSuggestions: (data: GlobalPluginData, pathname: string) => DocVersionSuggestions;
|
|
34
|
-
export {};
|
|
@@ -8,51 +8,52 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getDocVersionSuggestions = exports.getActiveDocContext = exports.getActiveVersion = exports.getLatestVersion = exports.getActivePlugin = void 0;
|
|
10
10
|
const router_1 = require("@docusaurus/router");
|
|
11
|
+
// This code is not part of the api surface, not in ./theme on purpose
|
|
12
|
+
// get the data of the plugin that is currently "active"
|
|
13
|
+
// ie the docs of that plugin are currently browsed
|
|
14
|
+
// it is useful to support multiple docs plugin instances
|
|
11
15
|
function getActivePlugin(allPluginDatas, pathname, options = {}) {
|
|
12
|
-
const activeEntry = Object.entries(allPluginDatas)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const activeEntry = Object.entries(allPluginDatas)
|
|
17
|
+
// Route sorting: '/android/foo' should match '/android' instead of '/'
|
|
18
|
+
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
|
19
|
+
.find(([, pluginData]) => !!(0, router_1.matchPath)(pathname, {
|
|
20
|
+
path: pluginData.path,
|
|
21
|
+
exact: false,
|
|
22
|
+
strict: false,
|
|
23
|
+
}));
|
|
19
24
|
const activePlugin = activeEntry
|
|
20
25
|
? { pluginId: activeEntry[0], pluginData: activeEntry[1] }
|
|
21
26
|
: undefined;
|
|
22
27
|
if (!activePlugin && options.failfast) {
|
|
23
|
-
throw new Error(`Can't find active docs plugin for
|
|
28
|
+
throw new Error(`Can't find active docs plugin for "${pathname}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(allPluginDatas)
|
|
24
29
|
.map((plugin) => plugin.path)
|
|
25
30
|
.join(', ')}`);
|
|
26
31
|
}
|
|
27
32
|
return activePlugin;
|
|
28
33
|
}
|
|
29
34
|
exports.getActivePlugin = getActivePlugin;
|
|
30
|
-
const getLatestVersion = (data) =>
|
|
31
|
-
return data.versions.find((version) => version.isLast);
|
|
32
|
-
};
|
|
35
|
+
const getLatestVersion = (data) => data.versions.find((version) => version.isLast);
|
|
33
36
|
exports.getLatestVersion = getLatestVersion;
|
|
34
37
|
// Note: return undefined on doc-unrelated pages,
|
|
35
38
|
// because there's no version currently considered as active
|
|
36
39
|
const getActiveVersion = (data, pathname) => {
|
|
37
|
-
const lastVersion = exports.getLatestVersion(data);
|
|
40
|
+
const lastVersion = (0, exports.getLatestVersion)(data);
|
|
38
41
|
// Last version is a route like /docs/*,
|
|
39
|
-
// we need to
|
|
42
|
+
// we need to match it last or it would match /docs/version-1.0/* as well
|
|
40
43
|
const orderedVersionsMetadata = [
|
|
41
44
|
...data.versions.filter((version) => version !== lastVersion),
|
|
42
45
|
lastVersion,
|
|
43
46
|
];
|
|
44
|
-
return orderedVersionsMetadata.find((version) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
});
|
|
47
|
+
return orderedVersionsMetadata.find((version) => !!(0, router_1.matchPath)(pathname, {
|
|
48
|
+
path: version.path,
|
|
49
|
+
exact: false,
|
|
50
|
+
strict: false,
|
|
51
|
+
}));
|
|
51
52
|
};
|
|
52
53
|
exports.getActiveVersion = getActiveVersion;
|
|
53
54
|
const getActiveDocContext = (data, pathname) => {
|
|
54
|
-
const activeVersion = exports.getActiveVersion(data, pathname);
|
|
55
|
-
const activeDoc = activeVersion === null || activeVersion === void 0 ? void 0 : activeVersion.docs.find((doc) => !!router_1.matchPath(pathname, {
|
|
55
|
+
const activeVersion = (0, exports.getActiveVersion)(data, pathname);
|
|
56
|
+
const activeDoc = activeVersion === null || activeVersion === void 0 ? void 0 : activeVersion.docs.find((doc) => !!(0, router_1.matchPath)(pathname, {
|
|
56
57
|
path: doc.path,
|
|
57
58
|
exact: true,
|
|
58
59
|
strict: false,
|
|
@@ -79,16 +80,9 @@ const getActiveDocContext = (data, pathname) => {
|
|
|
79
80
|
};
|
|
80
81
|
exports.getActiveDocContext = getActiveDocContext;
|
|
81
82
|
const getDocVersionSuggestions = (data, pathname) => {
|
|
82
|
-
const latestVersion = exports.getLatestVersion(data);
|
|
83
|
-
const activeDocContext = exports.getActiveDocContext(data, pathname);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const latestDocSuggestion = isNotOnLatestVersion
|
|
87
|
-
? activeDocContext === null || activeDocContext === void 0 ? void 0 : activeDocContext.alternateDocVersions[latestVersion.name]
|
|
88
|
-
: undefined;
|
|
89
|
-
const latestVersionSuggestion = isNotOnLatestVersion
|
|
90
|
-
? latestVersion
|
|
91
|
-
: undefined;
|
|
92
|
-
return { latestDocSuggestion, latestVersionSuggestion };
|
|
83
|
+
const latestVersion = (0, exports.getLatestVersion)(data);
|
|
84
|
+
const activeDocContext = (0, exports.getActiveDocContext)(data, pathname);
|
|
85
|
+
const latestDocSuggestion = activeDocContext === null || activeDocContext === void 0 ? void 0 : activeDocContext.alternateDocVersions[latestVersion.name];
|
|
86
|
+
return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
|
|
93
87
|
};
|
|
94
88
|
exports.getDocVersionSuggestions = getDocVersionSuggestions;
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { GlobalPluginData, GlobalVersion } from '
|
|
8
|
-
import { ActivePlugin, ActiveDocContext, DocVersionSuggestions, GetActivePluginOptions } from '../../client/docsClientUtils';
|
|
7
|
+
import type { GlobalPluginData, GlobalVersion, ActivePlugin, ActiveDocContext, DocVersionSuggestions, GetActivePluginOptions } from '@docusaurus/plugin-content-docs/client';
|
|
9
8
|
export declare const useAllDocsData: () => Record<string, GlobalPluginData>;
|
|
10
9
|
export declare const useDocsData: (pluginId: string | undefined) => GlobalPluginData;
|
|
11
10
|
export declare const useActivePlugin: (options?: GetActivePluginOptions) => ActivePlugin | undefined;
|
|
@@ -0,0 +1,75 @@
|
|
|
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.useDocVersionSuggestions = exports.useActiveDocContext = exports.useActiveVersion = exports.useLatestVersion = exports.useVersions = exports.useActivePluginAndVersion = exports.useActivePlugin = exports.useDocsData = exports.useAllDocsData = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const router_1 = require("@docusaurus/router");
|
|
12
|
+
const useGlobalData_1 = (0, tslib_1.__importStar)(require("@docusaurus/useGlobalData"));
|
|
13
|
+
const docsClientUtils_1 = require("./docsClientUtils");
|
|
14
|
+
// Important to use a constant object to avoid React useEffect executions etc.
|
|
15
|
+
// see https://github.com/facebook/docusaurus/issues/5089
|
|
16
|
+
const StableEmptyObject = {};
|
|
17
|
+
// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks
|
|
18
|
+
// are still used by the theme. We need a fail-safe fallback when the docs
|
|
19
|
+
// plugin is not in use
|
|
20
|
+
const useAllDocsData = () => { var _a; return (_a = (0, useGlobalData_1.default)()['docusaurus-plugin-content-docs']) !== null && _a !== void 0 ? _a : StableEmptyObject; };
|
|
21
|
+
exports.useAllDocsData = useAllDocsData;
|
|
22
|
+
const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId);
|
|
23
|
+
exports.useDocsData = useDocsData;
|
|
24
|
+
// TODO this feature should be provided by docusaurus core
|
|
25
|
+
const useActivePlugin = (options = {}) => {
|
|
26
|
+
const data = (0, exports.useAllDocsData)();
|
|
27
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
28
|
+
return (0, docsClientUtils_1.getActivePlugin)(data, pathname, options);
|
|
29
|
+
};
|
|
30
|
+
exports.useActivePlugin = useActivePlugin;
|
|
31
|
+
const useActivePluginAndVersion = (options = {}) => {
|
|
32
|
+
const activePlugin = (0, exports.useActivePlugin)(options);
|
|
33
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
34
|
+
if (activePlugin) {
|
|
35
|
+
const activeVersion = (0, docsClientUtils_1.getActiveVersion)(activePlugin.pluginData, pathname);
|
|
36
|
+
return {
|
|
37
|
+
activePlugin,
|
|
38
|
+
activeVersion,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
};
|
|
43
|
+
exports.useActivePluginAndVersion = useActivePluginAndVersion;
|
|
44
|
+
// versions are returned ordered (most recent first)
|
|
45
|
+
const useVersions = (pluginId) => {
|
|
46
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
47
|
+
return data.versions;
|
|
48
|
+
};
|
|
49
|
+
exports.useVersions = useVersions;
|
|
50
|
+
const useLatestVersion = (pluginId) => {
|
|
51
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
52
|
+
return (0, docsClientUtils_1.getLatestVersion)(data);
|
|
53
|
+
};
|
|
54
|
+
exports.useLatestVersion = useLatestVersion;
|
|
55
|
+
// Note: return undefined on doc-unrelated pages,
|
|
56
|
+
// because there's no version currently considered as active
|
|
57
|
+
const useActiveVersion = (pluginId) => {
|
|
58
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
59
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
60
|
+
return (0, docsClientUtils_1.getActiveVersion)(data, pathname);
|
|
61
|
+
};
|
|
62
|
+
exports.useActiveVersion = useActiveVersion;
|
|
63
|
+
const useActiveDocContext = (pluginId) => {
|
|
64
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
65
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
66
|
+
return (0, docsClientUtils_1.getActiveDocContext)(data, pathname);
|
|
67
|
+
};
|
|
68
|
+
exports.useActiveDocContext = useActiveDocContext;
|
|
69
|
+
// Useful to say "hey, you are not on the latest docs version, please switch"
|
|
70
|
+
const useDocVersionSuggestions = (pluginId) => {
|
|
71
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
72
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
73
|
+
return (0, docsClientUtils_1.getDocVersionSuggestions)(data, pathname);
|
|
74
|
+
};
|
|
75
|
+
exports.useDocVersionSuggestions = useDocVersionSuggestions;
|
package/lib/docFrontMatter.d.ts
CHANGED
|
@@ -4,18 +4,5 @@
|
|
|
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
|
-
|
|
8
|
-
id?: string;
|
|
9
|
-
title?: string;
|
|
10
|
-
hide_title?: boolean;
|
|
11
|
-
hide_table_of_contents?: boolean;
|
|
12
|
-
keywords?: string[];
|
|
13
|
-
image?: string;
|
|
14
|
-
description?: string;
|
|
15
|
-
slug?: string;
|
|
16
|
-
sidebar_label?: string;
|
|
17
|
-
sidebar_position?: number;
|
|
18
|
-
custom_edit_url?: string | null;
|
|
19
|
-
parse_number_prefixes?: boolean;
|
|
20
|
-
};
|
|
7
|
+
import type { DocFrontMatter } from './types';
|
|
21
8
|
export declare function validateDocFrontMatter(frontMatter: Record<string, unknown>): DocFrontMatter;
|
package/lib/docFrontMatter.js
CHANGED
|
@@ -7,10 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateDocFrontMatter = void 0;
|
|
10
|
-
/* eslint-disable camelcase */
|
|
11
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
11
|
// NOTE: we don't add any default value on purpose here
|
|
13
|
-
// We don't want default values to magically appear in doc
|
|
12
|
+
// We don't want default values to magically appear in doc metadata and props
|
|
14
13
|
// While the user did not provide those values explicitly
|
|
15
14
|
// We use default values in code instead
|
|
16
15
|
const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
@@ -19,15 +18,23 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
19
18
|
hide_title: utils_validation_1.JoiFrontMatter.boolean(),
|
|
20
19
|
hide_table_of_contents: utils_validation_1.JoiFrontMatter.boolean(),
|
|
21
20
|
keywords: utils_validation_1.JoiFrontMatter.array().items(utils_validation_1.JoiFrontMatter.string().required()),
|
|
22
|
-
image: utils_validation_1.
|
|
21
|
+
image: utils_validation_1.URISchema,
|
|
23
22
|
description: utils_validation_1.JoiFrontMatter.string().allow(''),
|
|
24
23
|
slug: utils_validation_1.JoiFrontMatter.string(),
|
|
25
24
|
sidebar_label: utils_validation_1.JoiFrontMatter.string(),
|
|
26
|
-
sidebar_position: utils_validation_1.JoiFrontMatter.number()
|
|
27
|
-
|
|
25
|
+
sidebar_position: utils_validation_1.JoiFrontMatter.number(),
|
|
26
|
+
sidebar_class_name: utils_validation_1.JoiFrontMatter.string(),
|
|
27
|
+
sidebar_custom_props: utils_validation_1.JoiFrontMatter.object().unknown(),
|
|
28
|
+
displayed_sidebar: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
29
|
+
tags: utils_validation_1.FrontMatterTagsSchema,
|
|
30
|
+
pagination_label: utils_validation_1.JoiFrontMatter.string(),
|
|
31
|
+
custom_edit_url: utils_validation_1.URISchema.allow('', null),
|
|
28
32
|
parse_number_prefixes: utils_validation_1.JoiFrontMatter.boolean(),
|
|
33
|
+
pagination_next: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
34
|
+
pagination_prev: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
35
|
+
...utils_validation_1.FrontMatterTOCHeadingLevels,
|
|
29
36
|
}).unknown();
|
|
30
37
|
function validateDocFrontMatter(frontMatter) {
|
|
31
|
-
return utils_validation_1.validateFrontMatter(frontMatter, DocFrontMatterSchema);
|
|
38
|
+
return (0, utils_validation_1.validateFrontMatter)(frontMatter, DocFrontMatterSchema);
|
|
32
39
|
}
|
|
33
40
|
exports.validateDocFrontMatter = validateDocFrontMatter;
|
package/lib/docs.d.ts
CHANGED
|
@@ -4,15 +4,51 @@
|
|
|
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 { LoadContext } from '@docusaurus/types';
|
|
8
|
-
import { DocFile, DocMetadataBase,
|
|
7
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
8
|
+
import type { DocFile, DocMetadataBase, VersionMetadata, LoadedVersion } from './types';
|
|
9
|
+
import type { SidebarsUtils } from './sidebars/utils';
|
|
10
|
+
import type { MetadataOptions, PluginOptions, CategoryIndexMatcher, CategoryIndexMatcherParam } from '@docusaurus/plugin-content-docs';
|
|
9
11
|
declare type LastUpdateOptions = Pick<PluginOptions, 'showLastUpdateAuthor' | 'showLastUpdateTime'>;
|
|
10
12
|
export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string, options: LastUpdateOptions): Promise<DocFile>;
|
|
11
|
-
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
|
12
|
-
export declare function processDocMetadata(
|
|
13
|
+
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
|
14
|
+
export declare function processDocMetadata(args: {
|
|
13
15
|
docFile: DocFile;
|
|
14
16
|
versionMetadata: VersionMetadata;
|
|
15
17
|
context: LoadContext;
|
|
16
18
|
options: MetadataOptions;
|
|
17
19
|
}): DocMetadataBase;
|
|
20
|
+
export declare function addDocNavigation(docsBase: DocMetadataBase[], sidebarsUtils: SidebarsUtils, sidebarFilePath: string): LoadedVersion['docs'];
|
|
21
|
+
/**
|
|
22
|
+
* The "main doc" is the "version entry point"
|
|
23
|
+
* We browse this doc by clicking on a version:
|
|
24
|
+
* - the "home" doc (at '/docs/')
|
|
25
|
+
* - the first doc of the first sidebar
|
|
26
|
+
* - a random doc (if no docs are in any sidebar... edge case)
|
|
27
|
+
*/
|
|
28
|
+
export declare function getMainDocId({ docs, sidebarsUtils, }: {
|
|
29
|
+
docs: DocMetadataBase[];
|
|
30
|
+
sidebarsUtils: SidebarsUtils;
|
|
31
|
+
}): string;
|
|
32
|
+
export declare const isCategoryIndex: CategoryIndexMatcher;
|
|
33
|
+
export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): CategoryIndexMatcherParam;
|
|
34
|
+
/**
|
|
35
|
+
* `guides/sidebar/autogenerated.md` ->
|
|
36
|
+
* `'autogenerated', '.md', ['sidebar', 'guides']`
|
|
37
|
+
*/
|
|
38
|
+
export declare function splitPath(str: string): {
|
|
39
|
+
/**
|
|
40
|
+
* The list of directories, from lowest level to highest.
|
|
41
|
+
* If there's no dir name, directories is ['.']
|
|
42
|
+
*/
|
|
43
|
+
directories: string[];
|
|
44
|
+
/** The file name, without extension */
|
|
45
|
+
fileName: string;
|
|
46
|
+
/** The extension, with a leading dot */
|
|
47
|
+
extension: string;
|
|
48
|
+
};
|
|
49
|
+
export declare function getDocIds(doc: DocMetadataBase): [string, string];
|
|
50
|
+
export declare function createDocsByIdIndex<Doc extends {
|
|
51
|
+
id: string;
|
|
52
|
+
unversionedId: string;
|
|
53
|
+
}>(docs: Doc[]): Record<string, Doc>;
|
|
18
54
|
export {};
|