@docusaurus/plugin-content-docs 2.0.0-beta.0e652730d → 2.0.0-beta.10
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/.tsbuildinfo +1 -1
- package/lib/categoryGeneratedIndex.d.ts +12 -0
- package/lib/categoryGeneratedIndex.js +37 -0
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +12 -34
- package/lib/client/docsClientUtils.d.ts +1 -4
- package/lib/client/docsClientUtils.js +21 -31
- package/lib/docFrontMatter.d.ts +1 -1
- package/lib/docFrontMatter.js +10 -6
- package/lib/docs.d.ts +25 -3
- package/lib/docs.js +125 -38
- package/lib/globalData.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +104 -138
- package/lib/lastUpdate.js +9 -10
- package/lib/markdown/index.d.ts +3 -6
- package/lib/markdown/index.js +3 -3
- package/lib/markdown/linkify.js +2 -2
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/options.d.ts +3 -3
- package/lib/options.js +49 -17
- package/lib/props.d.ts +7 -2
- package/lib/props.js +61 -9
- package/lib/routes.d.ts +27 -0
- package/lib/routes.js +105 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +5 -2
- package/lib/sidebars/generator.js +216 -0
- package/lib/sidebars/index.d.ts +15 -0
- package/lib/sidebars/index.js +73 -0
- package/lib/sidebars/normalization.d.ts +14 -0
- package/lib/sidebars/normalization.js +77 -0
- package/lib/sidebars/processor.d.ts +18 -0
- package/lib/sidebars/processor.js +85 -0
- package/lib/sidebars/types.d.ts +127 -0
- package/lib/sidebars/types.js +8 -0
- package/lib/sidebars/utils.d.ts +35 -0
- package/lib/sidebars/utils.js +228 -0
- package/lib/sidebars/validation.d.ts +10 -0
- package/lib/sidebars/validation.js +138 -0
- package/lib/slug.d.ts +4 -3
- package/lib/slug.js +27 -15
- package/lib/tags.d.ts +8 -0
- package/lib/tags.js +20 -0
- package/lib/theme/hooks/useDocs.js +24 -21
- package/lib/translations.d.ts +2 -2
- package/lib/translations.js +71 -29
- package/lib/types.d.ts +52 -62
- package/lib/versions.d.ts +3 -3
- package/lib/versions.js +76 -24
- package/package.json +22 -20
- package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +3 -0
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/sidebars.json +15 -1
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +1 -0
- package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +6 -0
- package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +2 -2
- package/src/__tests__/__snapshots__/cli.test.ts.snap +48 -73
- package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
- package/src/__tests__/__snapshots__/index.test.ts.snap +753 -112
- package/src/__tests__/__snapshots__/translations.test.ts.snap +45 -18
- package/src/__tests__/cli.test.ts +15 -11
- package/src/__tests__/docFrontMatter.test.ts +195 -40
- package/src/__tests__/docs.test.ts +311 -150
- package/src/__tests__/index.test.ts +112 -69
- package/src/__tests__/lastUpdate.test.ts +3 -2
- package/src/__tests__/options.test.ts +48 -4
- package/src/__tests__/props.test.ts +62 -0
- package/src/__tests__/slug.test.ts +127 -20
- package/src/__tests__/translations.test.ts +7 -2
- package/src/__tests__/versions.test.ts +93 -67
- package/src/categoryGeneratedIndex.ts +57 -0
- package/src/cli.ts +8 -41
- package/src/client/__tests__/docsClientUtils.test.ts +4 -5
- package/src/client/docsClientUtils.ts +19 -41
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/docFrontMatter.ts +13 -7
- package/src/docs.ts +158 -29
- package/src/globalData.ts +6 -1
- package/src/index.ts +134 -179
- package/src/lastUpdate.ts +10 -9
- package/src/markdown/index.ts +8 -12
- package/src/numberPrefix.ts +5 -3
- package/src/options.ts +59 -28
- package/src/plugin-content-docs.d.ts +179 -35
- package/src/props.ts +91 -16
- package/src/routes.ts +173 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
- package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +36 -6
- package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +143 -18
- package/src/sidebars/__tests__/index.test.ts +204 -0
- package/src/sidebars/__tests__/processor.test.ts +237 -0
- package/src/sidebars/__tests__/utils.test.ts +695 -0
- package/src/sidebars/__tests__/validation.test.ts +105 -0
- package/src/sidebars/generator.ts +310 -0
- package/src/sidebars/index.ts +94 -0
- package/src/sidebars/normalization.ts +112 -0
- package/src/sidebars/processor.ts +154 -0
- package/src/sidebars/types.ts +211 -0
- package/src/sidebars/utils.ts +329 -0
- package/src/sidebars/validation.ts +168 -0
- package/src/slug.ts +32 -17
- package/src/tags.ts +19 -0
- package/src/theme/hooks/useDocs.ts +5 -1
- package/src/translations.ts +103 -47
- package/src/types.ts +67 -105
- package/src/versions.ts +117 -21
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -43
- package/lib/sidebars.js +0 -319
- package/src/__tests__/sidebars.test.ts +0 -639
- package/src/sidebarItemsGenerator.ts +0 -307
- package/src/sidebars.ts +0 -506
package/lib/slug.js
CHANGED
|
@@ -8,23 +8,33 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const utils_1 = require("@docusaurus/utils");
|
|
10
10
|
const numberPrefix_1 = require("./numberPrefix");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (baseSlug.startsWith('/')) {
|
|
15
|
-
slug = baseSlug;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
11
|
+
const docs_1 = require("./docs");
|
|
12
|
+
function getSlug({ baseID, frontmatterSlug, source, sourceDirName, stripDirNumberPrefixes = true, numberPrefixParser = numberPrefix_1.DefaultNumberPrefixParser, }) {
|
|
13
|
+
function getDirNameSlug() {
|
|
18
14
|
const dirNameStripped = stripDirNumberPrefixes
|
|
19
|
-
? numberPrefix_1.stripPathNumberPrefixes(
|
|
20
|
-
:
|
|
21
|
-
const resolveDirname =
|
|
15
|
+
? (0, numberPrefix_1.stripPathNumberPrefixes)(sourceDirName, numberPrefixParser)
|
|
16
|
+
: sourceDirName;
|
|
17
|
+
const resolveDirname = sourceDirName === '.'
|
|
22
18
|
? '/'
|
|
23
|
-
: utils_1.addLeadingSlash(utils_1.addTrailingSlash(dirNameStripped));
|
|
24
|
-
|
|
19
|
+
: (0, utils_1.addLeadingSlash)((0, utils_1.addTrailingSlash)(dirNameStripped));
|
|
20
|
+
return resolveDirname;
|
|
21
|
+
}
|
|
22
|
+
function computeSlug() {
|
|
23
|
+
if (frontmatterSlug === null || frontmatterSlug === void 0 ? void 0 : frontmatterSlug.startsWith('/')) {
|
|
24
|
+
return frontmatterSlug;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const dirNameSlug = getDirNameSlug();
|
|
28
|
+
if (!frontmatterSlug && (0, docs_1.isConventionalDocIndex)({ source, sourceDirName })) {
|
|
29
|
+
return dirNameSlug;
|
|
30
|
+
}
|
|
31
|
+
const baseSlug = frontmatterSlug || baseID;
|
|
32
|
+
return (0, utils_1.resolvePathname)(baseSlug, getDirNameSlug());
|
|
33
|
+
}
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
function ensureValidSlug(slug) {
|
|
36
|
+
if (!(0, utils_1.isValidPathname)(slug)) {
|
|
37
|
+
throw new Error(`We couldn't compute a valid slug for document with id "${baseID}" in "${sourceDirName}" directory.
|
|
28
38
|
The slug we computed looks invalid: ${slug}.
|
|
29
39
|
Maybe your slug frontmatter is incorrect or you use weird chars in the file path?
|
|
30
40
|
By using the slug frontmatter, you should be able to fix this error, by using the slug of your choice:
|
|
@@ -34,7 +44,9 @@ Example =>
|
|
|
34
44
|
slug: /my/customDocPath
|
|
35
45
|
---
|
|
36
46
|
`);
|
|
47
|
+
}
|
|
48
|
+
return slug;
|
|
37
49
|
}
|
|
38
|
-
return
|
|
50
|
+
return ensureValidSlug(computeSlug());
|
|
39
51
|
}
|
|
40
52
|
exports.default = getSlug;
|
package/lib/tags.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { VersionTags, DocMetadata } from './types';
|
|
8
|
+
export declare function getVersionTags(docs: DocMetadata[]): VersionTags;
|
package/lib/tags.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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.getVersionTags = void 0;
|
|
10
|
+
const utils_1 = require("@docusaurus/utils");
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
12
|
+
function getVersionTags(docs) {
|
|
13
|
+
const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
|
|
14
|
+
return (0, lodash_1.mapValues)(groups, (group) => ({
|
|
15
|
+
name: group.tag.label,
|
|
16
|
+
docIds: group.items.map((item) => item.id),
|
|
17
|
+
permalink: group.tag.permalink,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
exports.getVersionTags = getVersionTags;
|
|
@@ -9,27 +9,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.useDocVersionSuggestions = exports.useActiveDocContext = exports.useActiveVersion = exports.useLatestVersion = exports.useVersions = exports.useActivePluginAndVersion = exports.useActivePlugin = exports.useDocsData = exports.useAllDocsData = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const router_1 = require("@docusaurus/router");
|
|
12
|
-
const useGlobalData_1 = tslib_1.__importStar(require("@docusaurus/useGlobalData"));
|
|
12
|
+
const useGlobalData_1 = (0, tslib_1.__importStar)(require("@docusaurus/useGlobalData"));
|
|
13
13
|
const docsClientUtils_1 = require("../../client/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 = {};
|
|
14
17
|
// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks are still used by the theme
|
|
15
18
|
// We need a fail-safe fallback when the docs plugin is not in use
|
|
16
19
|
const useAllDocsData = () => { var _a;
|
|
17
20
|
// useAllPluginInstancesData('docusaurus-plugin-content-docs');
|
|
18
|
-
return (_a = useGlobalData_1.default()['docusaurus-plugin-content-docs']) !== null && _a !== void 0 ? _a :
|
|
21
|
+
return (_a = (0, useGlobalData_1.default)()['docusaurus-plugin-content-docs']) !== null && _a !== void 0 ? _a : StableEmptyObject; };
|
|
19
22
|
exports.useAllDocsData = useAllDocsData;
|
|
20
|
-
const useDocsData = (pluginId) => useGlobalData_1.usePluginData('docusaurus-plugin-content-docs', pluginId);
|
|
23
|
+
const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId);
|
|
21
24
|
exports.useDocsData = useDocsData;
|
|
22
25
|
const useActivePlugin = (options = {}) => {
|
|
23
|
-
const data = exports.useAllDocsData();
|
|
24
|
-
const { pathname } = router_1.useLocation();
|
|
25
|
-
return docsClientUtils_1.getActivePlugin(data, pathname, options);
|
|
26
|
+
const data = (0, exports.useAllDocsData)();
|
|
27
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
28
|
+
return (0, docsClientUtils_1.getActivePlugin)(data, pathname, options);
|
|
26
29
|
};
|
|
27
30
|
exports.useActivePlugin = useActivePlugin;
|
|
28
31
|
const useActivePluginAndVersion = (options = {}) => {
|
|
29
|
-
const activePlugin = exports.useActivePlugin(options);
|
|
30
|
-
const { pathname } = router_1.useLocation();
|
|
32
|
+
const activePlugin = (0, exports.useActivePlugin)(options);
|
|
33
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
31
34
|
if (activePlugin) {
|
|
32
|
-
const activeVersion = docsClientUtils_1.getActiveVersion(activePlugin.pluginData, pathname);
|
|
35
|
+
const activeVersion = (0, docsClientUtils_1.getActiveVersion)(activePlugin.pluginData, pathname);
|
|
33
36
|
return {
|
|
34
37
|
activePlugin,
|
|
35
38
|
activeVersion,
|
|
@@ -40,33 +43,33 @@ const useActivePluginAndVersion = (options = {}) => {
|
|
|
40
43
|
exports.useActivePluginAndVersion = useActivePluginAndVersion;
|
|
41
44
|
// versions are returned ordered (most recent first)
|
|
42
45
|
const useVersions = (pluginId) => {
|
|
43
|
-
const data = exports.useDocsData(pluginId);
|
|
46
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
44
47
|
return data.versions;
|
|
45
48
|
};
|
|
46
49
|
exports.useVersions = useVersions;
|
|
47
50
|
const useLatestVersion = (pluginId) => {
|
|
48
|
-
const data = exports.useDocsData(pluginId);
|
|
49
|
-
return docsClientUtils_1.getLatestVersion(data);
|
|
51
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
52
|
+
return (0, docsClientUtils_1.getLatestVersion)(data);
|
|
50
53
|
};
|
|
51
54
|
exports.useLatestVersion = useLatestVersion;
|
|
52
55
|
// Note: return undefined on doc-unrelated pages,
|
|
53
56
|
// because there's no version currently considered as active
|
|
54
57
|
const useActiveVersion = (pluginId) => {
|
|
55
|
-
const data = exports.useDocsData(pluginId);
|
|
56
|
-
const { pathname } = router_1.useLocation();
|
|
57
|
-
return docsClientUtils_1.getActiveVersion(data, pathname);
|
|
58
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
59
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
60
|
+
return (0, docsClientUtils_1.getActiveVersion)(data, pathname);
|
|
58
61
|
};
|
|
59
62
|
exports.useActiveVersion = useActiveVersion;
|
|
60
63
|
const useActiveDocContext = (pluginId) => {
|
|
61
|
-
const data = exports.useDocsData(pluginId);
|
|
62
|
-
const { pathname } = router_1.useLocation();
|
|
63
|
-
return docsClientUtils_1.getActiveDocContext(data, pathname);
|
|
64
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
65
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
66
|
+
return (0, docsClientUtils_1.getActiveDocContext)(data, pathname);
|
|
64
67
|
};
|
|
65
68
|
exports.useActiveDocContext = useActiveDocContext;
|
|
66
69
|
// Useful to say "hey, you are not on the latest docs version, please switch"
|
|
67
70
|
const useDocVersionSuggestions = (pluginId) => {
|
|
68
|
-
const data = exports.useDocsData(pluginId);
|
|
69
|
-
const { pathname } = router_1.useLocation();
|
|
70
|
-
return docsClientUtils_1.getDocVersionSuggestions(data, pathname);
|
|
71
|
+
const data = (0, exports.useDocsData)(pluginId);
|
|
72
|
+
const { pathname } = (0, router_1.useLocation)();
|
|
73
|
+
return (0, docsClientUtils_1.getDocVersionSuggestions)(data, pathname);
|
|
71
74
|
};
|
|
72
75
|
exports.useDocVersionSuggestions = useDocVersionSuggestions;
|
package/lib/translations.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 { LoadedContent } from './types';
|
|
8
|
-
import { TranslationFile, TranslationFiles } from '@docusaurus/types';
|
|
7
|
+
import type { LoadedContent } from './types';
|
|
8
|
+
import type { TranslationFile, TranslationFiles } from '@docusaurus/types';
|
|
9
9
|
export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent): TranslationFiles;
|
|
10
10
|
export declare function translateLoadedContent(loadedContent: LoadedContent, translationFiles: TranslationFile[]): LoadedContent;
|
package/lib/translations.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const utils_1 = require("./sidebars/utils");
|
|
12
|
+
const utils_2 = require("@docusaurus/utils");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
14
|
function getVersionFileName(versionName) {
|
|
15
15
|
if (versionName === constants_1.CURRENT_VERSION_NAME) {
|
|
@@ -32,7 +32,7 @@ function getNormalizedSidebarName({ versionName, sidebarName, }) {
|
|
|
32
32
|
return rest.join('/');
|
|
33
33
|
}
|
|
34
34
|
/*
|
|
35
|
-
// Do we need to translate doc
|
|
35
|
+
// Do we need to translate doc metadata?
|
|
36
36
|
// It seems translating frontmatter labels is good enough
|
|
37
37
|
function getDocTranslations(doc: DocMetadata): TranslationFileContent {
|
|
38
38
|
return {
|
|
@@ -74,31 +74,75 @@ function translateDocs(
|
|
|
74
74
|
}
|
|
75
75
|
*/
|
|
76
76
|
function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
77
|
-
const categories =
|
|
78
|
-
const categoryContent =
|
|
79
|
-
|
|
80
|
-
.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
const categories = (0, utils_1.collectSidebarCategories)(sidebar);
|
|
78
|
+
const categoryContent = Object.fromEntries(categories.flatMap((category) => {
|
|
79
|
+
const entries = [];
|
|
80
|
+
entries.push([
|
|
81
|
+
`sidebar.${sidebarName}.category.${category.label}`,
|
|
82
|
+
{
|
|
83
|
+
message: category.label,
|
|
84
|
+
description: `The label for category ${category.label} in sidebar ${sidebarName}`,
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
if (category.link) {
|
|
88
|
+
if (category.link.type === 'generated-index') {
|
|
89
|
+
if (category.link.title) {
|
|
90
|
+
entries.push([
|
|
91
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`,
|
|
92
|
+
{
|
|
93
|
+
message: category.link.title,
|
|
94
|
+
description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`,
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
if (category.link.description) {
|
|
99
|
+
entries.push([
|
|
100
|
+
`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`,
|
|
101
|
+
{
|
|
102
|
+
message: category.link.description,
|
|
103
|
+
description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`,
|
|
104
|
+
},
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return entries;
|
|
110
|
+
}));
|
|
111
|
+
const links = (0, utils_1.collectSidebarLinks)(sidebar);
|
|
112
|
+
const linksContent = (0, lodash_1.chain)(links)
|
|
87
113
|
.keyBy((link) => `sidebar.${sidebarName}.link.${link.label}`)
|
|
88
114
|
.mapValues((link) => ({
|
|
89
115
|
message: link.label,
|
|
90
116
|
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
91
117
|
}))
|
|
92
118
|
.value();
|
|
93
|
-
return
|
|
119
|
+
return (0, utils_2.mergeTranslations)([categoryContent, linksContent]);
|
|
94
120
|
}
|
|
95
121
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
96
|
-
|
|
122
|
+
function transformSidebarCategoryLink(category) {
|
|
123
|
+
var _a, _b, _c, _d;
|
|
124
|
+
if (!category.link) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
if (category.link.type === 'generated-index') {
|
|
128
|
+
const title = (_b = (_a = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : category.link.title;
|
|
129
|
+
const description = (_d = (_c = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`]) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : category.link.description;
|
|
130
|
+
return {
|
|
131
|
+
...category.link,
|
|
132
|
+
title,
|
|
133
|
+
description,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return category.link;
|
|
137
|
+
}
|
|
138
|
+
return (0, utils_1.transformSidebarItems)(sidebar, (item) => {
|
|
97
139
|
var _a, _b, _c, _d;
|
|
98
140
|
if (item.type === 'category') {
|
|
141
|
+
const link = transformSidebarCategoryLink(item);
|
|
99
142
|
return {
|
|
100
143
|
...item,
|
|
101
144
|
label: (_b = (_a = sidebarsTranslations[`sidebar.${sidebarName}.category.${item.label}`]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : item.label,
|
|
145
|
+
...(link && { link }),
|
|
102
146
|
};
|
|
103
147
|
}
|
|
104
148
|
if (item.type === 'link') {
|
|
@@ -111,7 +155,7 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
|
111
155
|
});
|
|
112
156
|
}
|
|
113
157
|
function getSidebarsTranslations(version) {
|
|
114
|
-
return
|
|
158
|
+
return (0, utils_2.mergeTranslations)(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
|
|
115
159
|
const normalizedSidebarName = getNormalizedSidebarName({
|
|
116
160
|
sidebarName,
|
|
117
161
|
versionName: version.versionName,
|
|
@@ -120,16 +164,14 @@ function getSidebarsTranslations(version) {
|
|
|
120
164
|
}));
|
|
121
165
|
}
|
|
122
166
|
function translateSidebars(version, sidebarsTranslations) {
|
|
123
|
-
return lodash_1.mapValues(version.sidebars, (sidebar, sidebarName) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
sidebarName
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
});
|
|
167
|
+
return (0, lodash_1.mapValues)(version.sidebars, (sidebar, sidebarName) => translateSidebar({
|
|
168
|
+
sidebar,
|
|
169
|
+
sidebarName: getNormalizedSidebarName({
|
|
170
|
+
sidebarName,
|
|
171
|
+
versionName: version.versionName,
|
|
172
|
+
}),
|
|
173
|
+
sidebarsTranslations,
|
|
174
|
+
}));
|
|
133
175
|
}
|
|
134
176
|
function getVersionTranslationFiles(version) {
|
|
135
177
|
const versionTranslations = {
|
|
@@ -143,7 +185,7 @@ function getVersionTranslationFiles(version) {
|
|
|
143
185
|
return [
|
|
144
186
|
{
|
|
145
187
|
path: getVersionFileName(version.versionName),
|
|
146
|
-
content:
|
|
188
|
+
content: (0, utils_2.mergeTranslations)([
|
|
147
189
|
versionTranslations,
|
|
148
190
|
sidebarsTranslations,
|
|
149
191
|
// docsTranslations,
|
|
@@ -162,7 +204,7 @@ function translateVersion(version, translationFiles) {
|
|
|
162
204
|
};
|
|
163
205
|
}
|
|
164
206
|
function getVersionsTranslationFiles(versions) {
|
|
165
|
-
return
|
|
207
|
+
return versions.flatMap(getVersionTranslationFiles);
|
|
166
208
|
}
|
|
167
209
|
function translateVersions(versions, translationFiles) {
|
|
168
210
|
return versions.map((version) => translateVersion(version, translationFiles));
|
|
@@ -172,7 +214,7 @@ function getLoadedContentTranslationFiles(loadedContent) {
|
|
|
172
214
|
}
|
|
173
215
|
exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
|
|
174
216
|
function translateLoadedContent(loadedContent, translationFiles) {
|
|
175
|
-
const translationFilesMap = lodash_1.keyBy(translationFiles, (f) => f.path);
|
|
217
|
+
const translationFilesMap = (0, lodash_1.keyBy)(translationFiles, (f) => f.path);
|
|
176
218
|
return {
|
|
177
219
|
loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
|
|
178
220
|
};
|
package/lib/types.d.ts
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { RemarkAndRehypePluginOptions } from '@docusaurus/mdx-loader';
|
|
8
|
-
import {
|
|
8
|
+
import type { Tag, FrontMatterTag, Slugger } from '@docusaurus/utils';
|
|
9
|
+
import type { BrokenMarkdownLink as IBrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
|
|
10
|
+
import type { SidebarItemsGeneratorOption, Sidebars } from './sidebars/types';
|
|
9
11
|
export declare type DocFile = {
|
|
10
12
|
contentPath: string;
|
|
11
13
|
filePath: string;
|
|
@@ -18,8 +20,12 @@ export declare type VersionMetadata = ContentPaths & {
|
|
|
18
20
|
versionName: VersionName;
|
|
19
21
|
versionLabel: string;
|
|
20
22
|
versionPath: string;
|
|
23
|
+
tagsPath: string;
|
|
21
24
|
versionEditUrl?: string | undefined;
|
|
22
25
|
versionEditUrlLocalized?: string | undefined;
|
|
26
|
+
versionBanner: VersionBanner | null;
|
|
27
|
+
versionBadge: boolean;
|
|
28
|
+
versionClassName: string;
|
|
23
29
|
isLast: boolean;
|
|
24
30
|
sidebarFilePath: string | false | undefined;
|
|
25
31
|
routePriority: number | undefined;
|
|
@@ -33,7 +39,6 @@ export declare type EditUrlFunction = (editUrlParams: {
|
|
|
33
39
|
}) => string | undefined;
|
|
34
40
|
export declare type MetadataOptions = {
|
|
35
41
|
routeBasePath: string;
|
|
36
|
-
homePageId?: string;
|
|
37
42
|
editUrl?: string | EditUrlFunction;
|
|
38
43
|
editCurrentVersion: boolean;
|
|
39
44
|
editLocalizedFiles: boolean;
|
|
@@ -45,79 +50,41 @@ export declare type PathOptions = {
|
|
|
45
50
|
path: string;
|
|
46
51
|
sidebarPath?: string | false | undefined;
|
|
47
52
|
};
|
|
53
|
+
export declare type VersionBanner = 'unreleased' | 'unmaintained';
|
|
48
54
|
export declare type VersionOptions = {
|
|
49
55
|
path?: string;
|
|
50
56
|
label?: string;
|
|
57
|
+
banner?: 'none' | VersionBanner;
|
|
58
|
+
badge?: boolean;
|
|
59
|
+
className?: string;
|
|
51
60
|
};
|
|
52
61
|
export declare type VersionsOptions = {
|
|
53
62
|
lastVersion?: string;
|
|
54
63
|
versions: Record<string, VersionOptions>;
|
|
55
64
|
onlyIncludeVersions?: string[];
|
|
56
65
|
};
|
|
57
|
-
export declare type
|
|
66
|
+
export declare type SidebarOptions = {
|
|
67
|
+
sidebarCollapsible: boolean;
|
|
68
|
+
sidebarCollapsed: boolean;
|
|
69
|
+
};
|
|
70
|
+
export declare type NormalizeSidebarsParams = SidebarOptions & {
|
|
71
|
+
version: VersionMetadata;
|
|
72
|
+
categoryLabelSlugger: Slugger;
|
|
73
|
+
};
|
|
74
|
+
export declare type PluginOptions = MetadataOptions & PathOptions & VersionsOptions & RemarkAndRehypePluginOptions & SidebarOptions & {
|
|
58
75
|
id: string;
|
|
59
76
|
include: string[];
|
|
77
|
+
exclude: string[];
|
|
60
78
|
docLayoutComponent: string;
|
|
61
79
|
docItemComponent: string;
|
|
80
|
+
docTagDocListComponent: string;
|
|
81
|
+
docTagsListComponent: string;
|
|
82
|
+
docCategoryGeneratedIndexComponent: string;
|
|
62
83
|
admonitions: Record<string, unknown>;
|
|
63
84
|
disableVersioning: boolean;
|
|
64
|
-
excludeNextVersionDocs?: boolean;
|
|
65
85
|
includeCurrentVersion: boolean;
|
|
66
86
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
67
|
-
|
|
68
|
-
export declare type SidebarItemBase = {
|
|
69
|
-
customProps?: Record<string, unknown>;
|
|
70
|
-
};
|
|
71
|
-
export declare type SidebarItemDoc = SidebarItemBase & {
|
|
72
|
-
type: 'doc' | 'ref';
|
|
73
|
-
label?: string;
|
|
74
|
-
id: string;
|
|
75
|
-
};
|
|
76
|
-
export declare type SidebarItemLink = SidebarItemBase & {
|
|
77
|
-
type: 'link';
|
|
78
|
-
href: string;
|
|
79
|
-
label: string;
|
|
80
|
-
};
|
|
81
|
-
export declare type SidebarItemCategory = SidebarItemBase & {
|
|
82
|
-
type: 'category';
|
|
83
|
-
label: string;
|
|
84
|
-
items: SidebarItem[];
|
|
85
|
-
collapsed: boolean;
|
|
86
|
-
};
|
|
87
|
-
export declare type UnprocessedSidebarItemAutogenerated = {
|
|
88
|
-
type: 'autogenerated';
|
|
89
|
-
dirName: string;
|
|
90
|
-
};
|
|
91
|
-
export declare type UnprocessedSidebarItemCategory = SidebarItemBase & {
|
|
92
|
-
type: 'category';
|
|
93
|
-
label: string;
|
|
94
|
-
items: UnprocessedSidebarItem[];
|
|
95
|
-
collapsed: boolean;
|
|
96
|
-
};
|
|
97
|
-
export declare type UnprocessedSidebarItem = SidebarItemDoc | SidebarItemLink | UnprocessedSidebarItemCategory | UnprocessedSidebarItemAutogenerated;
|
|
98
|
-
export declare type UnprocessedSidebar = UnprocessedSidebarItem[];
|
|
99
|
-
export declare type UnprocessedSidebars = Record<string, UnprocessedSidebar>;
|
|
100
|
-
export declare type SidebarItem = SidebarItemDoc | SidebarItemLink | SidebarItemCategory;
|
|
101
|
-
export declare type Sidebar = SidebarItem[];
|
|
102
|
-
export declare type SidebarItemType = SidebarItem['type'];
|
|
103
|
-
export declare type Sidebars = Record<string, Sidebar>;
|
|
104
|
-
export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
|
|
105
|
-
export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
|
|
106
|
-
export declare type SidebarItemsGeneratorArgs = {
|
|
107
|
-
item: UnprocessedSidebarItemAutogenerated;
|
|
108
|
-
version: SidebarItemsGeneratorVersion;
|
|
109
|
-
docs: SidebarItemsGeneratorDoc[];
|
|
110
|
-
numberPrefixParser: NumberPrefixParser;
|
|
111
|
-
};
|
|
112
|
-
export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
|
|
113
|
-
export declare type SidebarItemsGeneratorOptionArgs = {
|
|
114
|
-
defaultSidebarItemsGenerator: SidebarItemsGenerator;
|
|
115
|
-
} & SidebarItemsGeneratorArgs;
|
|
116
|
-
export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<SidebarItem[]>;
|
|
117
|
-
export declare type OrderMetadata = {
|
|
118
|
-
previous?: string;
|
|
119
|
-
next?: string;
|
|
120
|
-
sidebar?: string;
|
|
87
|
+
tagsBasePath: string;
|
|
121
88
|
};
|
|
122
89
|
export declare type LastUpdateData = {
|
|
123
90
|
lastUpdatedAt?: number;
|
|
@@ -127,6 +94,7 @@ export declare type LastUpdateData = {
|
|
|
127
94
|
export declare type DocFrontMatter = {
|
|
128
95
|
id?: string;
|
|
129
96
|
title?: string;
|
|
97
|
+
tags?: FrontMatterTag[];
|
|
130
98
|
hide_title?: boolean;
|
|
131
99
|
hide_table_of_contents?: boolean;
|
|
132
100
|
keywords?: string[];
|
|
@@ -135,15 +103,19 @@ export declare type DocFrontMatter = {
|
|
|
135
103
|
slug?: string;
|
|
136
104
|
sidebar_label?: string;
|
|
137
105
|
sidebar_position?: number;
|
|
106
|
+
sidebar_class_name?: string;
|
|
138
107
|
pagination_label?: string;
|
|
139
108
|
custom_edit_url?: string | null;
|
|
140
109
|
parse_number_prefixes?: boolean;
|
|
110
|
+
toc_min_heading_level?: number;
|
|
111
|
+
toc_max_heading_level?: number;
|
|
112
|
+
pagination_next?: string | null;
|
|
113
|
+
pagination_prev?: string | null;
|
|
141
114
|
};
|
|
142
115
|
export declare type DocMetadataBase = LastUpdateData & {
|
|
143
|
-
version: VersionName;
|
|
144
|
-
unversionedId: string;
|
|
145
116
|
id: string;
|
|
146
|
-
|
|
117
|
+
unversionedId: string;
|
|
118
|
+
version: VersionName;
|
|
147
119
|
title: string;
|
|
148
120
|
description: string;
|
|
149
121
|
source: string;
|
|
@@ -152,6 +124,7 @@ export declare type DocMetadataBase = LastUpdateData & {
|
|
|
152
124
|
permalink: string;
|
|
153
125
|
sidebarPosition?: number;
|
|
154
126
|
editUrl?: string | null;
|
|
127
|
+
tags: Tag[];
|
|
155
128
|
frontMatter: DocFrontMatter & Record<string, unknown>;
|
|
156
129
|
};
|
|
157
130
|
export declare type DocNavLink = {
|
|
@@ -163,15 +136,32 @@ export declare type DocMetadata = DocMetadataBase & {
|
|
|
163
136
|
previous?: DocNavLink;
|
|
164
137
|
next?: DocNavLink;
|
|
165
138
|
};
|
|
139
|
+
export declare type CategoryGeneratedIndexMetadata = {
|
|
140
|
+
title: string;
|
|
141
|
+
description?: string;
|
|
142
|
+
slug: string;
|
|
143
|
+
permalink: string;
|
|
144
|
+
sidebar: string;
|
|
145
|
+
previous?: DocNavLink;
|
|
146
|
+
next?: DocNavLink;
|
|
147
|
+
};
|
|
166
148
|
export declare type SourceToPermalink = {
|
|
167
149
|
[source: string]: string;
|
|
168
150
|
};
|
|
151
|
+
export declare type VersionTag = {
|
|
152
|
+
name: string;
|
|
153
|
+
docIds: string[];
|
|
154
|
+
permalink: string;
|
|
155
|
+
};
|
|
156
|
+
export declare type VersionTags = {
|
|
157
|
+
[key: string]: VersionTag;
|
|
158
|
+
};
|
|
169
159
|
export declare type LoadedVersion = VersionMetadata & {
|
|
170
160
|
versionPath: string;
|
|
171
161
|
mainDocId: string;
|
|
172
162
|
docs: DocMetadata[];
|
|
173
163
|
sidebars: Sidebars;
|
|
174
|
-
|
|
164
|
+
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
175
165
|
};
|
|
176
166
|
export declare type LoadedContent = {
|
|
177
167
|
loadedVersions: LoadedVersion[];
|
package/lib/versions.d.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
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 { PluginOptions, VersionMetadata } from './types';
|
|
8
|
-
import { LoadContext } from '@docusaurus/types';
|
|
7
|
+
import type { PluginOptions, VersionMetadata } from './types';
|
|
8
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
9
9
|
export declare function getVersionedDocsDirPath(siteDir: string, pluginId: string): string;
|
|
10
10
|
export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: string): string;
|
|
11
11
|
export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
|
|
12
12
|
export declare function readVersionsMetadata({ context, options, }: {
|
|
13
13
|
context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
|
|
14
|
-
options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
|
|
14
|
+
options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'tagsBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
|
|
15
15
|
}): VersionMetadata[];
|
|
16
16
|
export declare function getDocsDirPaths(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>): [string, string];
|