@docusaurus/plugin-content-docs 2.0.0-beta.fbdeefcac → 2.0.0-rc.1
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 +57 -72
- package/lib/client/docsClientUtils.d.ts +9 -28
- package/lib/client/docsClientUtils.js +34 -43
- package/lib/client/index.d.ts +81 -0
- package/lib/client/index.js +67 -0
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +34 -7
- package/lib/docs.js +202 -79
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js → lib/frontMatter.d.ts} +4 -8
- package/lib/{docFrontMatter.js → frontMatter.js} +22 -3
- package/lib/globalData.d.ts +3 -3
- package/lib/globalData.js +35 -6
- package/lib/index.d.ts +3 -3
- package/lib/index.js +124 -154
- 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 +56 -23
- package/lib/props.d.ts +7 -2
- package/lib/props.js +84 -14
- 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 +25 -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 +59 -0
- package/lib/sidebars/postProcessor.d.ts +11 -0
- package/lib/sidebars/postProcessor.js +81 -0
- package/lib/sidebars/processor.d.ts +10 -0
- package/lib/sidebars/processor.js +79 -0
- package/lib/sidebars/types.d.ts +183 -0
- package/lib/{docFrontMatter.d.ts → sidebars/types.js} +2 -2
- package/lib/sidebars/utils.d.ts +55 -0
- package/lib/sidebars/utils.js +259 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +143 -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 +100 -93
- package/lib/types.d.ts +13 -185
- package/lib/versions/files.d.ts +50 -0
- package/lib/versions/files.js +141 -0
- package/lib/versions/index.d.ts +36 -0
- package/lib/versions/index.js +154 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +71 -0
- package/package.json +44 -30
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +88 -114
- package/src/client/docsClientUtils.ts +44 -71
- package/src/client/index.ts +158 -0
- package/src/constants.ts +4 -2
- package/src/docs.ts +281 -83
- package/src/frontMatter.ts +63 -0
- package/src/globalData.ts +57 -7
- package/src/index.ts +183 -224
- package/src/lastUpdate.ts +27 -38
- package/src/markdown/index.ts +10 -16
- package/src/markdown/linkify.ts +7 -4
- package/src/numberPrefix.ts +19 -26
- package/src/options.ts +61 -29
- package/src/plugin-content-docs.d.ts +569 -93
- package/src/props.ts +121 -21
- package/src/routes.ts +159 -0
- package/src/server-export.ts +26 -0
- package/src/sidebars/README.md +10 -0
- package/src/sidebars/generator.ts +292 -0
- package/src/sidebars/index.ts +118 -0
- package/src/sidebars/normalization.ts +91 -0
- package/src/sidebars/postProcessor.ts +112 -0
- package/src/sidebars/processor.ts +123 -0
- package/src/sidebars/types.ts +280 -0
- package/src/sidebars/utils.ts +393 -0
- package/src/sidebars/validation.ts +179 -0
- package/src/slug.ts +41 -22
- package/src/tags.ts +20 -0
- package/src/translations.ts +155 -124
- package/src/types.ts +17 -250
- package/src/versions/files.ts +216 -0
- package/src/versions/index.ts +246 -0
- package/src/versions/validation.ts +115 -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 -75
- 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/docFrontMatter.ts +0 -41
- 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 -103
- package/src/versions.ts +0 -572
- package/tsconfig.json +0 -9
- package/types.d.ts +0 -13
|
@@ -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 SidebarsUtils } from './sidebars/utils';
|
|
8
|
+
import type { CategoryGeneratedIndexMetadata, DocMetadataBase } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
export declare function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }: {
|
|
10
|
+
sidebarsUtils: SidebarsUtils;
|
|
11
|
+
docs: DocMetadataBase[];
|
|
12
|
+
}): CategoryGeneratedIndexMetadata[];
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
const { sidebarName, previous, next } = sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
|
14
|
+
return {
|
|
15
|
+
title: category.link.title ?? category.label,
|
|
16
|
+
description: category.link.description,
|
|
17
|
+
image: category.link.image,
|
|
18
|
+
keywords: category.link.keywords,
|
|
19
|
+
slug: category.link.slug,
|
|
20
|
+
permalink: category.link.permalink,
|
|
21
|
+
sidebar: sidebarName,
|
|
22
|
+
navigation: {
|
|
23
|
+
previous: (0, utils_1.toNavigationLink)(previous, docsById),
|
|
24
|
+
next: (0, utils_1.toNavigationLink)(next, docsById),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }) {
|
|
29
|
+
const docsById = (0, docs_1.createDocsByIdIndex)(docs);
|
|
30
|
+
const categoryGeneratedIndexItems = sidebarsUtils.getCategoryGeneratedIndexList();
|
|
31
|
+
return categoryGeneratedIndexItems.map((category) => getCategoryGeneratedIndexMetadata({
|
|
32
|
+
category,
|
|
33
|
+
sidebarsUtils,
|
|
34
|
+
docsById,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
exports.getCategoryGeneratedIndexMetadataList = getCategoryGeneratedIndexMetadataList;
|
package/lib/cli.d.ts
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
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 {
|
|
8
|
-
|
|
7
|
+
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
9
|
+
export declare function cliDocsVersionCommand(version: unknown, { id: pluginId, path: docsPath, sidebarPath }: PluginOptions, { siteDir, i18n }: LoadContext): Promise<void>;
|
package/lib/cli.js
CHANGED
|
@@ -8,100 +8,85 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.cliDocsVersionCommand = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const versions_1 = require("./versions");
|
|
12
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
const files_1 = require("./versions/files");
|
|
16
|
+
const validation_1 = require("./versions/validation");
|
|
14
17
|
const sidebars_1 = require("./sidebars");
|
|
15
|
-
const constants_1 = require("
|
|
16
|
-
function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, version, }) {
|
|
18
|
+
const constants_1 = require("./constants");
|
|
19
|
+
async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, version, }) {
|
|
17
20
|
// Load current sidebar and create a new versioned sidebars file (if needed).
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
+
// Note: we don't need the sidebars file to be normalized: it's ok to let
|
|
22
|
+
// plugin option changes to impact older, versioned sidebars
|
|
23
|
+
// We don't validate here, assuming the user has already built the version
|
|
24
|
+
const sidebars = await (0, sidebars_1.loadSidebarsFileUnsafe)(sidebarPath);
|
|
25
|
+
// Do not create a useless versioned sidebars file if sidebars file is empty
|
|
26
|
+
// or sidebars are disabled/false)
|
|
27
|
+
const shouldCreateVersionedSidebarFile = Object.keys(sidebars).length > 0;
|
|
21
28
|
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);
|
|
45
|
-
const newSidebarFile = path_1.default.join(versionedSidebarsDir, `version-${version}-sidebars.json`);
|
|
46
|
-
fs_extra_1.default.ensureDirSync(path_1.default.dirname(newSidebarFile));
|
|
47
|
-
fs_extra_1.default.writeFileSync(newSidebarFile, `${JSON.stringify(versionedSidebar, null, 2)}\n`, 'utf8');
|
|
29
|
+
await fs_extra_1.default.outputFile((0, files_1.getVersionSidebarsPath)(siteDir, pluginId, version), `${JSON.stringify(sidebars, null, 2)}\n`, 'utf8');
|
|
48
30
|
}
|
|
49
31
|
}
|
|
50
32
|
// Tests depend on non-default export for mocking.
|
|
51
|
-
|
|
52
|
-
function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
33
|
+
async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, sidebarPath }, { siteDir, i18n }) {
|
|
53
34
|
// It wouldn't be very user-friendly to show a [default] log prefix,
|
|
54
35
|
// so we use [docs] instead of [default]
|
|
55
|
-
const pluginIdLogPrefix = pluginId ===
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
if (version.includes('/') || version.includes('\\')) {
|
|
60
|
-
throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Do not include slash (/) or backslash (\\). Try something like: 1.0.0.`);
|
|
61
|
-
}
|
|
62
|
-
if (version.length > 32) {
|
|
63
|
-
throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Length cannot exceed 32 characters. Try something like: 1.0.0.`);
|
|
64
|
-
}
|
|
65
|
-
// Since we are going to create `version-${version}` folder, we need to make
|
|
66
|
-
// sure it's a valid pathname.
|
|
67
|
-
// eslint-disable-next-line no-control-regex
|
|
68
|
-
if (/[<>:"|?*\x00-\x1F]/g.test(version)) {
|
|
69
|
-
throw new Error(`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`);
|
|
36
|
+
const pluginIdLogPrefix = pluginId === utils_1.DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;
|
|
37
|
+
try {
|
|
38
|
+
(0, validation_1.validateVersionName)(version);
|
|
70
39
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// Load existing versions.
|
|
75
|
-
let versions = [];
|
|
76
|
-
const versionsJSONFile = versions_1.getVersionsFilePath(siteDir, pluginId);
|
|
77
|
-
if (fs_extra_1.default.existsSync(versionsJSONFile)) {
|
|
78
|
-
versions = JSON.parse(fs_extra_1.default.readFileSync(versionsJSONFile, 'utf8'));
|
|
40
|
+
catch (err) {
|
|
41
|
+
logger_1.default.info `${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
|
|
42
|
+
throw err;
|
|
79
43
|
}
|
|
44
|
+
const versions = (await (0, files_1.readVersionsFile)(siteDir, pluginId)) ?? [];
|
|
80
45
|
// Check if version already exists.
|
|
81
46
|
if (versions.includes(version)) {
|
|
82
47
|
throw new Error(`${pluginIdLogPrefix}: this version already exists! Use a version tag that does not already exist.`);
|
|
83
48
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const docsDir = path_1.default.join(siteDir, docsPath);
|
|
87
|
-
if (fs_extra_1.default.existsSync(docsDir) && fs_extra_1.default.readdirSync(docsDir).length > 0) {
|
|
88
|
-
const versionedDir = versions_1.getVersionedDocsDirPath(siteDir, pluginId);
|
|
89
|
-
const newVersionDir = path_1.default.join(versionedDir, `version-${version}`);
|
|
90
|
-
fs_extra_1.default.copySync(docsDir, newVersionDir);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
|
|
49
|
+
if (i18n.locales.length > 1) {
|
|
50
|
+
logger_1.default.info `Versioned docs will be created for the following locales: name=${i18n.locales}`;
|
|
94
51
|
}
|
|
95
|
-
|
|
52
|
+
await Promise.all(i18n.locales.map(async (locale) => {
|
|
53
|
+
const localizationDir = path_1.default.resolve(siteDir, i18n.path, i18n.localeConfigs[locale].path);
|
|
54
|
+
// Copy docs files.
|
|
55
|
+
const docsDir = locale === i18n.defaultLocale
|
|
56
|
+
? path_1.default.resolve(siteDir, docsPath)
|
|
57
|
+
: (0, files_1.getDocsDirPathLocalized)({
|
|
58
|
+
localizationDir,
|
|
59
|
+
pluginId,
|
|
60
|
+
versionName: constants_1.CURRENT_VERSION_NAME,
|
|
61
|
+
});
|
|
62
|
+
if (!(await fs_extra_1.default.pathExists(docsDir)) ||
|
|
63
|
+
(await fs_extra_1.default.readdir(docsDir)).length === 0) {
|
|
64
|
+
if (locale === i18n.defaultLocale) {
|
|
65
|
+
throw new Error(logger_1.default.interpolate `${pluginIdLogPrefix}: no docs found in path=${docsDir}.`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
logger_1.default.warn `${pluginIdLogPrefix}: no docs found in path=${docsDir}. Skipping.`;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const newVersionDir = locale === i18n.defaultLocale
|
|
73
|
+
? (0, files_1.getVersionDocsDirPath)(siteDir, pluginId, version)
|
|
74
|
+
: (0, files_1.getDocsDirPathLocalized)({
|
|
75
|
+
localizationDir,
|
|
76
|
+
pluginId,
|
|
77
|
+
versionName: version,
|
|
78
|
+
});
|
|
79
|
+
await fs_extra_1.default.copy(docsDir, newVersionDir);
|
|
80
|
+
}));
|
|
81
|
+
await createVersionedSidebarFile({
|
|
96
82
|
siteDir,
|
|
97
83
|
pluginId,
|
|
98
84
|
version,
|
|
99
|
-
sidebarPath
|
|
85
|
+
sidebarPath,
|
|
100
86
|
});
|
|
101
87
|
// Update versions.json file.
|
|
102
88
|
versions.unshift(version);
|
|
103
|
-
fs_extra_1.default.
|
|
104
|
-
|
|
105
|
-
console.log(`${pluginIdLogPrefix}: version ${version} created!`);
|
|
89
|
+
await fs_extra_1.default.outputFile((0, files_1.getVersionsFilePath)(siteDir, pluginId), `${JSON.stringify(versions, null, 2)}\n`);
|
|
90
|
+
logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
|
|
106
91
|
}
|
|
107
92
|
exports.cliDocsVersionCommand = cliDocsVersionCommand;
|
|
@@ -4,31 +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 { GlobalPluginData, GlobalVersion,
|
|
8
|
-
|
|
9
|
-
declare
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export declare
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
export declare function getActivePlugin(allPluginDatas: Record<string, GlobalPluginData>, pathname: string, options: {
|
|
18
|
-
failfast: true;
|
|
19
|
-
}): ActivePlugin;
|
|
20
|
-
export declare function getActivePlugin(allPluginDatas: Record<string, GlobalPluginData>, pathname: string, options?: GetActivePluginOptions): ActivePlugin | undefined;
|
|
21
|
-
export declare type ActiveDocContext = {
|
|
22
|
-
activeVersion?: Version;
|
|
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;
|
|
28
|
-
export declare const getActiveDocContext: (data: GlobalPluginData, pathname: string) => ActiveDocContext;
|
|
29
|
-
export declare type DocVersionSuggestions = {
|
|
30
|
-
latestVersionSuggestion: GlobalVersion;
|
|
31
|
-
latestDocSuggestion?: GlobalDoc;
|
|
32
|
-
};
|
|
33
|
-
export declare const getDocVersionSuggestions: (data: GlobalPluginData, pathname: string) => DocVersionSuggestions;
|
|
34
|
-
export {};
|
|
7
|
+
import type { GlobalPluginData, GlobalVersion, ActivePlugin, ActiveDocContext, DocVersionSuggestions } from '@docusaurus/plugin-content-docs/client';
|
|
8
|
+
import type { UseDataOptions } from '@docusaurus/types';
|
|
9
|
+
export declare function getActivePlugin(allPluginData: {
|
|
10
|
+
[pluginId: string]: GlobalPluginData;
|
|
11
|
+
}, pathname: string, options?: UseDataOptions): ActivePlugin | undefined;
|
|
12
|
+
export declare const getLatestVersion: (data: GlobalPluginData) => GlobalVersion;
|
|
13
|
+
export declare function getActiveVersion(data: GlobalPluginData, pathname: string): GlobalVersion | undefined;
|
|
14
|
+
export declare function getActiveDocContext(data: GlobalPluginData, pathname: string): ActiveDocContext;
|
|
15
|
+
export declare function getDocVersionSuggestions(data: GlobalPluginData, pathname: string): DocVersionSuggestions;
|
|
@@ -1,58 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
3
|
*
|
|
5
4
|
* This source code is licensed under the MIT license found in the
|
|
6
5
|
* LICENSE file in the root directory of this source tree.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
import { matchPath } from '@docusaurus/router';
|
|
8
|
+
// This code is not part of the api surface, not in ./theme on purpose
|
|
9
|
+
// get the data of the plugin that is currently "active"
|
|
10
|
+
// ie the docs of that plugin are currently browsed
|
|
11
|
+
// it is useful to support multiple docs plugin instances
|
|
12
|
+
export function getActivePlugin(allPluginData, pathname, options = {}) {
|
|
13
|
+
const activeEntry = Object.entries(allPluginData)
|
|
14
|
+
// Route sorting: '/android/foo' should match '/android' instead of '/'
|
|
15
|
+
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
|
16
|
+
.find(([, pluginData]) => !!matchPath(pathname, {
|
|
17
|
+
path: pluginData.path,
|
|
18
|
+
exact: false,
|
|
19
|
+
strict: false,
|
|
20
|
+
}));
|
|
19
21
|
const activePlugin = activeEntry
|
|
20
22
|
? { pluginId: activeEntry[0], pluginData: activeEntry[1] }
|
|
21
23
|
: undefined;
|
|
22
24
|
if (!activePlugin && options.failfast) {
|
|
23
|
-
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(
|
|
25
|
+
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(allPluginData)
|
|
24
26
|
.map((plugin) => plugin.path)
|
|
25
27
|
.join(', ')}`);
|
|
26
28
|
}
|
|
27
29
|
return activePlugin;
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
33
|
-
exports.getLatestVersion = getLatestVersion;
|
|
34
|
-
// Note: return undefined on doc-unrelated pages,
|
|
35
|
-
// because there's no version currently considered as active
|
|
36
|
-
const getActiveVersion = (data, pathname) => {
|
|
37
|
-
const lastVersion = exports.getLatestVersion(data);
|
|
31
|
+
export const getLatestVersion = (data) => data.versions.find((version) => version.isLast);
|
|
32
|
+
export function getActiveVersion(data, pathname) {
|
|
33
|
+
const lastVersion = getLatestVersion(data);
|
|
38
34
|
// Last version is a route like /docs/*,
|
|
39
|
-
// we need to
|
|
35
|
+
// we need to match it last or it would match /docs/version-1.0/* as well
|
|
40
36
|
const orderedVersionsMetadata = [
|
|
41
37
|
...data.versions.filter((version) => version !== lastVersion),
|
|
42
38
|
lastVersion,
|
|
43
39
|
];
|
|
44
|
-
return orderedVersionsMetadata.find((version) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
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, {
|
|
40
|
+
return orderedVersionsMetadata.find((version) => !!matchPath(pathname, {
|
|
41
|
+
path: version.path,
|
|
42
|
+
exact: false,
|
|
43
|
+
strict: false,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
export function getActiveDocContext(data, pathname) {
|
|
47
|
+
const activeVersion = getActiveVersion(data, pathname);
|
|
48
|
+
const activeDoc = activeVersion?.docs.find((doc) => !!matchPath(pathname, {
|
|
56
49
|
path: doc.path,
|
|
57
50
|
exact: true,
|
|
58
51
|
strict: false,
|
|
@@ -76,12 +69,10 @@ const getActiveDocContext = (data, pathname) => {
|
|
|
76
69
|
activeDoc,
|
|
77
70
|
alternateDocVersions: alternateVersionDocs,
|
|
78
71
|
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const latestDocSuggestion = activeDocContext === null || activeDocContext === void 0 ? void 0 : activeDocContext.alternateDocVersions[latestVersion.name];
|
|
72
|
+
}
|
|
73
|
+
export function getDocVersionSuggestions(data, pathname) {
|
|
74
|
+
const latestVersion = getLatestVersion(data);
|
|
75
|
+
const activeDocContext = getActiveDocContext(data, pathname);
|
|
76
|
+
const latestDocSuggestion = activeDocContext.alternateDocVersions[latestVersion.name];
|
|
85
77
|
return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
|
|
86
|
-
}
|
|
87
|
-
exports.getDocVersionSuggestions = getDocVersionSuggestions;
|
|
78
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { UseDataOptions } from '@docusaurus/types';
|
|
8
|
+
export declare type ActivePlugin = {
|
|
9
|
+
pluginId: string;
|
|
10
|
+
pluginData: GlobalPluginData;
|
|
11
|
+
};
|
|
12
|
+
export declare type ActiveDocContext = {
|
|
13
|
+
activeVersion?: GlobalVersion;
|
|
14
|
+
activeDoc?: GlobalDoc;
|
|
15
|
+
alternateDocVersions: {
|
|
16
|
+
[versionName: string]: GlobalDoc;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare type GlobalDoc = {
|
|
20
|
+
/**
|
|
21
|
+
* For generated index pages, this is the `slug`, **not** `permalink`
|
|
22
|
+
* (without base URL). Because slugs have leading slashes but IDs don't,
|
|
23
|
+
* there won't be clashes.
|
|
24
|
+
*/
|
|
25
|
+
id: string;
|
|
26
|
+
path: string;
|
|
27
|
+
sidebar: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
export declare type GlobalVersion = {
|
|
30
|
+
name: string;
|
|
31
|
+
label: string;
|
|
32
|
+
isLast: boolean;
|
|
33
|
+
path: string;
|
|
34
|
+
/** The doc with `slug: /`, or first doc in first sidebar */
|
|
35
|
+
mainDocId: string;
|
|
36
|
+
docs: GlobalDoc[];
|
|
37
|
+
/** Unversioned IDs. In development, this list is empty. */
|
|
38
|
+
draftIds: string[];
|
|
39
|
+
sidebars?: {
|
|
40
|
+
[sidebarId: string]: GlobalSidebar;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export declare type GlobalSidebar = {
|
|
44
|
+
link?: {
|
|
45
|
+
label: string;
|
|
46
|
+
path: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export declare type GlobalPluginData = {
|
|
50
|
+
path: string;
|
|
51
|
+
versions: GlobalVersion[];
|
|
52
|
+
breadcrumbs: boolean;
|
|
53
|
+
};
|
|
54
|
+
export declare type DocVersionSuggestions = {
|
|
55
|
+
/** Suggest the latest version */
|
|
56
|
+
latestVersionSuggestion: GlobalVersion;
|
|
57
|
+
/** Suggest the same doc, in latest version (if one exists) */
|
|
58
|
+
latestDocSuggestion?: GlobalDoc;
|
|
59
|
+
};
|
|
60
|
+
export declare const useAllDocsData: () => {
|
|
61
|
+
[pluginId: string]: GlobalPluginData;
|
|
62
|
+
};
|
|
63
|
+
export declare const useDocsData: (pluginId: string | undefined) => GlobalPluginData;
|
|
64
|
+
export declare function useActivePlugin(options?: UseDataOptions): ActivePlugin | undefined;
|
|
65
|
+
export declare function useActivePluginAndVersion(options?: UseDataOptions): {
|
|
66
|
+
activePlugin: ActivePlugin;
|
|
67
|
+
activeVersion: GlobalVersion | undefined;
|
|
68
|
+
} | undefined;
|
|
69
|
+
/** Versions are returned ordered (most recent first). */
|
|
70
|
+
export declare function useVersions(pluginId: string | undefined): GlobalVersion[];
|
|
71
|
+
export declare function useLatestVersion(pluginId: string | undefined): GlobalVersion;
|
|
72
|
+
/**
|
|
73
|
+
* Returns `undefined` on doc-unrelated pages, because there's no version
|
|
74
|
+
* currently considered as active.
|
|
75
|
+
*/
|
|
76
|
+
export declare function useActiveVersion(pluginId: string | undefined): GlobalVersion | undefined;
|
|
77
|
+
export declare function useActiveDocContext(pluginId: string | undefined): ActiveDocContext;
|
|
78
|
+
/**
|
|
79
|
+
* Useful to say "hey, you are not on the latest docs version, please switch"
|
|
80
|
+
*/
|
|
81
|
+
export declare function useDocVersionSuggestions(pluginId: string | undefined): DocVersionSuggestions;
|
|
@@ -0,0 +1,67 @@
|
|
|
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 { useLocation } from '@docusaurus/router';
|
|
8
|
+
import { useAllPluginInstancesData, usePluginData, } from '@docusaurus/useGlobalData';
|
|
9
|
+
import { getActivePlugin, getLatestVersion, getActiveVersion, getActiveDocContext, getDocVersionSuggestions, } from './docsClientUtils';
|
|
10
|
+
// Important to use a constant object to avoid React useEffect executions etc.
|
|
11
|
+
// see https://github.com/facebook/docusaurus/issues/5089
|
|
12
|
+
const StableEmptyObject = {};
|
|
13
|
+
// In blog-only mode, docs hooks are still used by the theme. We need a fail-
|
|
14
|
+
// safe fallback when the docs plugin is not in use
|
|
15
|
+
export const useAllDocsData = () => useAllPluginInstancesData('docusaurus-plugin-content-docs') ?? StableEmptyObject;
|
|
16
|
+
export const useDocsData = (pluginId) => usePluginData('docusaurus-plugin-content-docs', pluginId, {
|
|
17
|
+
failfast: true,
|
|
18
|
+
});
|
|
19
|
+
// TODO this feature should be provided by docusaurus core
|
|
20
|
+
export function useActivePlugin(options = {}) {
|
|
21
|
+
const data = useAllDocsData();
|
|
22
|
+
const { pathname } = useLocation();
|
|
23
|
+
return getActivePlugin(data, pathname, options);
|
|
24
|
+
}
|
|
25
|
+
export function useActivePluginAndVersion(options = {}) {
|
|
26
|
+
const activePlugin = useActivePlugin(options);
|
|
27
|
+
const { pathname } = useLocation();
|
|
28
|
+
if (!activePlugin) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const activeVersion = getActiveVersion(activePlugin.pluginData, pathname);
|
|
32
|
+
return {
|
|
33
|
+
activePlugin,
|
|
34
|
+
activeVersion,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Versions are returned ordered (most recent first). */
|
|
38
|
+
export function useVersions(pluginId) {
|
|
39
|
+
const data = useDocsData(pluginId);
|
|
40
|
+
return data.versions;
|
|
41
|
+
}
|
|
42
|
+
export function useLatestVersion(pluginId) {
|
|
43
|
+
const data = useDocsData(pluginId);
|
|
44
|
+
return getLatestVersion(data);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns `undefined` on doc-unrelated pages, because there's no version
|
|
48
|
+
* currently considered as active.
|
|
49
|
+
*/
|
|
50
|
+
export function useActiveVersion(pluginId) {
|
|
51
|
+
const data = useDocsData(pluginId);
|
|
52
|
+
const { pathname } = useLocation();
|
|
53
|
+
return getActiveVersion(data, pathname);
|
|
54
|
+
}
|
|
55
|
+
export function useActiveDocContext(pluginId) {
|
|
56
|
+
const data = useDocsData(pluginId);
|
|
57
|
+
const { pathname } = useLocation();
|
|
58
|
+
return getActiveDocContext(data, pathname);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Useful to say "hey, you are not on the latest docs version, please switch"
|
|
62
|
+
*/
|
|
63
|
+
export function useDocVersionSuggestions(pluginId) {
|
|
64
|
+
const data = useDocsData(pluginId);
|
|
65
|
+
const { pathname } = useLocation();
|
|
66
|
+
return getDocVersionSuggestions(data, pathname);
|
|
67
|
+
}
|
package/lib/constants.d.ts
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
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
|
+
/** The name of the version that's actively worked on (e.g. `website/docs`) */
|
|
7
8
|
export declare const CURRENT_VERSION_NAME = "current";
|
|
9
|
+
/** All doc versions are stored here by version names */
|
|
8
10
|
export declare const VERSIONED_DOCS_DIR = "versioned_docs";
|
|
11
|
+
/** All doc versioned sidebars are stored here by version names */
|
|
9
12
|
export declare const VERSIONED_SIDEBARS_DIR = "versioned_sidebars";
|
|
13
|
+
/** The version names. Should 1-1 map to the content of versioned docs dir. */
|
|
10
14
|
export declare const VERSIONS_JSON_FILE = "versions.json";
|
package/lib/constants.js
CHANGED
|
@@ -7,8 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.VERSIONS_JSON_FILE = exports.VERSIONED_SIDEBARS_DIR = exports.VERSIONED_DOCS_DIR = exports.CURRENT_VERSION_NAME = void 0;
|
|
10
|
-
|
|
10
|
+
/** The name of the version that's actively worked on (e.g. `website/docs`) */
|
|
11
11
|
exports.CURRENT_VERSION_NAME = 'current';
|
|
12
|
+
/** All doc versions are stored here by version names */
|
|
12
13
|
exports.VERSIONED_DOCS_DIR = 'versioned_docs';
|
|
14
|
+
/** All doc versioned sidebars are stored here by version names */
|
|
13
15
|
exports.VERSIONED_SIDEBARS_DIR = 'versioned_sidebars';
|
|
16
|
+
/** The version names. Should 1-1 map to the content of versioned docs dir. */
|
|
14
17
|
exports.VERSIONS_JSON_FILE = 'versions.json';
|
package/lib/docs.d.ts
CHANGED
|
@@ -4,15 +4,42 @@
|
|
|
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 {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare function
|
|
7
|
+
import type { MetadataOptions, PluginOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
9
|
+
import type { SidebarsUtils } from './sidebars/utils';
|
|
10
|
+
import type { DocFile } from './types';
|
|
11
|
+
export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string): Promise<DocFile>;
|
|
12
|
+
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
|
13
|
+
export declare type DocEnv = 'production' | 'development';
|
|
12
14
|
export declare function processDocMetadata(args: {
|
|
13
15
|
docFile: DocFile;
|
|
14
16
|
versionMetadata: VersionMetadata;
|
|
15
17
|
context: LoadContext;
|
|
16
18
|
options: MetadataOptions;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
env: DocEnv;
|
|
20
|
+
}): Promise<DocMetadataBase>;
|
|
21
|
+
export declare function addDocNavigation(docsBase: DocMetadataBase[], sidebarsUtils: SidebarsUtils, sidebarFilePath: string): LoadedVersion['docs'];
|
|
22
|
+
/**
|
|
23
|
+
* The "main doc" is the "version entry point"
|
|
24
|
+
* We browse this doc by clicking on a version:
|
|
25
|
+
* - the "home" doc (at '/docs/')
|
|
26
|
+
* - the first doc of the first sidebar
|
|
27
|
+
* - a random doc (if no docs are in any sidebar... edge case)
|
|
28
|
+
*/
|
|
29
|
+
export declare function getMainDocId({ docs, sidebarsUtils, }: {
|
|
30
|
+
docs: DocMetadataBase[];
|
|
31
|
+
sidebarsUtils: SidebarsUtils;
|
|
32
|
+
}): string;
|
|
33
|
+
export declare const isCategoryIndex: CategoryIndexMatcher;
|
|
34
|
+
/**
|
|
35
|
+
* `guides/sidebar/autogenerated.md` ->
|
|
36
|
+
* `'autogenerated', '.md', ['sidebar', 'guides']`
|
|
37
|
+
*/
|
|
38
|
+
export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): Parameters<CategoryIndexMatcher>[0];
|
|
39
|
+
export declare function getDocIds(doc: DocMetadataBase): [string, string];
|
|
40
|
+
export declare function createDocsByIdIndex<Doc extends {
|
|
41
|
+
id: string;
|
|
42
|
+
unversionedId: string;
|
|
43
|
+
}>(docs: Doc[]): {
|
|
44
|
+
[docId: string]: Doc;
|
|
45
|
+
};
|