@docusaurus/plugin-content-docs 0.0.0-4608 → 0.0.0-4614
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/cli.js +9 -8
- package/lib/docs.js +4 -5
- package/lib/globalData.js +3 -2
- package/lib/index.js +6 -2
- package/lib/props.js +13 -9
- package/lib/sidebars/generator.js +3 -3
- package/lib/sidebars/index.js +4 -4
- package/lib/sidebars/normalization.js +3 -2
- package/lib/sidebars/postProcessor.js +3 -2
- package/lib/sidebars/processor.js +5 -5
- package/lib/sidebars/utils.js +6 -5
- package/lib/tags.js +3 -2
- package/lib/translations.js +11 -10
- package/lib/versions.js +7 -7
- package/package.json +9 -9
- package/src/cli.ts +14 -8
- package/src/docs.ts +6 -5
- package/src/globalData.ts +2 -2
- package/src/index.ts +12 -4
- package/src/props.ts +15 -11
- package/src/sidebars/generator.ts +3 -3
- package/src/sidebars/index.ts +4 -4
- package/src/sidebars/normalization.ts +2 -2
- package/src/sidebars/postProcessor.ts +2 -2
- package/src/sidebars/processor.ts +5 -5
- package/src/sidebars/utils.ts +5 -5
- package/src/tags.ts +2 -2
- package/src/translations.ts +12 -10
- package/src/versions.ts +10 -8
package/lib/cli.js
CHANGED
|
@@ -26,8 +26,8 @@ async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, vers
|
|
|
26
26
|
if (shouldCreateVersionedSidebarFile) {
|
|
27
27
|
const versionedSidebarsDir = (0, versions_1.getVersionedSidebarsDirPath)(siteDir, pluginId);
|
|
28
28
|
const newSidebarFile = path_1.default.join(versionedSidebarsDir, `version-${version}-sidebars.json`);
|
|
29
|
-
fs_extra_1.default.
|
|
30
|
-
fs_extra_1.default.
|
|
29
|
+
await fs_extra_1.default.ensureDir(path_1.default.dirname(newSidebarFile));
|
|
30
|
+
await fs_extra_1.default.writeFile(newSidebarFile, `${JSON.stringify(sidebars, null, 2)}\n`, 'utf8');
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
// Tests depend on non-default export for mocking.
|
|
@@ -56,8 +56,8 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
56
56
|
// Load existing versions.
|
|
57
57
|
let versions = [];
|
|
58
58
|
const versionsJSONFile = (0, versions_1.getVersionsFilePath)(siteDir, pluginId);
|
|
59
|
-
if (fs_extra_1.default.
|
|
60
|
-
versions = JSON.parse(fs_extra_1.default.
|
|
59
|
+
if (await fs_extra_1.default.pathExists(versionsJSONFile)) {
|
|
60
|
+
versions = JSON.parse(await fs_extra_1.default.readFile(versionsJSONFile, 'utf8'));
|
|
61
61
|
}
|
|
62
62
|
// Check if version already exists.
|
|
63
63
|
if (versions.includes(version)) {
|
|
@@ -66,10 +66,11 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
66
66
|
const { path: docsPath, sidebarPath } = options;
|
|
67
67
|
// Copy docs files.
|
|
68
68
|
const docsDir = path_1.default.join(siteDir, docsPath);
|
|
69
|
-
if (
|
|
69
|
+
if ((await fs_extra_1.default.pathExists(docsDir)) &&
|
|
70
|
+
(await fs_extra_1.default.readdir(docsDir)).length > 0) {
|
|
70
71
|
const versionedDir = (0, versions_1.getVersionedDocsDirPath)(siteDir, pluginId);
|
|
71
72
|
const newVersionDir = path_1.default.join(versionedDir, `version-${version}`);
|
|
72
|
-
fs_extra_1.default.
|
|
73
|
+
await fs_extra_1.default.copy(docsDir, newVersionDir);
|
|
73
74
|
}
|
|
74
75
|
else {
|
|
75
76
|
throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
|
|
@@ -82,8 +83,8 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
82
83
|
});
|
|
83
84
|
// Update versions.json file.
|
|
84
85
|
versions.unshift(version);
|
|
85
|
-
fs_extra_1.default.
|
|
86
|
-
fs_extra_1.default.
|
|
86
|
+
await fs_extra_1.default.ensureDir(path_1.default.dirname(versionsJSONFile));
|
|
87
|
+
await fs_extra_1.default.writeFile(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
|
|
87
88
|
logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
|
|
88
89
|
}
|
|
89
90
|
exports.cliDocsVersionCommand = cliDocsVersionCommand;
|
package/lib/docs.js
CHANGED
|
@@ -11,7 +11,6 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
12
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
13
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
14
|
-
const lodash_1 = require("lodash");
|
|
15
14
|
const utils_1 = require("@docusaurus/utils");
|
|
16
15
|
const lastUpdate_1 = require("./lastUpdate");
|
|
17
16
|
const slug_1 = (0, tslib_1.__importDefault)(require("./slug"));
|
|
@@ -285,9 +284,9 @@ exports.getDocIds = getDocIds;
|
|
|
285
284
|
// versioned doc ids ("id" should be removed & "versionedId" should be renamed
|
|
286
285
|
// to "id")
|
|
287
286
|
function createDocsByIdIndex(docs) {
|
|
288
|
-
return
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
287
|
+
return Object.fromEntries(docs.flatMap((doc) => [
|
|
288
|
+
[doc.unversionedId, doc],
|
|
289
|
+
[doc.id, doc],
|
|
290
|
+
]));
|
|
292
291
|
}
|
|
293
292
|
exports.createDocsByIdIndex = createDocsByIdIndex;
|
package/lib/globalData.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.toGlobalDataVersion = exports.toGlobalSidebars = exports.toGlobalDataGeneratedIndex = exports.toGlobalDataDoc = void 0;
|
|
10
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
11
12
|
const utils_1 = require("@docusaurus/utils");
|
|
12
13
|
const utils_2 = require("./sidebars/utils");
|
|
13
14
|
function toGlobalDataDoc(doc) {
|
|
@@ -28,7 +29,7 @@ function toGlobalDataGeneratedIndex(doc) {
|
|
|
28
29
|
exports.toGlobalDataGeneratedIndex = toGlobalDataGeneratedIndex;
|
|
29
30
|
function toGlobalSidebars(sidebars, version) {
|
|
30
31
|
const { getFirstLink } = (0, utils_2.createSidebarsUtils)(sidebars);
|
|
31
|
-
return
|
|
32
|
+
return lodash_1.default.mapValues(sidebars, (sidebar, sidebarId) => {
|
|
32
33
|
const firstLink = getFirstLink(sidebarId);
|
|
33
34
|
if (!firstLink) {
|
|
34
35
|
return {};
|
package/lib/index.js
CHANGED
|
@@ -16,7 +16,6 @@ const docs_1 = require("./docs");
|
|
|
16
16
|
const versions_1 = require("./versions");
|
|
17
17
|
const cli_1 = require("./cli");
|
|
18
18
|
const constants_1 = require("./constants");
|
|
19
|
-
const lodash_1 = require("lodash");
|
|
20
19
|
const globalData_1 = require("./globalData");
|
|
21
20
|
const props_1 = require("./props");
|
|
22
21
|
const translations_1 = require("./translations");
|
|
@@ -199,7 +198,7 @@ async function pluginContentDocs(context, options) {
|
|
|
199
198
|
const { rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
|
|
200
199
|
function getSourceToPermalink() {
|
|
201
200
|
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
202
|
-
return (
|
|
201
|
+
return Object.fromEntries(allDocs.map(({ source, permalink }) => [source, permalink]));
|
|
203
202
|
}
|
|
204
203
|
const docsMarkdownOptions = {
|
|
205
204
|
siteDir,
|
|
@@ -237,6 +236,11 @@ async function pluginContentDocs(context, options) {
|
|
|
237
236
|
const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
|
|
238
237
|
return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
|
|
239
238
|
},
|
|
239
|
+
// Assets allow to convert some relative images paths to
|
|
240
|
+
// require(...) calls
|
|
241
|
+
createAssets: ({ frontMatter, }) => ({
|
|
242
|
+
image: frontMatter.image,
|
|
243
|
+
}),
|
|
240
244
|
},
|
|
241
245
|
},
|
|
242
246
|
{
|
package/lib/props.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.toTagDocListProp = exports.toVersionMetadataProp = exports.toSidebarsProp = void 0;
|
|
10
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
11
12
|
const docs_1 = require("./docs");
|
|
12
13
|
function toSidebarsProp(loadedVersion) {
|
|
13
14
|
const docsById = (0, docs_1.createDocsByIdIndex)(loadedVersion.docs);
|
|
@@ -63,16 +64,19 @@ Available document ids are:
|
|
|
63
64
|
// Transform the sidebar so that all sidebar item will be in the
|
|
64
65
|
// form of 'link' or 'category' only.
|
|
65
66
|
// This is what will be passed as props to the UI component.
|
|
66
|
-
return
|
|
67
|
+
return lodash_1.default.mapValues(loadedVersion.sidebars, (items) => items.map(normalizeItem));
|
|
67
68
|
}
|
|
68
69
|
exports.toSidebarsProp = toSidebarsProp;
|
|
69
70
|
function toVersionDocsProp(loadedVersion) {
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
return Object.fromEntries(loadedVersion.docs.map((doc) => [
|
|
72
|
+
doc.unversionedId,
|
|
73
|
+
{
|
|
74
|
+
id: doc.unversionedId,
|
|
75
|
+
title: doc.title,
|
|
76
|
+
description: doc.description,
|
|
77
|
+
sidebar: doc.sidebar,
|
|
78
|
+
},
|
|
79
|
+
]));
|
|
76
80
|
}
|
|
77
81
|
function toVersionMetadataProp(pluginId, loadedVersion) {
|
|
78
82
|
return {
|
|
@@ -90,7 +94,7 @@ function toVersionMetadataProp(pluginId, loadedVersion) {
|
|
|
90
94
|
exports.toVersionMetadataProp = toVersionMetadataProp;
|
|
91
95
|
function toTagDocListProp({ allTagsPath, tag, docs, }) {
|
|
92
96
|
function toDocListProp() {
|
|
93
|
-
const list =
|
|
97
|
+
const list = lodash_1.default.compact(tag.docIds.map((id) => docs.find((doc) => doc.id === id)));
|
|
94
98
|
// Sort docs by title
|
|
95
99
|
list.sort((doc1, doc2) => doc1.title.localeCompare(doc2.title));
|
|
96
100
|
return list.map((doc) => ({
|
|
@@ -8,7 +8,7 @@
|
|
|
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 lodash_1 = require("lodash");
|
|
11
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
14
14
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
@@ -18,7 +18,7 @@ const BreadcrumbSeparator = '/';
|
|
|
18
18
|
const docIdPrefix = '$doc$/';
|
|
19
19
|
// Just an alias to the make code more explicit
|
|
20
20
|
function getLocalDocId(docId) {
|
|
21
|
-
return
|
|
21
|
+
return lodash_1.default.last(docId.split('/'));
|
|
22
22
|
}
|
|
23
23
|
exports.CategoryMetadataFilenameBase = '_category_';
|
|
24
24
|
exports.CategoryMetadataFilenamePattern = '_category_.{json,yml,yaml}';
|
|
@@ -177,7 +177,7 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryInde
|
|
|
177
177
|
}
|
|
178
178
|
return item;
|
|
179
179
|
});
|
|
180
|
-
const sortedSidebarItems =
|
|
180
|
+
const sortedSidebarItems = lodash_1.default.sortBy(processedSidebarItems, (item) => item.position);
|
|
181
181
|
return sortedSidebarItems.map(({ position, ...item }) => item);
|
|
182
182
|
}
|
|
183
183
|
// TODO: the whole code is designed for pipeline operator
|
package/lib/sidebars/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
|
18
18
|
const utils_1 = require("@docusaurus/utils");
|
|
19
19
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
20
20
|
const js_yaml_1 = (0, tslib_1.__importDefault)(require("js-yaml"));
|
|
21
|
-
const lodash_1 = require("lodash");
|
|
21
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
22
22
|
const combine_promises_1 = (0, tslib_1.__importDefault)(require("combine-promises"));
|
|
23
23
|
exports.DefaultSidebars = {
|
|
24
24
|
defaultSidebar: [
|
|
@@ -41,8 +41,8 @@ async function readCategoriesMetadata(contentPath) {
|
|
|
41
41
|
const categoryFiles = await (0, utils_1.Globby)('**/_category_.{json,yml,yaml}', {
|
|
42
42
|
cwd: contentPath,
|
|
43
43
|
});
|
|
44
|
-
const categoryToFile =
|
|
45
|
-
return (0, combine_promises_1.default)(
|
|
44
|
+
const categoryToFile = lodash_1.default.groupBy(categoryFiles, path_1.default.dirname);
|
|
45
|
+
return (0, combine_promises_1.default)(lodash_1.default.mapValues(categoryToFile, async (files, folder) => {
|
|
46
46
|
const [filePath] = files;
|
|
47
47
|
if (files.length > 1) {
|
|
48
48
|
logger_1.default.warn `There are more than one category metadata files for path=${folder}: ${files.join(', ')}. The behavior is undetermined.`;
|
|
@@ -69,7 +69,7 @@ async function loadSidebarsFileUnsafe(sidebarFilePath) {
|
|
|
69
69
|
// Non-existent sidebars file: no sidebars
|
|
70
70
|
// Note: this edge case can happen on versioned docs, not current version
|
|
71
71
|
// We avoid creating empty versioned sidebars file with the CLI
|
|
72
|
-
if (!fs_extra_1.default.
|
|
72
|
+
if (!(await fs_extra_1.default.pathExists(sidebarFilePath))) {
|
|
73
73
|
return exports.DisabledSidebars;
|
|
74
74
|
}
|
|
75
75
|
// We don't want sidebars to be cached because of hot reloading.
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.normalizeSidebars = exports.normalizeItem = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
10
11
|
const utils_1 = require("./utils");
|
|
11
|
-
const lodash_1 = require("lodash");
|
|
12
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
12
13
|
function normalizeCategoriesShorthand(sidebar) {
|
|
13
14
|
return Object.entries(sidebar).map(([label, items]) => ({
|
|
14
15
|
type: 'category',
|
|
@@ -54,6 +55,6 @@ function normalizeSidebar(sidebar) {
|
|
|
54
55
|
return normalizedSidebar.flatMap((subItem) => normalizeItem(subItem));
|
|
55
56
|
}
|
|
56
57
|
function normalizeSidebars(sidebars) {
|
|
57
|
-
return
|
|
58
|
+
return lodash_1.default.mapValues(sidebars, normalizeSidebar);
|
|
58
59
|
}
|
|
59
60
|
exports.normalizeSidebars = normalizeSidebars;
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.postProcessSidebars = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
10
11
|
const utils_1 = require("@docusaurus/utils");
|
|
11
|
-
const lodash_1 = require("lodash");
|
|
12
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
12
13
|
function normalizeCategoryLink(category, params) {
|
|
13
14
|
var _a, _b;
|
|
14
15
|
if (((_a = category.link) === null || _a === void 0 ? void 0 : _a.type) === 'generated-index') {
|
|
@@ -66,6 +67,6 @@ function postProcessSidebarItem(item, params) {
|
|
|
66
67
|
return item;
|
|
67
68
|
}
|
|
68
69
|
function postProcessSidebars(sidebars, params) {
|
|
69
|
-
return
|
|
70
|
+
return lodash_1.default.mapValues(sidebars, (sidebar) => sidebar.map((item) => postProcessSidebarItem(item, params)));
|
|
70
71
|
}
|
|
71
72
|
exports.postProcessSidebars = postProcessSidebars;
|
|
@@ -10,11 +10,11 @@ exports.processSidebars = void 0;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const generator_1 = require("./generator");
|
|
12
12
|
const validation_1 = require("./validation");
|
|
13
|
-
const lodash_1 = require("lodash");
|
|
13
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
14
14
|
const combine_promises_1 = (0, tslib_1.__importDefault)(require("combine-promises"));
|
|
15
15
|
const docs_1 = require("../docs");
|
|
16
16
|
function toSidebarItemsGeneratorDoc(doc) {
|
|
17
|
-
return
|
|
17
|
+
return lodash_1.default.pick(doc, [
|
|
18
18
|
'id',
|
|
19
19
|
'unversionedId',
|
|
20
20
|
'frontMatter',
|
|
@@ -24,14 +24,14 @@ function toSidebarItemsGeneratorDoc(doc) {
|
|
|
24
24
|
]);
|
|
25
25
|
}
|
|
26
26
|
function toSidebarItemsGeneratorVersion(version) {
|
|
27
|
-
return
|
|
27
|
+
return lodash_1.default.pick(version, ['versionName', 'contentPath']);
|
|
28
28
|
}
|
|
29
29
|
// Handle the generation of autogenerated sidebar items and other
|
|
30
30
|
// post-processing checks
|
|
31
31
|
async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
32
32
|
const { sidebarItemsGenerator, numberPrefixParser, docs, version, sidebarOptions, } = params;
|
|
33
33
|
// Just a minor lazy transformation optimization
|
|
34
|
-
const getSidebarItemsGeneratorDocsAndVersion =
|
|
34
|
+
const getSidebarItemsGeneratorDocsAndVersion = lodash_1.default.memoize(() => ({
|
|
35
35
|
docs: docs.map(toSidebarItemsGeneratorDoc),
|
|
36
36
|
version: toSidebarItemsGeneratorVersion(version),
|
|
37
37
|
}));
|
|
@@ -72,7 +72,7 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
|
72
72
|
return processedSidebar;
|
|
73
73
|
}
|
|
74
74
|
async function processSidebars(unprocessedSidebars, categoriesMetadata, params) {
|
|
75
|
-
const processedSidebars = await (0, combine_promises_1.default)(
|
|
75
|
+
const processedSidebars = await (0, combine_promises_1.default)(lodash_1.default.mapValues(unprocessedSidebars, (unprocessedSidebar) => processSidebar(unprocessedSidebar, categoriesMetadata, params)));
|
|
76
76
|
(0, validation_1.validateSidebars)(processedSidebars);
|
|
77
77
|
return processedSidebars;
|
|
78
78
|
}
|
package/lib/sidebars/utils.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.toNavigationLink = exports.toDocNavigationLink = exports.createSidebarsUtils = exports.collectSidebarsNavigations = exports.collectSidebarsDocIds = exports.collectSidebarNavigation = exports.collectSidebarDocIds = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = exports.isCategoriesShorthand = void 0;
|
|
10
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
11
12
|
const utils_1 = require("@docusaurus/utils");
|
|
12
13
|
function isCategoriesShorthand(item) {
|
|
13
14
|
return typeof item !== 'string' && !item.type;
|
|
@@ -81,11 +82,11 @@ function collectSidebarNavigation(sidebar) {
|
|
|
81
82
|
}
|
|
82
83
|
exports.collectSidebarNavigation = collectSidebarNavigation;
|
|
83
84
|
function collectSidebarsDocIds(sidebars) {
|
|
84
|
-
return
|
|
85
|
+
return lodash_1.default.mapValues(sidebars, collectSidebarDocIds);
|
|
85
86
|
}
|
|
86
87
|
exports.collectSidebarsDocIds = collectSidebarsDocIds;
|
|
87
88
|
function collectSidebarsNavigations(sidebars) {
|
|
88
|
-
return
|
|
89
|
+
return lodash_1.default.mapValues(sidebars, collectSidebarNavigation);
|
|
89
90
|
}
|
|
90
91
|
exports.collectSidebarsNavigations = collectSidebarsNavigations;
|
|
91
92
|
function createSidebarsUtils(sidebars) {
|
|
@@ -172,14 +173,14 @@ function createSidebarsUtils(sidebars) {
|
|
|
172
173
|
}
|
|
173
174
|
function checkSidebarsDocIds(validDocIds, sidebarFilePath) {
|
|
174
175
|
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
175
|
-
const invalidSidebarDocIds =
|
|
176
|
+
const invalidSidebarDocIds = lodash_1.default.difference(allSidebarDocIds, validDocIds);
|
|
176
177
|
if (invalidSidebarDocIds.length > 0) {
|
|
177
178
|
throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
|
|
178
179
|
These sidebar document ids do not exist:
|
|
179
180
|
- ${invalidSidebarDocIds.sort().join('\n- ')}
|
|
180
181
|
|
|
181
182
|
Available document ids are:
|
|
182
|
-
- ${
|
|
183
|
+
- ${lodash_1.default.uniq(validDocIds).sort().join('\n- ')}`);
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
function getFirstLink(sidebar) {
|
package/lib/tags.js
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getVersionTags = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
10
11
|
const utils_1 = require("@docusaurus/utils");
|
|
11
|
-
const lodash_1 = require("lodash");
|
|
12
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
12
13
|
function getVersionTags(docs) {
|
|
13
14
|
const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
|
|
14
|
-
return
|
|
15
|
+
return lodash_1.default.mapValues(groups, (group) => ({
|
|
15
16
|
name: group.tag.label,
|
|
16
17
|
docIds: group.items.map((item) => item.id),
|
|
17
18
|
permalink: group.tag.permalink,
|
package/lib/translations.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
|
|
10
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
11
12
|
const utils_1 = require("./sidebars/utils");
|
|
12
13
|
const utils_2 = require("@docusaurus/utils");
|
|
13
14
|
const constants_1 = require("./constants");
|
|
@@ -108,13 +109,13 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
108
109
|
return entries;
|
|
109
110
|
}));
|
|
110
111
|
const links = (0, utils_1.collectSidebarLinks)(sidebar);
|
|
111
|
-
const linksContent = (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
const linksContent = Object.fromEntries(links.map((link) => [
|
|
113
|
+
`sidebar.${sidebarName}.link.${link.label}`,
|
|
114
|
+
{
|
|
115
|
+
message: link.label,
|
|
116
|
+
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
117
|
+
},
|
|
118
|
+
]));
|
|
118
119
|
return (0, utils_2.mergeTranslations)([categoryContent, linksContent]);
|
|
119
120
|
}
|
|
120
121
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
@@ -163,7 +164,7 @@ function getSidebarsTranslations(version) {
|
|
|
163
164
|
}));
|
|
164
165
|
}
|
|
165
166
|
function translateSidebars(version, sidebarsTranslations) {
|
|
166
|
-
return
|
|
167
|
+
return lodash_1.default.mapValues(version.sidebars, (sidebar, sidebarName) => translateSidebar({
|
|
167
168
|
sidebar,
|
|
168
169
|
sidebarName: getNormalizedSidebarName({
|
|
169
170
|
sidebarName,
|
|
@@ -214,7 +215,7 @@ function getLoadedContentTranslationFiles(loadedContent) {
|
|
|
214
215
|
}
|
|
215
216
|
exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
|
|
216
217
|
function translateLoadedContent(loadedContent, translationFiles) {
|
|
217
|
-
const translationFilesMap =
|
|
218
|
+
const translationFilesMap = lodash_1.default.keyBy(translationFiles, (f) => f.path);
|
|
218
219
|
return {
|
|
219
220
|
loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
|
|
220
221
|
};
|
package/lib/versions.js
CHANGED
|
@@ -12,7 +12,7 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
|
12
12
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
14
|
const utils_1 = require("@docusaurus/utils");
|
|
15
|
-
const lodash_1 = require("lodash");
|
|
15
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
16
16
|
const sidebars_1 = require("./sidebars");
|
|
17
17
|
// retro-compatibility: no prefix for the default plugin id
|
|
18
18
|
function addPluginIdPrefix(fileOrDir, pluginId) {
|
|
@@ -236,11 +236,11 @@ function createVersionMetadata({ versionName, versionNames, lastVersionName, con
|
|
|
236
236
|
contentPathLocalized,
|
|
237
237
|
};
|
|
238
238
|
}
|
|
239
|
-
function checkVersionMetadataPaths({ versionMetadata, context, }) {
|
|
239
|
+
async function checkVersionMetadataPaths({ versionMetadata, context, }) {
|
|
240
240
|
const { versionName, contentPath, sidebarFilePath } = versionMetadata;
|
|
241
241
|
const { siteDir } = context;
|
|
242
242
|
const isCurrentVersion = versionName === constants_1.CURRENT_VERSION_NAME;
|
|
243
|
-
if (!fs_extra_1.default.
|
|
243
|
+
if (!(await fs_extra_1.default.pathExists(contentPath))) {
|
|
244
244
|
throw new Error(`The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${path_1.default.relative(siteDir, contentPath)}.`);
|
|
245
245
|
}
|
|
246
246
|
// If the current version defines a path to a sidebar file that does not
|
|
@@ -250,7 +250,7 @@ function checkVersionMetadataPaths({ versionMetadata, context, }) {
|
|
|
250
250
|
// See https://github.com/facebook/docusaurus/pull/4775
|
|
251
251
|
if (isCurrentVersion &&
|
|
252
252
|
typeof sidebarFilePath === 'string' &&
|
|
253
|
-
!fs_extra_1.default.
|
|
253
|
+
!(await fs_extra_1.default.pathExists(sidebarFilePath))) {
|
|
254
254
|
throw new Error(`The path to the sidebar file does not exist at "${path_1.default.relative(siteDir, sidebarFilePath)}".
|
|
255
255
|
Please set the docs "sidebarPath" field in your config file to:
|
|
256
256
|
- a sidebars path that exists
|
|
@@ -273,7 +273,7 @@ function checkVersionsOptions(availableVersionNames, options) {
|
|
|
273
273
|
!availableVersionNames.includes(options.lastVersion)) {
|
|
274
274
|
throw new Error(`Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`);
|
|
275
275
|
}
|
|
276
|
-
const unknownVersionConfigNames =
|
|
276
|
+
const unknownVersionConfigNames = lodash_1.default.difference(Object.keys(options.versions), availableVersionNames);
|
|
277
277
|
if (unknownVersionConfigNames.length > 0) {
|
|
278
278
|
throw new Error(`Invalid docs option "versions": unknown versions (${unknownVersionConfigNames.join(',')}) found. ${availableVersionNamesMsg}`);
|
|
279
279
|
}
|
|
@@ -281,7 +281,7 @@ function checkVersionsOptions(availableVersionNames, options) {
|
|
|
281
281
|
if (options.onlyIncludeVersions.length === 0) {
|
|
282
282
|
throw new Error(`Invalid docs option "onlyIncludeVersions": an empty array is not allowed, at least one version is needed.`);
|
|
283
283
|
}
|
|
284
|
-
const unknownOnlyIncludeVersionNames =
|
|
284
|
+
const unknownOnlyIncludeVersionNames = lodash_1.default.difference(options.onlyIncludeVersions, availableVersionNames);
|
|
285
285
|
if (unknownOnlyIncludeVersionNames.length > 0) {
|
|
286
286
|
throw new Error(`Invalid docs option "onlyIncludeVersions": unknown versions (${unknownOnlyIncludeVersionNames.join(',')}) found. ${availableVersionNamesMsg}`);
|
|
287
287
|
}
|
|
@@ -316,7 +316,7 @@ async function readVersionsMetadata({ context, options, }) {
|
|
|
316
316
|
context,
|
|
317
317
|
options,
|
|
318
318
|
}));
|
|
319
|
-
versionsMetadata.
|
|
319
|
+
await Promise.all(versionsMetadata.map((versionMetadata) => checkVersionMetadataPaths({ versionMetadata, context })));
|
|
320
320
|
return versionsMetadata;
|
|
321
321
|
}
|
|
322
322
|
exports.readVersionsMetadata = readVersionsMetadata;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4614",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@docusaurus/core": "0.0.0-
|
|
27
|
-
"@docusaurus/logger": "0.0.0-
|
|
28
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
29
|
-
"@docusaurus/utils": "0.0.0-
|
|
30
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
26
|
+
"@docusaurus/core": "0.0.0-4614",
|
|
27
|
+
"@docusaurus/logger": "0.0.0-4614",
|
|
28
|
+
"@docusaurus/mdx-loader": "0.0.0-4614",
|
|
29
|
+
"@docusaurus/utils": "0.0.0-4614",
|
|
30
|
+
"@docusaurus/utils-validation": "0.0.0-4614",
|
|
31
31
|
"combine-promises": "^1.1.0",
|
|
32
32
|
"fs-extra": "^10.0.0",
|
|
33
33
|
"import-fresh": "^3.3.0",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"webpack": "^5.69.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
43
|
-
"@docusaurus/types": "0.0.0-
|
|
42
|
+
"@docusaurus/module-type-aliases": "0.0.0-4614",
|
|
43
|
+
"@docusaurus/types": "0.0.0-4614",
|
|
44
44
|
"@types/js-yaml": "^4.0.5",
|
|
45
45
|
"@types/picomatch": "^2.3.0",
|
|
46
46
|
"commander": "^5.1.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=14"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "0fa2e52fbc24ea9aa80a5da40149036009bcf21c"
|
|
60
60
|
}
|
package/src/cli.ts
CHANGED
|
@@ -47,8 +47,8 @@ async function createVersionedSidebarFile({
|
|
|
47
47
|
versionedSidebarsDir,
|
|
48
48
|
`version-${version}-sidebars.json`,
|
|
49
49
|
);
|
|
50
|
-
fs.
|
|
51
|
-
fs.
|
|
50
|
+
await fs.ensureDir(path.dirname(newSidebarFile));
|
|
51
|
+
await fs.writeFile(
|
|
52
52
|
newSidebarFile,
|
|
53
53
|
`${JSON.stringify(sidebars, null, 2)}\n`,
|
|
54
54
|
'utf8',
|
|
@@ -104,8 +104,8 @@ export async function cliDocsVersionCommand(
|
|
|
104
104
|
// Load existing versions.
|
|
105
105
|
let versions = [];
|
|
106
106
|
const versionsJSONFile = getVersionsFilePath(siteDir, pluginId);
|
|
107
|
-
if (fs.
|
|
108
|
-
versions = JSON.parse(fs.
|
|
107
|
+
if (await fs.pathExists(versionsJSONFile)) {
|
|
108
|
+
versions = JSON.parse(await fs.readFile(versionsJSONFile, 'utf8'));
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
// Check if version already exists.
|
|
@@ -120,10 +120,13 @@ export async function cliDocsVersionCommand(
|
|
|
120
120
|
// Copy docs files.
|
|
121
121
|
const docsDir = path.join(siteDir, docsPath);
|
|
122
122
|
|
|
123
|
-
if (
|
|
123
|
+
if (
|
|
124
|
+
(await fs.pathExists(docsDir)) &&
|
|
125
|
+
(await fs.readdir(docsDir)).length > 0
|
|
126
|
+
) {
|
|
124
127
|
const versionedDir = getVersionedDocsDirPath(siteDir, pluginId);
|
|
125
128
|
const newVersionDir = path.join(versionedDir, `version-${version}`);
|
|
126
|
-
fs.
|
|
129
|
+
await fs.copy(docsDir, newVersionDir);
|
|
127
130
|
} else {
|
|
128
131
|
throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
|
|
129
132
|
}
|
|
@@ -137,8 +140,11 @@ export async function cliDocsVersionCommand(
|
|
|
137
140
|
|
|
138
141
|
// Update versions.json file.
|
|
139
142
|
versions.unshift(version);
|
|
140
|
-
fs.
|
|
141
|
-
fs.
|
|
143
|
+
await fs.ensureDir(path.dirname(versionsJSONFile));
|
|
144
|
+
await fs.writeFile(
|
|
145
|
+
versionsJSONFile,
|
|
146
|
+
`${JSON.stringify(versions, null, 2)}\n`,
|
|
147
|
+
);
|
|
142
148
|
|
|
143
149
|
logger.success`name=${pluginIdLogPrefix}: version name=${version} created!`;
|
|
144
150
|
}
|
package/src/docs.ts
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
10
|
import logger from '@docusaurus/logger';
|
|
11
|
-
import {keyBy} from 'lodash';
|
|
12
11
|
import {
|
|
13
12
|
aliasedSitePath,
|
|
14
13
|
getEditUrl,
|
|
@@ -444,8 +443,10 @@ export function getDocIds(doc: DocMetadataBase): [string, string] {
|
|
|
444
443
|
export function createDocsByIdIndex<
|
|
445
444
|
Doc extends {id: string; unversionedId: string},
|
|
446
445
|
>(docs: Doc[]): Record<string, Doc> {
|
|
447
|
-
return
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
446
|
+
return Object.fromEntries(
|
|
447
|
+
docs.flatMap((doc) => [
|
|
448
|
+
[doc.unversionedId, doc],
|
|
449
|
+
[doc.id, doc],
|
|
450
|
+
]),
|
|
451
|
+
);
|
|
451
452
|
}
|
package/src/globalData.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import _ from 'lodash';
|
|
9
9
|
import {normalizeUrl} from '@docusaurus/utils';
|
|
10
10
|
import type {Sidebars} from './sidebars/types';
|
|
11
11
|
import {createSidebarsUtils} from './sidebars/utils';
|
|
@@ -43,7 +43,7 @@ export function toGlobalSidebars(
|
|
|
43
43
|
version: LoadedVersion,
|
|
44
44
|
): Record<string, GlobalSidebar> {
|
|
45
45
|
const {getFirstLink} = createSidebarsUtils(sidebars);
|
|
46
|
-
return mapValues(sidebars, (sidebar, sidebarId) => {
|
|
46
|
+
return _.mapValues(sidebars, (sidebar, sidebarId) => {
|
|
47
47
|
const firstLink = getFirstLink(sidebarId);
|
|
48
48
|
if (!firstLink) {
|
|
49
49
|
return {};
|
package/src/index.ts
CHANGED
|
@@ -38,11 +38,11 @@ import type {
|
|
|
38
38
|
DocFile,
|
|
39
39
|
DocsMarkdownOption,
|
|
40
40
|
VersionTag,
|
|
41
|
+
DocFrontMatter,
|
|
41
42
|
} from './types';
|
|
42
43
|
import type {RuleSetRule} from 'webpack';
|
|
43
44
|
import {cliDocsVersionCommand} from './cli';
|
|
44
45
|
import {VERSIONS_JSON_FILE} from './constants';
|
|
45
|
-
import {keyBy, mapValues} from 'lodash';
|
|
46
46
|
import {toGlobalDataVersion} from './globalData';
|
|
47
47
|
import {toTagDocListProp} from './props';
|
|
48
48
|
import {
|
|
@@ -311,9 +311,8 @@ export default async function pluginContentDocs(
|
|
|
311
311
|
|
|
312
312
|
function getSourceToPermalink(): SourceToPermalink {
|
|
313
313
|
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
314
|
-
return
|
|
315
|
-
|
|
316
|
-
(d) => d.permalink,
|
|
314
|
+
return Object.fromEntries(
|
|
315
|
+
allDocs.map(({source, permalink}) => [source, permalink]),
|
|
317
316
|
);
|
|
318
317
|
}
|
|
319
318
|
|
|
@@ -362,6 +361,15 @@ export default async function pluginContentDocs(
|
|
|
362
361
|
const aliasedPath = aliasedSitePath(mdxPath, siteDir);
|
|
363
362
|
return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
|
|
364
363
|
},
|
|
364
|
+
// Assets allow to convert some relative images paths to
|
|
365
|
+
// require(...) calls
|
|
366
|
+
createAssets: ({
|
|
367
|
+
frontMatter,
|
|
368
|
+
}: {
|
|
369
|
+
frontMatter: DocFrontMatter;
|
|
370
|
+
}) => ({
|
|
371
|
+
image: frontMatter.image,
|
|
372
|
+
}),
|
|
365
373
|
},
|
|
366
374
|
},
|
|
367
375
|
{
|
package/src/props.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
PropTagDocListDoc,
|
|
23
23
|
PropSidebarItemLink,
|
|
24
24
|
} from '@docusaurus/plugin-content-docs';
|
|
25
|
-
import
|
|
25
|
+
import _ from 'lodash';
|
|
26
26
|
import {createDocsByIdIndex} from './docs';
|
|
27
27
|
|
|
28
28
|
export function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars {
|
|
@@ -93,18 +93,22 @@ Available document ids are:
|
|
|
93
93
|
// Transform the sidebar so that all sidebar item will be in the
|
|
94
94
|
// form of 'link' or 'category' only.
|
|
95
95
|
// This is what will be passed as props to the UI component.
|
|
96
|
-
return mapValues(loadedVersion.sidebars, (items) =>
|
|
96
|
+
return _.mapValues(loadedVersion.sidebars, (items) =>
|
|
97
|
+
items.map(normalizeItem),
|
|
98
|
+
);
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
function toVersionDocsProp(loadedVersion: LoadedVersion): PropVersionDocs {
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
return Object.fromEntries(
|
|
103
|
+
loadedVersion.docs.map((doc) => [
|
|
104
|
+
doc.unversionedId,
|
|
105
|
+
{
|
|
106
|
+
id: doc.unversionedId,
|
|
107
|
+
title: doc.title,
|
|
108
|
+
description: doc.description,
|
|
109
|
+
sidebar: doc.sidebar,
|
|
110
|
+
},
|
|
111
|
+
]),
|
|
108
112
|
);
|
|
109
113
|
}
|
|
110
114
|
|
|
@@ -135,7 +139,7 @@ export function toTagDocListProp({
|
|
|
135
139
|
docs: Pick<DocMetadata, 'id' | 'title' | 'description' | 'permalink'>[];
|
|
136
140
|
}): PropTagDocList {
|
|
137
141
|
function toDocListProp(): PropTagDocListDoc[] {
|
|
138
|
-
const list = compact(
|
|
142
|
+
const list = _.compact(
|
|
139
143
|
tag.docIds.map((id) => docs.find((doc) => doc.id === id)),
|
|
140
144
|
);
|
|
141
145
|
// Sort docs by title
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
NormalizedSidebarItem,
|
|
14
14
|
SidebarItemCategoryLinkConfig,
|
|
15
15
|
} from './types';
|
|
16
|
-
import
|
|
16
|
+
import _ from 'lodash';
|
|
17
17
|
import {addTrailingSlash, posixPath} from '@docusaurus/utils';
|
|
18
18
|
import logger from '@docusaurus/logger';
|
|
19
19
|
import path from 'path';
|
|
@@ -25,7 +25,7 @@ const docIdPrefix = '$doc$/';
|
|
|
25
25
|
|
|
26
26
|
// Just an alias to the make code more explicit
|
|
27
27
|
function getLocalDocId(docId: string): string {
|
|
28
|
-
return last(docId.split('/'))!;
|
|
28
|
+
return _.last(docId.split('/'))!;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const CategoryMetadataFilenameBase = '_category_';
|
|
@@ -248,7 +248,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
|
|
|
248
248
|
}
|
|
249
249
|
return item;
|
|
250
250
|
});
|
|
251
|
-
const sortedSidebarItems = sortBy(
|
|
251
|
+
const sortedSidebarItems = _.sortBy(
|
|
252
252
|
processedSidebarItems,
|
|
253
253
|
(item) => item.position,
|
|
254
254
|
);
|
package/src/sidebars/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {Globby} from '@docusaurus/utils';
|
|
|
17
17
|
import logger from '@docusaurus/logger';
|
|
18
18
|
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
|
|
19
19
|
import Yaml from 'js-yaml';
|
|
20
|
-
import
|
|
20
|
+
import _ from 'lodash';
|
|
21
21
|
import combinePromises from 'combine-promises';
|
|
22
22
|
|
|
23
23
|
export const DefaultSidebars: SidebarsConfig = {
|
|
@@ -46,9 +46,9 @@ async function readCategoriesMetadata(contentPath: string) {
|
|
|
46
46
|
const categoryFiles = await Globby('**/_category_.{json,yml,yaml}', {
|
|
47
47
|
cwd: contentPath,
|
|
48
48
|
});
|
|
49
|
-
const categoryToFile = groupBy(categoryFiles, path.dirname);
|
|
49
|
+
const categoryToFile = _.groupBy(categoryFiles, path.dirname);
|
|
50
50
|
return combinePromises(
|
|
51
|
-
mapValues(categoryToFile, async (files, folder) => {
|
|
51
|
+
_.mapValues(categoryToFile, async (files, folder) => {
|
|
52
52
|
const [filePath] = files;
|
|
53
53
|
if (files.length > 1) {
|
|
54
54
|
logger.warn`There are more than one category metadata files for path=${folder}: ${files.join(
|
|
@@ -85,7 +85,7 @@ export async function loadSidebarsFileUnsafe(
|
|
|
85
85
|
// Non-existent sidebars file: no sidebars
|
|
86
86
|
// Note: this edge case can happen on versioned docs, not current version
|
|
87
87
|
// We avoid creating empty versioned sidebars file with the CLI
|
|
88
|
-
if (!fs.
|
|
88
|
+
if (!(await fs.pathExists(sidebarFilePath))) {
|
|
89
89
|
return DisabledSidebars;
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
NormalizedSidebarItemCategory,
|
|
18
18
|
} from './types';
|
|
19
19
|
import {isCategoriesShorthand} from './utils';
|
|
20
|
-
import
|
|
20
|
+
import _ from 'lodash';
|
|
21
21
|
|
|
22
22
|
function normalizeCategoriesShorthand(
|
|
23
23
|
sidebar: SidebarCategoriesShorthand,
|
|
@@ -81,5 +81,5 @@ function normalizeSidebar(sidebar: SidebarConfig): NormalizedSidebar {
|
|
|
81
81
|
export function normalizeSidebars(
|
|
82
82
|
sidebars: SidebarsConfig,
|
|
83
83
|
): NormalizedSidebars {
|
|
84
|
-
return mapValues(sidebars, normalizeSidebar);
|
|
84
|
+
return _.mapValues(sidebars, normalizeSidebar);
|
|
85
85
|
}
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
ProcessedSidebars,
|
|
16
16
|
SidebarItemCategoryLink,
|
|
17
17
|
} from './types';
|
|
18
|
-
import
|
|
18
|
+
import _ from 'lodash';
|
|
19
19
|
|
|
20
20
|
function normalizeCategoryLink(
|
|
21
21
|
category: ProcessedSidebarItemCategory,
|
|
@@ -88,7 +88,7 @@ export function postProcessSidebars(
|
|
|
88
88
|
sidebars: ProcessedSidebars,
|
|
89
89
|
params: SidebarProcessorParams,
|
|
90
90
|
): Sidebars {
|
|
91
|
-
return mapValues(sidebars, (sidebar) =>
|
|
91
|
+
return _.mapValues(sidebars, (sidebar) =>
|
|
92
92
|
sidebar.map((item) => postProcessSidebarItem(item, params)),
|
|
93
93
|
);
|
|
94
94
|
}
|
|
@@ -21,14 +21,14 @@ import type {
|
|
|
21
21
|
} from './types';
|
|
22
22
|
import {DefaultSidebarItemsGenerator} from './generator';
|
|
23
23
|
import {validateSidebars} from './validation';
|
|
24
|
-
import
|
|
24
|
+
import _ from 'lodash';
|
|
25
25
|
import combinePromises from 'combine-promises';
|
|
26
26
|
import {isCategoryIndex} from '../docs';
|
|
27
27
|
|
|
28
28
|
function toSidebarItemsGeneratorDoc(
|
|
29
29
|
doc: DocMetadataBase,
|
|
30
30
|
): SidebarItemsGeneratorDoc {
|
|
31
|
-
return pick(doc, [
|
|
31
|
+
return _.pick(doc, [
|
|
32
32
|
'id',
|
|
33
33
|
'unversionedId',
|
|
34
34
|
'frontMatter',
|
|
@@ -41,7 +41,7 @@ function toSidebarItemsGeneratorDoc(
|
|
|
41
41
|
function toSidebarItemsGeneratorVersion(
|
|
42
42
|
version: VersionMetadata,
|
|
43
43
|
): SidebarItemsGeneratorVersion {
|
|
44
|
-
return pick(version, ['versionName', 'contentPath']);
|
|
44
|
+
return _.pick(version, ['versionName', 'contentPath']);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// Handle the generation of autogenerated sidebar items and other
|
|
@@ -60,7 +60,7 @@ async function processSidebar(
|
|
|
60
60
|
} = params;
|
|
61
61
|
|
|
62
62
|
// Just a minor lazy transformation optimization
|
|
63
|
-
const getSidebarItemsGeneratorDocsAndVersion = memoize(() => ({
|
|
63
|
+
const getSidebarItemsGeneratorDocsAndVersion = _.memoize(() => ({
|
|
64
64
|
docs: docs.map(toSidebarItemsGeneratorDoc),
|
|
65
65
|
version: toSidebarItemsGeneratorVersion(version),
|
|
66
66
|
}));
|
|
@@ -117,7 +117,7 @@ export async function processSidebars(
|
|
|
117
117
|
params: SidebarProcessorParams,
|
|
118
118
|
): Promise<ProcessedSidebars> {
|
|
119
119
|
const processedSidebars = await combinePromises(
|
|
120
|
-
mapValues(unprocessedSidebars, (unprocessedSidebar) =>
|
|
120
|
+
_.mapValues(unprocessedSidebars, (unprocessedSidebar) =>
|
|
121
121
|
processSidebar(unprocessedSidebar, categoriesMetadata, params),
|
|
122
122
|
),
|
|
123
123
|
);
|
package/src/sidebars/utils.ts
CHANGED
|
@@ -19,7 +19,7 @@ import type {
|
|
|
19
19
|
SidebarNavigationItem,
|
|
20
20
|
} from './types';
|
|
21
21
|
|
|
22
|
-
import
|
|
22
|
+
import _ from 'lodash';
|
|
23
23
|
import {getElementsAround, toMessageRelativeFilePath} from '@docusaurus/utils';
|
|
24
24
|
import type {DocMetadataBase, DocNavLink} from '../types';
|
|
25
25
|
|
|
@@ -110,13 +110,13 @@ export function collectSidebarNavigation(
|
|
|
110
110
|
export function collectSidebarsDocIds(
|
|
111
111
|
sidebars: Sidebars,
|
|
112
112
|
): Record<string, string[]> {
|
|
113
|
-
return mapValues(sidebars, collectSidebarDocIds);
|
|
113
|
+
return _.mapValues(sidebars, collectSidebarDocIds);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
export function collectSidebarsNavigations(
|
|
117
117
|
sidebars: Sidebars,
|
|
118
118
|
): Record<string, SidebarNavigationItem[]> {
|
|
119
|
-
return mapValues(sidebars, collectSidebarNavigation);
|
|
119
|
+
return _.mapValues(sidebars, collectSidebarNavigation);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
export type SidebarNavigation = {
|
|
@@ -276,7 +276,7 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|
|
276
276
|
|
|
277
277
|
function checkSidebarsDocIds(validDocIds: string[], sidebarFilePath: string) {
|
|
278
278
|
const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
|
|
279
|
-
const invalidSidebarDocIds = difference(allSidebarDocIds, validDocIds);
|
|
279
|
+
const invalidSidebarDocIds = _.difference(allSidebarDocIds, validDocIds);
|
|
280
280
|
if (invalidSidebarDocIds.length > 0) {
|
|
281
281
|
throw new Error(
|
|
282
282
|
`Invalid sidebar file at "${toMessageRelativeFilePath(
|
|
@@ -286,7 +286,7 @@ These sidebar document ids do not exist:
|
|
|
286
286
|
- ${invalidSidebarDocIds.sort().join('\n- ')}
|
|
287
287
|
|
|
288
288
|
Available document ids are:
|
|
289
|
-
- ${uniq(validDocIds).sort().join('\n- ')}`,
|
|
289
|
+
- ${_.uniq(validDocIds).sort().join('\n- ')}`,
|
|
290
290
|
);
|
|
291
291
|
}
|
|
292
292
|
}
|
package/src/tags.ts
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import {groupTaggedItems} from '@docusaurus/utils';
|
|
9
9
|
import type {VersionTags, DocMetadata} from './types';
|
|
10
|
-
import
|
|
10
|
+
import _ from 'lodash';
|
|
11
11
|
|
|
12
12
|
export function getVersionTags(docs: DocMetadata[]): VersionTags {
|
|
13
13
|
const groups = groupTaggedItems(docs, (doc) => doc.tags);
|
|
14
|
-
return mapValues(groups, (group) => ({
|
|
14
|
+
return _.mapValues(groups, (group) => ({
|
|
15
15
|
name: group.tag.label,
|
|
16
16
|
docIds: group.items.map((item) => item.id),
|
|
17
17
|
permalink: group.tag.permalink,
|
package/src/translations.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
Sidebars,
|
|
14
14
|
} from './sidebars/types';
|
|
15
15
|
|
|
16
|
-
import
|
|
16
|
+
import _ from 'lodash';
|
|
17
17
|
import {
|
|
18
18
|
collectSidebarCategories,
|
|
19
19
|
transformSidebarItems,
|
|
@@ -146,13 +146,15 @@ function getSidebarTranslationFileContent(
|
|
|
146
146
|
);
|
|
147
147
|
|
|
148
148
|
const links = collectSidebarLinks(sidebar);
|
|
149
|
-
const linksContent: TranslationFileContent =
|
|
150
|
-
.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
const linksContent: TranslationFileContent = Object.fromEntries(
|
|
150
|
+
links.map((link) => [
|
|
151
|
+
`sidebar.${sidebarName}.link.${link.label}`,
|
|
152
|
+
{
|
|
153
|
+
message: link.label,
|
|
154
|
+
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
155
|
+
},
|
|
156
|
+
]),
|
|
157
|
+
);
|
|
156
158
|
|
|
157
159
|
return mergeTranslations([categoryContent, linksContent]);
|
|
158
160
|
}
|
|
@@ -230,7 +232,7 @@ function translateSidebars(
|
|
|
230
232
|
version: LoadedVersion,
|
|
231
233
|
sidebarsTranslations: TranslationFileContent,
|
|
232
234
|
): Sidebars {
|
|
233
|
-
return mapValues(version.sidebars, (sidebar, sidebarName) =>
|
|
235
|
+
return _.mapValues(version.sidebars, (sidebar, sidebarName) =>
|
|
234
236
|
translateSidebar({
|
|
235
237
|
sidebar,
|
|
236
238
|
sidebarName: getNormalizedSidebarName({
|
|
@@ -302,7 +304,7 @@ export function translateLoadedContent(
|
|
|
302
304
|
loadedContent: LoadedContent,
|
|
303
305
|
translationFiles: TranslationFile[],
|
|
304
306
|
): LoadedContent {
|
|
305
|
-
const translationFilesMap: Record<string, TranslationFile> = keyBy(
|
|
307
|
+
const translationFilesMap: Record<string, TranslationFile> = _.keyBy(
|
|
306
308
|
translationFiles,
|
|
307
309
|
(f) => f.path,
|
|
308
310
|
);
|
package/src/versions.ts
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
posixPath,
|
|
29
29
|
DEFAULT_PLUGIN_ID,
|
|
30
30
|
} from '@docusaurus/utils';
|
|
31
|
-
import
|
|
31
|
+
import _ from 'lodash';
|
|
32
32
|
import {resolveSidebarPathOption} from './sidebars';
|
|
33
33
|
|
|
34
34
|
// retro-compatibility: no prefix for the default plugin id
|
|
@@ -418,7 +418,7 @@ function createVersionMetadata({
|
|
|
418
418
|
};
|
|
419
419
|
}
|
|
420
420
|
|
|
421
|
-
function checkVersionMetadataPaths({
|
|
421
|
+
async function checkVersionMetadataPaths({
|
|
422
422
|
versionMetadata,
|
|
423
423
|
context,
|
|
424
424
|
}: {
|
|
@@ -429,7 +429,7 @@ function checkVersionMetadataPaths({
|
|
|
429
429
|
const {siteDir} = context;
|
|
430
430
|
const isCurrentVersion = versionName === CURRENT_VERSION_NAME;
|
|
431
431
|
|
|
432
|
-
if (!fs.
|
|
432
|
+
if (!(await fs.pathExists(contentPath))) {
|
|
433
433
|
throw new Error(
|
|
434
434
|
`The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${path.relative(
|
|
435
435
|
siteDir,
|
|
@@ -446,7 +446,7 @@ function checkVersionMetadataPaths({
|
|
|
446
446
|
if (
|
|
447
447
|
isCurrentVersion &&
|
|
448
448
|
typeof sidebarFilePath === 'string' &&
|
|
449
|
-
!fs.
|
|
449
|
+
!(await fs.pathExists(sidebarFilePath))
|
|
450
450
|
) {
|
|
451
451
|
throw new Error(`The path to the sidebar file does not exist at "${path.relative(
|
|
452
452
|
siteDir,
|
|
@@ -486,7 +486,7 @@ function checkVersionsOptions(
|
|
|
486
486
|
`Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`,
|
|
487
487
|
);
|
|
488
488
|
}
|
|
489
|
-
const unknownVersionConfigNames = difference(
|
|
489
|
+
const unknownVersionConfigNames = _.difference(
|
|
490
490
|
Object.keys(options.versions),
|
|
491
491
|
availableVersionNames,
|
|
492
492
|
);
|
|
@@ -504,7 +504,7 @@ function checkVersionsOptions(
|
|
|
504
504
|
`Invalid docs option "onlyIncludeVersions": an empty array is not allowed, at least one version is needed.`,
|
|
505
505
|
);
|
|
506
506
|
}
|
|
507
|
-
const unknownOnlyIncludeVersionNames = difference(
|
|
507
|
+
const unknownOnlyIncludeVersionNames = _.difference(
|
|
508
508
|
options.onlyIncludeVersions,
|
|
509
509
|
availableVersionNames,
|
|
510
510
|
);
|
|
@@ -585,8 +585,10 @@ export async function readVersionsMetadata({
|
|
|
585
585
|
options,
|
|
586
586
|
}),
|
|
587
587
|
);
|
|
588
|
-
|
|
589
|
-
|
|
588
|
+
await Promise.all(
|
|
589
|
+
versionsMetadata.map((versionMetadata) =>
|
|
590
|
+
checkVersionMetadataPaths({versionMetadata, context}),
|
|
591
|
+
),
|
|
590
592
|
);
|
|
591
593
|
return versionsMetadata;
|
|
592
594
|
}
|