@docusaurus/plugin-content-docs 2.0.0-beta.20 → 2.0.0-beta.21
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 +1 -1
- package/lib/cli.d.ts +1 -1
- package/lib/cli.js +8 -13
- package/lib/client/docsClientUtils.js +12 -20
- package/lib/client/index.js +29 -42
- package/lib/docs.d.ts +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -3
- package/lib/markdown/index.js +1 -1
- package/lib/options.d.ts +1 -1
- package/lib/options.js +1 -1
- package/lib/props.js +1 -1
- package/lib/routes.js +1 -1
- package/lib/sidebars/generator.js +3 -3
- package/lib/sidebars/index.d.ts +1 -1
- package/lib/sidebars/index.js +6 -6
- package/lib/sidebars/normalization.js +1 -1
- package/lib/sidebars/postProcessor.d.ts +3 -0
- package/lib/sidebars/postProcessor.js +33 -17
- package/lib/sidebars/processor.js +5 -16
- package/lib/sidebars/types.d.ts +2 -2
- package/lib/sidebars/utils.js +1 -1
- package/lib/sidebars/validation.js +5 -1
- package/lib/slug.js +1 -1
- package/lib/tags.js +1 -1
- package/lib/translations.js +8 -8
- package/lib/versions/files.d.ts +7 -0
- package/lib/versions/files.js +3 -2
- package/lib/versions/index.js +1 -1
- package/lib/versions/validation.js +1 -1
- package/package.json +13 -13
- package/src/categoryGeneratedIndex.ts +2 -2
- package/src/cli.ts +11 -15
- package/src/client/docsClientUtils.ts +1 -1
- package/src/client/index.ts +5 -2
- package/src/docs.ts +3 -3
- package/src/globalData.ts +1 -1
- package/src/index.ts +21 -17
- package/src/markdown/index.ts +1 -1
- package/src/markdown/linkify.ts +1 -1
- package/src/options.ts +5 -6
- package/src/plugin-content-docs.d.ts +19 -2
- package/src/props.ts +3 -3
- package/src/routes.ts +3 -3
- package/src/sidebars/README.md +1 -0
- package/src/sidebars/generator.ts +6 -6
- package/src/sidebars/index.ts +7 -7
- package/src/sidebars/normalization.ts +3 -3
- package/src/sidebars/postProcessor.ts +47 -24
- package/src/sidebars/processor.ts +8 -24
- package/src/sidebars/types.ts +2 -2
- package/src/sidebars/utils.ts +3 -4
- package/src/sidebars/validation.ts +6 -2
- package/src/slug.ts +1 -1
- package/src/tags.ts +1 -1
- package/src/translations.ts +8 -9
- package/src/types.ts +0 -2
- package/src/versions/files.ts +3 -3
- package/src/versions/index.ts +1 -1
- package/src/versions/validation.ts +3 -1
|
@@ -4,8 +4,8 @@
|
|
|
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 type { CategoryGeneratedIndexMetadata, DocMetadataBase } from '@docusaurus/plugin-content-docs';
|
|
8
7
|
import { type SidebarsUtils } from './sidebars/utils';
|
|
8
|
+
import type { CategoryGeneratedIndexMetadata, DocMetadataBase } from '@docusaurus/plugin-content-docs';
|
|
9
9
|
export declare function getCategoryGeneratedIndexMetadataList({ docs, sidebarsUtils, }: {
|
|
10
10
|
sidebarsUtils: SidebarsUtils;
|
|
11
11
|
docs: DocMetadataBase[];
|
package/lib/cli.d.ts
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
8
8
|
import type { LoadContext } from '@docusaurus/types';
|
|
9
|
-
export declare function cliDocsVersionCommand(version:
|
|
9
|
+
export declare function cliDocsVersionCommand(version: unknown, { id: pluginId, path: docsPath, sidebarPath }: PluginOptions, { siteDir, i18n }: LoadContext): Promise<void>;
|
package/lib/cli.js
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.cliDocsVersionCommand = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const files_1 = require("./versions/files");
|
|
12
|
-
const validation_1 = require("./versions/validation");
|
|
13
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
14
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");
|
|
15
17
|
const sidebars_1 = require("./sidebars");
|
|
16
18
|
const constants_1 = require("./constants");
|
|
17
|
-
const utils_1 = require("@docusaurus/utils");
|
|
18
|
-
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
19
19
|
async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, version, }) {
|
|
20
20
|
// Load current sidebar and create a new versioned sidebars file (if needed).
|
|
21
21
|
// Note: we don't need the sidebars file to be normalized: it's ok to let
|
|
@@ -37,16 +37,11 @@ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, si
|
|
|
37
37
|
try {
|
|
38
38
|
(0, validation_1.validateVersionName)(version);
|
|
39
39
|
}
|
|
40
|
-
catch (
|
|
40
|
+
catch (err) {
|
|
41
41
|
logger_1.default.info `${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
|
|
42
|
-
throw
|
|
43
|
-
}
|
|
44
|
-
// Load existing versions.
|
|
45
|
-
let versions = [];
|
|
46
|
-
const versionsJSONFile = (0, files_1.getVersionsFilePath)(siteDir, pluginId);
|
|
47
|
-
if (await fs_extra_1.default.pathExists(versionsJSONFile)) {
|
|
48
|
-
versions = await fs_extra_1.default.readJSON(versionsJSONFile);
|
|
42
|
+
throw err;
|
|
49
43
|
}
|
|
44
|
+
const versions = (await (0, files_1.readVersionsFile)(siteDir, pluginId)) ?? [];
|
|
50
45
|
// Check if version already exists.
|
|
51
46
|
if (versions.includes(version)) {
|
|
52
47
|
throw new Error(`${pluginIdLogPrefix}: this version already exists! Use a version tag that does not already exist.`);
|
|
@@ -92,7 +87,7 @@ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, si
|
|
|
92
87
|
});
|
|
93
88
|
// Update versions.json file.
|
|
94
89
|
versions.unshift(version);
|
|
95
|
-
await fs_extra_1.default.outputFile(
|
|
90
|
+
await fs_extra_1.default.outputFile((0, files_1.getVersionsFilePath)(siteDir, pluginId), `${JSON.stringify(versions, null, 2)}\n`);
|
|
96
91
|
logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
|
|
97
92
|
}
|
|
98
93
|
exports.cliDocsVersionCommand = cliDocsVersionCommand;
|
|
@@ -1,22 +1,19 @@
|
|
|
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
|
-
exports.getDocVersionSuggestions = exports.getActiveDocContext = exports.getActiveVersion = exports.getLatestVersion = exports.getActivePlugin = void 0;
|
|
10
|
-
const router_1 = require("@docusaurus/router");
|
|
7
|
+
import { matchPath } from '@docusaurus/router';
|
|
11
8
|
// This code is not part of the api surface, not in ./theme on purpose
|
|
12
9
|
// get the data of the plugin that is currently "active"
|
|
13
10
|
// ie the docs of that plugin are currently browsed
|
|
14
11
|
// it is useful to support multiple docs plugin instances
|
|
15
|
-
function getActivePlugin(allPluginData, pathname, options = {}) {
|
|
12
|
+
export function getActivePlugin(allPluginData, pathname, options = {}) {
|
|
16
13
|
const activeEntry = Object.entries(allPluginData)
|
|
17
14
|
// Route sorting: '/android/foo' should match '/android' instead of '/'
|
|
18
15
|
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
|
19
|
-
.find(([, pluginData]) => !!
|
|
16
|
+
.find(([, pluginData]) => !!matchPath(pathname, {
|
|
20
17
|
path: pluginData.path,
|
|
21
18
|
exact: false,
|
|
22
19
|
strict: false,
|
|
@@ -31,27 +28,24 @@ function getActivePlugin(allPluginData, pathname, options = {}) {
|
|
|
31
28
|
}
|
|
32
29
|
return activePlugin;
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
function getActiveVersion(data, pathname) {
|
|
38
|
-
const lastVersion = (0, 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);
|
|
39
34
|
// Last version is a route like /docs/*,
|
|
40
35
|
// we need to match it last or it would match /docs/version-1.0/* as well
|
|
41
36
|
const orderedVersionsMetadata = [
|
|
42
37
|
...data.versions.filter((version) => version !== lastVersion),
|
|
43
38
|
lastVersion,
|
|
44
39
|
];
|
|
45
|
-
return orderedVersionsMetadata.find((version) => !!
|
|
40
|
+
return orderedVersionsMetadata.find((version) => !!matchPath(pathname, {
|
|
46
41
|
path: version.path,
|
|
47
42
|
exact: false,
|
|
48
43
|
strict: false,
|
|
49
44
|
}));
|
|
50
45
|
}
|
|
51
|
-
|
|
52
|
-
function getActiveDocContext(data, pathname) {
|
|
46
|
+
export function getActiveDocContext(data, pathname) {
|
|
53
47
|
const activeVersion = getActiveVersion(data, pathname);
|
|
54
|
-
const activeDoc = activeVersion?.docs.find((doc) => !!
|
|
48
|
+
const activeDoc = activeVersion?.docs.find((doc) => !!matchPath(pathname, {
|
|
55
49
|
path: doc.path,
|
|
56
50
|
exact: true,
|
|
57
51
|
strict: false,
|
|
@@ -76,11 +70,9 @@ function getActiveDocContext(data, pathname) {
|
|
|
76
70
|
alternateDocVersions: alternateVersionDocs,
|
|
77
71
|
};
|
|
78
72
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const latestVersion = (0, exports.getLatestVersion)(data);
|
|
73
|
+
export function getDocVersionSuggestions(data, pathname) {
|
|
74
|
+
const latestVersion = getLatestVersion(data);
|
|
82
75
|
const activeDocContext = getActiveDocContext(data, pathname);
|
|
83
|
-
const latestDocSuggestion = activeDocContext
|
|
76
|
+
const latestDocSuggestion = activeDocContext.alternateDocVersions[latestVersion.name];
|
|
84
77
|
return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
|
|
85
78
|
}
|
|
86
|
-
exports.getDocVersionSuggestions = getDocVersionSuggestions;
|
package/lib/client/index.js
CHANGED
|
@@ -1,72 +1,59 @@
|
|
|
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
|
-
const useGlobalData_1 = require("@docusaurus/useGlobalData");
|
|
12
|
-
const docsClientUtils_1 = require("./docsClientUtils");
|
|
7
|
+
import { useLocation } from '@docusaurus/router';
|
|
8
|
+
import { useAllPluginInstancesData, usePluginData, } from '@docusaurus/useGlobalData';
|
|
9
|
+
import { getActivePlugin, getLatestVersion, getActiveVersion, getActiveDocContext, getDocVersionSuggestions, } from './docsClientUtils';
|
|
13
10
|
// Important to use a constant object to avoid React useEffect executions etc.
|
|
14
11
|
// see https://github.com/facebook/docusaurus/issues/5089
|
|
15
12
|
const StableEmptyObject = {};
|
|
16
13
|
// In blog-only mode, docs hooks are still used by the theme. We need a fail-
|
|
17
14
|
// safe fallback when the docs plugin is not in use
|
|
18
|
-
const useAllDocsData = () =>
|
|
19
|
-
|
|
20
|
-
exports.useAllDocsData = useAllDocsData;
|
|
21
|
-
const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId, {
|
|
15
|
+
export const useAllDocsData = () => useAllPluginInstancesData('docusaurus-plugin-content-docs') ?? StableEmptyObject;
|
|
16
|
+
export const useDocsData = (pluginId) => usePluginData('docusaurus-plugin-content-docs', pluginId, {
|
|
22
17
|
failfast: true,
|
|
23
18
|
});
|
|
24
|
-
exports.useDocsData = useDocsData;
|
|
25
19
|
// TODO this feature should be provided by docusaurus core
|
|
26
|
-
function useActivePlugin(options = {}) {
|
|
27
|
-
const data =
|
|
28
|
-
const { pathname } =
|
|
29
|
-
return
|
|
20
|
+
export function useActivePlugin(options = {}) {
|
|
21
|
+
const data = useAllDocsData();
|
|
22
|
+
const { pathname } = useLocation();
|
|
23
|
+
return getActivePlugin(data, pathname, options);
|
|
30
24
|
}
|
|
31
|
-
|
|
32
|
-
function useActivePluginAndVersion(options = {}) {
|
|
25
|
+
export function useActivePluginAndVersion(options = {}) {
|
|
33
26
|
const activePlugin = useActivePlugin(options);
|
|
34
|
-
const { pathname } =
|
|
27
|
+
const { pathname } = useLocation();
|
|
35
28
|
if (!activePlugin) {
|
|
36
29
|
return undefined;
|
|
37
30
|
}
|
|
38
|
-
const activeVersion =
|
|
31
|
+
const activeVersion = getActiveVersion(activePlugin.pluginData, pathname);
|
|
39
32
|
return {
|
|
40
33
|
activePlugin,
|
|
41
34
|
activeVersion,
|
|
42
35
|
};
|
|
43
36
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const data = (0, exports.useDocsData)(pluginId);
|
|
37
|
+
export function useVersions(pluginId) {
|
|
38
|
+
const data = useDocsData(pluginId);
|
|
47
39
|
return data.versions;
|
|
48
40
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return (0, docsClientUtils_1.getLatestVersion)(data);
|
|
41
|
+
export function useLatestVersion(pluginId) {
|
|
42
|
+
const data = useDocsData(pluginId);
|
|
43
|
+
return getLatestVersion(data);
|
|
53
44
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
return (0, docsClientUtils_1.getActiveVersion)(data, pathname);
|
|
45
|
+
export function useActiveVersion(pluginId) {
|
|
46
|
+
const data = useDocsData(pluginId);
|
|
47
|
+
const { pathname } = useLocation();
|
|
48
|
+
return getActiveVersion(data, pathname);
|
|
59
49
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
return (0, docsClientUtils_1.getActiveDocContext)(data, pathname);
|
|
50
|
+
export function useActiveDocContext(pluginId) {
|
|
51
|
+
const data = useDocsData(pluginId);
|
|
52
|
+
const { pathname } = useLocation();
|
|
53
|
+
return getActiveDocContext(data, pathname);
|
|
65
54
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
return (0, docsClientUtils_1.getDocVersionSuggestions)(data, pathname);
|
|
55
|
+
export function useDocVersionSuggestions(pluginId) {
|
|
56
|
+
const data = useDocsData(pluginId);
|
|
57
|
+
const { pathname } = useLocation();
|
|
58
|
+
return getDocVersionSuggestions(data, pathname);
|
|
71
59
|
}
|
|
72
|
-
exports.useDocVersionSuggestions = useDocVersionSuggestions;
|
package/lib/docs.d.ts
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
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 type { MetadataOptions, PluginOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
|
|
7
8
|
import type { LoadContext } from '@docusaurus/types';
|
|
8
|
-
import type { DocFile } from './types';
|
|
9
9
|
import type { SidebarsUtils } from './sidebars/utils';
|
|
10
|
-
import type {
|
|
10
|
+
import type { DocFile } from './types';
|
|
11
11
|
declare type LastUpdateOptions = Pick<PluginOptions, 'showLastUpdateAuthor' | 'showLastUpdateTime'>;
|
|
12
12
|
export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string, options: LastUpdateOptions): Promise<DocFile>;
|
|
13
13
|
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +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 type { LoadContext, Plugin } from '@docusaurus/types';
|
|
8
7
|
import type { PluginOptions, LoadedContent } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
9
9
|
export default function pluginContentDocs(context: LoadContext, options: PluginOptions): Promise<Plugin<LoadedContent>>;
|
|
10
10
|
export { validateOptions } from './options';
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.validateOptions = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
14
|
const utils_1 = require("@docusaurus/utils");
|
|
13
15
|
const sidebars_1 = require("./sidebars");
|
|
14
16
|
const generator_1 = require("./sidebars/generator");
|
|
@@ -20,11 +22,9 @@ const globalData_1 = require("./globalData");
|
|
|
20
22
|
const props_1 = require("./props");
|
|
21
23
|
const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
|
|
22
24
|
const translations_1 = require("./translations");
|
|
23
|
-
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
24
25
|
const tags_1 = require("./tags");
|
|
25
26
|
const routes_1 = require("./routes");
|
|
26
27
|
const utils_2 = require("./sidebars/utils");
|
|
27
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
28
28
|
async function pluginContentDocs(context, options) {
|
|
29
29
|
const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
|
|
30
30
|
// Mutate options to resolve sidebar path according to siteDir
|
|
@@ -76,7 +76,7 @@ async function pluginContentDocs(context, options) {
|
|
|
76
76
|
if (docFiles.length === 0) {
|
|
77
77
|
throw new Error(`Docs version "${versionMetadata.versionName}" has no docs! At least one doc should exist at "${path_1.default.relative(siteDir, versionMetadata.contentPath)}".`);
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
function processVersionDoc(docFile) {
|
|
80
80
|
return (0, docs_1.processDocMetadata)({
|
|
81
81
|
docFile,
|
|
82
82
|
versionMetadata,
|
package/lib/markdown/index.js
CHANGED
|
@@ -11,6 +11,6 @@ function markdownLoader(source) {
|
|
|
11
11
|
const fileString = source;
|
|
12
12
|
const callback = this.async();
|
|
13
13
|
const options = this.getOptions();
|
|
14
|
-
return callback
|
|
14
|
+
return callback(null, (0, linkify_1.linkify)(fileString, this.resourcePath, options));
|
|
15
15
|
}
|
|
16
16
|
exports.default = markdownLoader;
|
package/lib/options.d.ts
CHANGED
|
@@ -4,7 +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 type { PluginOptions, Options } from '@docusaurus/plugin-content-docs';
|
|
8
7
|
import type { OptionValidationContext } from '@docusaurus/types';
|
|
8
|
+
import type { PluginOptions, Options } from '@docusaurus/plugin-content-docs';
|
|
9
9
|
export declare const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'>;
|
|
10
10
|
export declare function validateOptions({ validate, options: userOptions, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
|
package/lib/options.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateOptions = exports.DEFAULT_OPTIONS = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
11
12
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
13
|
const utils_1 = require("@docusaurus/utils");
|
|
13
|
-
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
14
|
const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
|
|
15
15
|
const generator_1 = require("./sidebars/generator");
|
|
16
16
|
const numberPrefix_1 = require("./numberPrefix");
|
package/lib/props.js
CHANGED
|
@@ -26,7 +26,7 @@ Available document ids are:
|
|
|
26
26
|
const { title, permalink, frontMatter: { sidebar_label: sidebarLabel }, } = docMetadata;
|
|
27
27
|
return {
|
|
28
28
|
type: 'link',
|
|
29
|
-
label: sidebarLabel
|
|
29
|
+
label: sidebarLabel ?? item.label ?? title,
|
|
30
30
|
href: permalink,
|
|
31
31
|
className: item.className,
|
|
32
32
|
customProps: item.customProps ?? docMetadata.frontMatter.sidebar_custom_props,
|
package/lib/routes.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createVersionRoutes = exports.createDocRoutes = exports.createCategoryGeneratedIndexRoutes = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
11
12
|
const utils_1 = require("@docusaurus/utils");
|
|
12
13
|
const props_1 = require("./props");
|
|
13
|
-
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
14
|
async function createCategoryGeneratedIndexRoutes({ version, actions, docCategoryGeneratedIndexComponent, aliasedSource, }) {
|
|
15
15
|
const slugs = (0, utils_1.createSlugger)();
|
|
16
16
|
async function createCategoryGeneratedIndexRoute(categoryGeneratedIndex) {
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.DefaultSidebarItemsGenerator = exports.CategoryMetadataFilenamePattern = exports.CategoryMetadataFilenameBase = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
12
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
-
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
-
const
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
15
|
const docs_1 = require("../docs");
|
|
16
16
|
const BreadcrumbSeparator = '/';
|
|
17
17
|
// Just an alias to the make code more explicit
|
|
@@ -21,7 +21,7 @@ function getLocalDocId(docId) {
|
|
|
21
21
|
exports.CategoryMetadataFilenameBase = '_category_';
|
|
22
22
|
exports.CategoryMetadataFilenamePattern = '_category_.{json,yml,yaml}';
|
|
23
23
|
// Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
|
|
24
|
-
const DefaultSidebarItemsGenerator =
|
|
24
|
+
const DefaultSidebarItemsGenerator = ({ numberPrefixParser, isCategoryIndex, docs: allDocs, item: { dirName: autogenDir }, categoriesMetadata, }) => {
|
|
25
25
|
const docsById = (0, docs_1.createDocsByIdIndex)(allDocs);
|
|
26
26
|
const findDoc = (docId) => docsById[docId];
|
|
27
27
|
const getDoc = (docId) => {
|
package/lib/sidebars/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
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 type { SidebarsConfig, Sidebars, SidebarProcessorParams } from './types';
|
|
8
7
|
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { SidebarsConfig, Sidebars, SidebarProcessorParams } from './types';
|
|
9
9
|
export declare const DefaultSidebars: SidebarsConfig;
|
|
10
10
|
export declare const DisabledSidebars: SidebarsConfig;
|
|
11
11
|
export declare function resolveSidebarPathOption(siteDir: string, sidebarPathOption: PluginOptions['sidebarPath']): PluginOptions['sidebarPath'];
|
package/lib/sidebars/index.js
CHANGED
|
@@ -9,17 +9,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.loadSidebars = exports.loadSidebarsFileUnsafe = exports.resolveSidebarPathOption = exports.DisabledSidebars = exports.DefaultSidebars = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
17
|
+
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
12
18
|
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
13
19
|
const validation_1 = require("./validation");
|
|
14
20
|
const normalization_1 = require("./normalization");
|
|
15
21
|
const processor_1 = require("./processor");
|
|
16
22
|
const postProcessor_1 = require("./postProcessor");
|
|
17
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
18
|
-
const utils_1 = require("@docusaurus/utils");
|
|
19
|
-
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
20
|
-
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
21
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
22
|
-
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
23
23
|
exports.DefaultSidebars = {
|
|
24
24
|
defaultSidebar: [
|
|
25
25
|
{
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.normalizeSidebars = exports.normalizeItem = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
14
|
function normalizeCategoriesShorthand(sidebar) {
|
|
15
15
|
return Object.entries(sidebar).map(([label, items]) => ({
|
|
16
16
|
type: 'category',
|
|
@@ -5,4 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Sidebars, SidebarProcessorParams, ProcessedSidebars } from './types';
|
|
8
|
+
export declare type SidebarPostProcessorParams = SidebarProcessorParams & {
|
|
9
|
+
draftIds: Set<string>;
|
|
10
|
+
};
|
|
8
11
|
export declare function postProcessSidebars(sidebars: ProcessedSidebars, params: SidebarProcessorParams): Sidebars;
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.postProcessSidebars = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const utils_1 = require("@docusaurus/utils");
|
|
12
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
const docs_1 = require("../docs");
|
|
13
14
|
function normalizeCategoryLink(category, params) {
|
|
15
|
+
if (category.link?.type === 'doc' && params.draftIds.has(category.link.id)) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
14
18
|
if (category.link?.type === 'generated-index') {
|
|
15
19
|
// Default slug logic can be improved
|
|
16
20
|
const getDefaultSlug = () => `/category/${params.categoryLabelSlugger.slug(category.label)}`;
|
|
@@ -26,40 +30,52 @@ function normalizeCategoryLink(category, params) {
|
|
|
26
30
|
}
|
|
27
31
|
function postProcessSidebarItem(item, params) {
|
|
28
32
|
if (item.type === 'category') {
|
|
33
|
+
// Fail-fast if there's actually no subitems, no because all subitems are
|
|
34
|
+
// drafts. This is likely a configuration mistake.
|
|
35
|
+
if (item.items.length === 0 && !item.link) {
|
|
36
|
+
throw new Error(`Sidebar category ${item.label} has neither any subitem nor a link. This makes this item not able to link to anything.`);
|
|
37
|
+
}
|
|
29
38
|
const category = {
|
|
30
39
|
...item,
|
|
31
40
|
collapsed: item.collapsed ?? params.sidebarOptions.sidebarCollapsed,
|
|
32
41
|
collapsible: item.collapsible ?? params.sidebarOptions.sidebarCollapsible,
|
|
33
42
|
link: normalizeCategoryLink(item, params),
|
|
34
|
-
items: item.items
|
|
43
|
+
items: item.items
|
|
44
|
+
.map((subItem) => postProcessSidebarItem(subItem, params))
|
|
45
|
+
.filter((v) => Boolean(v)),
|
|
35
46
|
};
|
|
36
47
|
// If the current category doesn't have subitems, we render a normal link
|
|
37
48
|
// instead.
|
|
38
49
|
if (category.items.length === 0) {
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
// Doesn't make sense to render an empty generated index page, so we
|
|
51
|
+
// filter the entire category out as well.
|
|
52
|
+
if (!category.link ||
|
|
53
|
+
category.link.type === 'generated-index' ||
|
|
54
|
+
params.draftIds.has(category.link.id)) {
|
|
55
|
+
return null;
|
|
41
56
|
}
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
: {
|
|
49
|
-
type: 'link',
|
|
50
|
-
label: category.label,
|
|
51
|
-
href: category.link.permalink,
|
|
52
|
-
};
|
|
57
|
+
return {
|
|
58
|
+
type: 'doc',
|
|
59
|
+
label: category.label,
|
|
60
|
+
id: category.link.id,
|
|
61
|
+
};
|
|
53
62
|
}
|
|
54
63
|
// A non-collapsible category can't be collapsed!
|
|
55
|
-
if (category.collapsible
|
|
64
|
+
if (!category.collapsible) {
|
|
56
65
|
category.collapsed = false;
|
|
57
66
|
}
|
|
58
67
|
return category;
|
|
59
68
|
}
|
|
69
|
+
if ((item.type === 'doc' || item.type === 'ref') &&
|
|
70
|
+
params.draftIds.has(item.id)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
60
73
|
return item;
|
|
61
74
|
}
|
|
62
75
|
function postProcessSidebars(sidebars, params) {
|
|
63
|
-
|
|
76
|
+
const draftIds = new Set(params.drafts.flatMap(docs_1.getDocIds));
|
|
77
|
+
return lodash_1.default.mapValues(sidebars, (sidebar) => sidebar
|
|
78
|
+
.map((item) => postProcessSidebarItem(item, { ...params, draftIds }))
|
|
79
|
+
.filter((v) => Boolean(v)));
|
|
64
80
|
}
|
|
65
81
|
exports.postProcessSidebars = postProcessSidebars;
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.processSidebars = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const generator_1 = require("./generator");
|
|
12
|
-
const validation_1 = require("./validation");
|
|
13
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
12
|
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
13
|
+
const generator_1 = require("./generator");
|
|
14
|
+
const validation_1 = require("./validation");
|
|
15
15
|
const docs_1 = require("../docs");
|
|
16
16
|
function toSidebarItemsGeneratorDoc(doc) {
|
|
17
17
|
return lodash_1.default.pick(doc, [
|
|
@@ -30,7 +30,7 @@ function toSidebarItemsGeneratorVersion(version) {
|
|
|
30
30
|
// Handle the generation of autogenerated sidebar items and other
|
|
31
31
|
// post-processing checks
|
|
32
32
|
async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
33
|
-
const { sidebarItemsGenerator, numberPrefixParser, docs,
|
|
33
|
+
const { sidebarItemsGenerator, numberPrefixParser, docs, version } = params;
|
|
34
34
|
// Just a minor lazy transformation optimization
|
|
35
35
|
const getSidebarItemsGeneratorDocsAndVersion = lodash_1.default.memoize(() => ({
|
|
36
36
|
docs: docs.map(toSidebarItemsGeneratorDoc),
|
|
@@ -51,23 +51,12 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
|
51
51
|
// more autogenerated items, or when loop count (e.g. 10) is reached
|
|
52
52
|
return processItems(generatedItems);
|
|
53
53
|
}
|
|
54
|
-
const draftIds = new Set(drafts.flatMap(docs_1.getDocIds));
|
|
55
|
-
const isDraftItem = (item) => {
|
|
56
|
-
if (item.type === 'doc' || item.type === 'ref') {
|
|
57
|
-
return draftIds.has(item.id);
|
|
58
|
-
}
|
|
59
|
-
// If a category only contains draft items, it should be filtered entirely.
|
|
60
|
-
if (item.type === 'category') {
|
|
61
|
-
return item.items.every(isDraftItem);
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
64
|
-
};
|
|
65
54
|
async function processItem(item) {
|
|
66
55
|
if (item.type === 'category') {
|
|
67
56
|
return [
|
|
68
57
|
{
|
|
69
58
|
...item,
|
|
70
|
-
items: await
|
|
59
|
+
items: (await Promise.all(item.items.map(processItem))).flat(),
|
|
71
60
|
},
|
|
72
61
|
];
|
|
73
62
|
}
|
|
@@ -77,7 +66,7 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
|
77
66
|
return [item];
|
|
78
67
|
}
|
|
79
68
|
async function processItems(items) {
|
|
80
|
-
return (await Promise.all(items.
|
|
69
|
+
return (await Promise.all(items.map(processItem))).flat();
|
|
81
70
|
}
|
|
82
71
|
const processedSidebar = await processItems(unprocessedSidebar);
|
|
83
72
|
return processedSidebar;
|
package/lib/sidebars/types.d.ts
CHANGED
|
@@ -157,7 +157,7 @@ export declare type SidebarItemsGeneratorArgs = {
|
|
|
157
157
|
[filePath: string]: CategoryMetadataFile;
|
|
158
158
|
};
|
|
159
159
|
};
|
|
160
|
-
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
|
|
160
|
+
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
|
|
161
161
|
export declare type SidebarItemsGeneratorOption = (generatorArgs: {
|
|
162
162
|
/**
|
|
163
163
|
* Useful to re-use/enhance the default sidebar generation logic from
|
|
@@ -165,7 +165,7 @@ export declare type SidebarItemsGeneratorOption = (generatorArgs: {
|
|
|
165
165
|
* @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
|
|
166
166
|
*/
|
|
167
167
|
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
168
|
-
} & SidebarItemsGeneratorArgs) => Promise<
|
|
168
|
+
} & SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
|
|
169
169
|
export declare type SidebarProcessorParams = {
|
|
170
170
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
171
171
|
numberPrefixParser: NumberPrefixParser;
|
package/lib/sidebars/utils.js
CHANGED
|
@@ -158,7 +158,7 @@ function createSidebarsUtils(sidebars) {
|
|
|
158
158
|
function getCategoryGeneratedIndexNavigation(categoryGeneratedIndexPermalink) {
|
|
159
159
|
function isCurrentCategoryGeneratedIndexItem(item) {
|
|
160
160
|
return (item.type === 'category' &&
|
|
161
|
-
item.link
|
|
161
|
+
item.link.type === 'generated-index' &&
|
|
162
162
|
item.link.permalink === categoryGeneratedIndexPermalink);
|
|
163
163
|
}
|
|
164
164
|
const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))[0];
|
|
@@ -133,6 +133,10 @@ const categoryMetadataFileSchema = utils_validation_1.Joi.object({
|
|
|
133
133
|
customProps: utils_validation_1.Joi.object().unknown(),
|
|
134
134
|
});
|
|
135
135
|
function validateCategoryMetadataFile(unsafeContent) {
|
|
136
|
-
|
|
136
|
+
const { error, value } = categoryMetadataFileSchema.validate(unsafeContent);
|
|
137
|
+
if (error) {
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
137
141
|
}
|
|
138
142
|
exports.validateCategoryMetadataFile = validateCategoryMetadataFile;
|
package/lib/slug.js
CHANGED
|
@@ -28,7 +28,7 @@ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumbe
|
|
|
28
28
|
(0, docs_1.isCategoryIndex)((0, docs_1.toCategoryIndexMatcherParam)({ source, sourceDirName }))) {
|
|
29
29
|
return dirNameSlug;
|
|
30
30
|
}
|
|
31
|
-
const baseSlug = frontMatterSlug
|
|
31
|
+
const baseSlug = frontMatterSlug ?? baseID;
|
|
32
32
|
return (0, utils_1.resolvePathname)(baseSlug, getDirNameSlug());
|
|
33
33
|
}
|
|
34
34
|
function ensureValidSlug(slug) {
|