@docusaurus/plugin-content-docs 2.0.0-beta.16 → 2.0.0-beta.17
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.js +1 -2
- package/lib/cli.js +3 -3
- package/lib/client/docsClientUtils.js +2 -2
- package/lib/client/index.js +2 -2
- package/lib/docs.js +9 -11
- package/lib/globalData.js +1 -1
- package/lib/index.js +3 -4
- package/lib/lastUpdate.js +1 -1
- package/lib/numberPrefix.js +2 -3
- package/lib/options.js +2 -2
- package/lib/props.js +3 -4
- package/lib/routes.js +1 -1
- package/lib/sidebars/generator.js +32 -29
- package/lib/sidebars/index.js +7 -7
- package/lib/sidebars/normalization.js +2 -2
- package/lib/sidebars/postProcessor.js +5 -7
- package/lib/sidebars/processor.js +2 -2
- package/lib/sidebars/utils.js +9 -15
- package/lib/slug.js +1 -1
- package/lib/tags.js +1 -1
- package/lib/translations.js +8 -9
- package/lib/versions.js +15 -20
- package/package.json +9 -9
- package/src/sidebars/generator.ts +39 -33
|
@@ -10,13 +10,12 @@ exports.getCategoryGeneratedIndexMetadataList = void 0;
|
|
|
10
10
|
const utils_1 = require("./sidebars/utils");
|
|
11
11
|
const docs_1 = require("./docs");
|
|
12
12
|
function getCategoryGeneratedIndexMetadata({ category, sidebarsUtils, docsById, }) {
|
|
13
|
-
var _a;
|
|
14
13
|
const { sidebarName, previous, next } = sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
|
15
14
|
if (!sidebarName) {
|
|
16
15
|
throw new Error('unexpected');
|
|
17
16
|
}
|
|
18
17
|
return {
|
|
19
|
-
title:
|
|
18
|
+
title: category.link.title ?? category.label,
|
|
20
19
|
description: category.link.description,
|
|
21
20
|
image: category.link.image,
|
|
22
21
|
keywords: category.link.keywords,
|
package/lib/cli.js
CHANGED
|
@@ -9,11 +9,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.cliDocsVersionCommand = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const versions_1 = require("./versions");
|
|
12
|
-
const fs_extra_1 =
|
|
13
|
-
const path_1 =
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
14
|
const sidebars_1 = require("./sidebars");
|
|
15
15
|
const utils_1 = require("@docusaurus/utils");
|
|
16
|
-
const logger_1 =
|
|
16
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
17
17
|
async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, version, }) {
|
|
18
18
|
// Load current sidebar and create a new versioned sidebars file (if needed).
|
|
19
19
|
// Note: we don't need the sidebars file to be normalized: it's ok to let
|
|
@@ -53,7 +53,7 @@ const getActiveVersion = (data, pathname) => {
|
|
|
53
53
|
exports.getActiveVersion = getActiveVersion;
|
|
54
54
|
const getActiveDocContext = (data, pathname) => {
|
|
55
55
|
const activeVersion = (0, exports.getActiveVersion)(data, pathname);
|
|
56
|
-
const activeDoc = activeVersion
|
|
56
|
+
const activeDoc = activeVersion?.docs.find((doc) => !!(0, router_1.matchPath)(pathname, {
|
|
57
57
|
path: doc.path,
|
|
58
58
|
exact: true,
|
|
59
59
|
strict: false,
|
|
@@ -82,7 +82,7 @@ exports.getActiveDocContext = getActiveDocContext;
|
|
|
82
82
|
const getDocVersionSuggestions = (data, pathname) => {
|
|
83
83
|
const latestVersion = (0, exports.getLatestVersion)(data);
|
|
84
84
|
const activeDocContext = (0, exports.getActiveDocContext)(data, pathname);
|
|
85
|
-
const latestDocSuggestion = activeDocContext
|
|
85
|
+
const latestDocSuggestion = activeDocContext?.alternateDocVersions[latestVersion.name];
|
|
86
86
|
return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
|
|
87
87
|
};
|
|
88
88
|
exports.getDocVersionSuggestions = getDocVersionSuggestions;
|
package/lib/client/index.js
CHANGED
|
@@ -9,7 +9,7 @@ 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 =
|
|
12
|
+
const useGlobalData_1 = tslib_1.__importStar(require("@docusaurus/useGlobalData"));
|
|
13
13
|
const docsClientUtils_1 = require("./docsClientUtils");
|
|
14
14
|
// Important to use a constant object to avoid React useEffect executions etc.
|
|
15
15
|
// see https://github.com/facebook/docusaurus/issues/5089
|
|
@@ -17,7 +17,7 @@ const StableEmptyObject = {};
|
|
|
17
17
|
// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks
|
|
18
18
|
// are still used by the theme. We need a fail-safe fallback when the docs
|
|
19
19
|
// plugin is not in use
|
|
20
|
-
const useAllDocsData = () =>
|
|
20
|
+
const useAllDocsData = () => (0, useGlobalData_1.default)()['docusaurus-plugin-content-docs'] ?? StableEmptyObject;
|
|
21
21
|
exports.useAllDocsData = useAllDocsData;
|
|
22
22
|
const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId);
|
|
23
23
|
exports.useDocsData = useDocsData;
|
package/lib/docs.js
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createDocsByIdIndex = exports.getDocIds = exports.splitPath = exports.toCategoryIndexMatcherParam = exports.isCategoryIndex = exports.getMainDocId = exports.addDocNavigation = exports.processDocMetadata = exports.readVersionDocs = exports.readDocFile = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 =
|
|
12
|
-
const fs_extra_1 =
|
|
13
|
-
const logger_1 =
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
14
|
const utils_1 = require("@docusaurus/utils");
|
|
15
15
|
const lastUpdate_1 = require("./lastUpdate");
|
|
16
|
-
const slug_1 =
|
|
16
|
+
const slug_1 = tslib_1.__importDefault(require("./slug"));
|
|
17
17
|
const constants_1 = require("./constants");
|
|
18
18
|
const versions_1 = require("./versions");
|
|
19
19
|
const numberPrefix_1 = require("./numberPrefix");
|
|
@@ -58,7 +58,6 @@ async function readVersionDocs(versionMetadata, options) {
|
|
|
58
58
|
}
|
|
59
59
|
exports.readVersionDocs = readVersionDocs;
|
|
60
60
|
function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
61
|
-
var _a, _b, _c, _d, _e, _f;
|
|
62
61
|
const { source, content, lastUpdate, contentPath, filePath } = docFile;
|
|
63
62
|
const { siteDir, i18n } = context;
|
|
64
63
|
const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = (0, utils_1.parseMarkdownString)(content);
|
|
@@ -77,13 +76,13 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
77
76
|
const { filename: unprefixedFileName, numberPrefix } = parseNumberPrefixes
|
|
78
77
|
? options.numberPrefixParser(sourceFileNameWithoutExtension)
|
|
79
78
|
: { filename: sourceFileNameWithoutExtension, numberPrefix: undefined };
|
|
80
|
-
const baseID =
|
|
79
|
+
const baseID = frontMatter.id ?? unprefixedFileName;
|
|
81
80
|
if (baseID.includes('/')) {
|
|
82
81
|
throw new Error(`Document id "${baseID}" cannot include slash.`);
|
|
83
82
|
}
|
|
84
83
|
// For autogenerated sidebars, sidebar position can come from filename number
|
|
85
84
|
// prefix or front matter
|
|
86
|
-
const sidebarPosition =
|
|
85
|
+
const sidebarPosition = frontMatter.sidebar_position ?? numberPrefix;
|
|
87
86
|
// TODO legacy retrocompatibility
|
|
88
87
|
// The same doc in 2 distinct version could keep the same id,
|
|
89
88
|
// we just need to namespace the data by version
|
|
@@ -118,8 +117,8 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
118
117
|
// Note: the title is used by default for page title, sidebar label,
|
|
119
118
|
// pagination buttons... frontMatter.title should be used in priority over
|
|
120
119
|
// contentTitle (because it can contain markdown/JSX syntax)
|
|
121
|
-
const title =
|
|
122
|
-
const description =
|
|
120
|
+
const title = frontMatter.title ?? contentTitle ?? baseID;
|
|
121
|
+
const description = frontMatter.description ?? excerpt ?? '';
|
|
123
122
|
const permalink = (0, utils_1.normalizeUrl)([versionMetadata.versionPath, docSlug]);
|
|
124
123
|
function getDocEditUrl() {
|
|
125
124
|
const relativeFilePath = path_1.default.relative(contentPath, filePath);
|
|
@@ -241,11 +240,10 @@ exports.getMainDocId = getMainDocId;
|
|
|
241
240
|
// - Slugs do not end with a weird "/index" suffix
|
|
242
241
|
// - Auto-generated sidebar categories link to them as intro
|
|
243
242
|
const isCategoryIndex = ({ fileName, directories, }) => {
|
|
244
|
-
var _a;
|
|
245
243
|
const eligibleDocIndexNames = [
|
|
246
244
|
'index',
|
|
247
245
|
'readme',
|
|
248
|
-
|
|
246
|
+
directories[0]?.toLowerCase(),
|
|
249
247
|
];
|
|
250
248
|
return eligibleDocIndexNames.includes(fileName.toLowerCase());
|
|
251
249
|
};
|
package/lib/globalData.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.toGlobalDataVersion = exports.toGlobalSidebars = exports.toGlobalDataGeneratedIndex = exports.toGlobalDataDoc = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const lodash_1 =
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
const utils_2 = require("./sidebars/utils");
|
|
14
14
|
function toGlobalDataDoc(doc) {
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateOptions = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 =
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
const sidebars_1 = require("./sidebars");
|
|
14
14
|
const generator_1 = require("./sidebars/generator");
|
|
@@ -19,16 +19,15 @@ const constants_1 = require("./constants");
|
|
|
19
19
|
const globalData_1 = require("./globalData");
|
|
20
20
|
const props_1 = require("./props");
|
|
21
21
|
const translations_1 = require("./translations");
|
|
22
|
-
const logger_1 =
|
|
22
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
23
23
|
const tags_1 = require("./tags");
|
|
24
24
|
const routes_1 = require("./routes");
|
|
25
25
|
const utils_2 = require("./sidebars/utils");
|
|
26
26
|
const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
|
|
27
27
|
async function pluginContentDocs(context, options) {
|
|
28
|
-
var _a;
|
|
29
28
|
const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
|
|
30
29
|
const versionsMetadata = await (0, versions_1.readVersionsMetadata)({ context, options });
|
|
31
|
-
const pluginId =
|
|
30
|
+
const pluginId = options.id ?? utils_1.DEFAULT_PLUGIN_ID;
|
|
32
31
|
const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
|
|
33
32
|
const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
|
|
34
33
|
const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
|
package/lib/lastUpdate.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getFileLastUpdate = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const logger_1 =
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
let showedGitRequirementError = false;
|
|
14
14
|
async function getFileLastUpdate(filePath) {
|
package/lib/numberPrefix.js
CHANGED
|
@@ -23,13 +23,12 @@ const NumberPrefixRegex = /^(?<numberPrefix>\d+)(?<separator>\s*[-_.]+\s*)(?<suf
|
|
|
23
23
|
// 0-myDoc => {filename: myDoc, numberPrefix: 0}
|
|
24
24
|
// 003 - myDoc => {filename: myDoc, numberPrefix: 3}
|
|
25
25
|
const DefaultNumberPrefixParser = (filename) => {
|
|
26
|
-
var _a, _b, _c;
|
|
27
26
|
if (IgnoredPrefixPatterns.exec(filename)) {
|
|
28
27
|
return { filename, numberPrefix: undefined };
|
|
29
28
|
}
|
|
30
29
|
const match = NumberPrefixRegex.exec(filename);
|
|
31
|
-
const cleanFileName =
|
|
32
|
-
const numberPrefixString =
|
|
30
|
+
const cleanFileName = match?.groups?.suffix ?? filename;
|
|
31
|
+
const numberPrefixString = match?.groups?.numberPrefix;
|
|
33
32
|
const numberPrefix = numberPrefixString
|
|
34
33
|
? parseInt(numberPrefixString, 10)
|
|
35
34
|
: undefined;
|
package/lib/options.js
CHANGED
|
@@ -10,8 +10,8 @@ exports.validateOptions = exports.OptionsSchema = exports.DEFAULT_OPTIONS = void
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
|
-
const logger_1 =
|
|
14
|
-
const remark_admonitions_1 =
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
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");
|
|
17
17
|
exports.DEFAULT_OPTIONS = {
|
package/lib/props.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.toTagDocListProp = exports.toVersionMetadataProp = exports.toSidebarsProp = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const lodash_1 =
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const docs_1 = require("./docs");
|
|
13
13
|
function toSidebarsProp(loadedVersion) {
|
|
14
14
|
const docsById = (0, docs_1.createDocsByIdIndex)(loadedVersion.docs);
|
|
@@ -22,7 +22,6 @@ Available document ids are:
|
|
|
22
22
|
return docMetadata;
|
|
23
23
|
}
|
|
24
24
|
const convertDocLink = (item) => {
|
|
25
|
-
var _a;
|
|
26
25
|
const docMetadata = getDocById(item.id);
|
|
27
26
|
const { title, permalink, frontMatter: { sidebar_label: sidebarLabel }, } = docMetadata;
|
|
28
27
|
return {
|
|
@@ -30,12 +29,12 @@ Available document ids are:
|
|
|
30
29
|
label: sidebarLabel || item.label || title,
|
|
31
30
|
href: permalink,
|
|
32
31
|
className: item.className,
|
|
33
|
-
customProps:
|
|
32
|
+
customProps: item.customProps ?? docMetadata.frontMatter.sidebar_custom_props,
|
|
34
33
|
docId: docMetadata.unversionedId,
|
|
35
34
|
};
|
|
36
35
|
};
|
|
37
36
|
function getCategoryLinkHref(link) {
|
|
38
|
-
switch (link
|
|
37
|
+
switch (link?.type) {
|
|
39
38
|
case 'doc':
|
|
40
39
|
return getDocById(link.id).permalink;
|
|
41
40
|
case 'generated-index':
|
package/lib/routes.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.createVersionRoutes = exports.createDocRoutes = exports.createCategoryGe
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
12
|
const props_1 = require("./props");
|
|
13
|
-
const logger_1 =
|
|
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,14 +8,12 @@
|
|
|
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 =
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
|
-
const logger_1 =
|
|
14
|
-
const path_1 =
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
15
15
|
const docs_1 = require("../docs");
|
|
16
16
|
const BreadcrumbSeparator = '/';
|
|
17
|
-
// To avoid possible name clashes with a folder of the same name as the ID
|
|
18
|
-
const docIdPrefix = '$doc$/';
|
|
19
17
|
// Just an alias to the make code more explicit
|
|
20
18
|
function getLocalDocId(docId) {
|
|
21
19
|
return lodash_1.default.last(docId.split('/'));
|
|
@@ -72,14 +70,16 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryInde
|
|
|
72
70
|
const treeRoot = {};
|
|
73
71
|
docs.forEach((doc) => {
|
|
74
72
|
const breadcrumb = getRelativeBreadcrumb(doc);
|
|
75
|
-
|
|
73
|
+
// We walk down the file's path to generate the fs structure
|
|
74
|
+
let currentDir = treeRoot;
|
|
76
75
|
breadcrumb.forEach((dir) => {
|
|
77
76
|
if (typeof currentDir[dir] === 'undefined') {
|
|
78
77
|
currentDir[dir] = {}; // Create new folder.
|
|
79
78
|
}
|
|
80
79
|
currentDir = currentDir[dir]; // Go into the subdirectory.
|
|
81
80
|
});
|
|
82
|
-
|
|
81
|
+
// We've walked through the path. Register the file in this directory.
|
|
82
|
+
currentDir[path_1.default.basename(doc.source)] = doc.id;
|
|
83
83
|
});
|
|
84
84
|
return treeRoot;
|
|
85
85
|
}
|
|
@@ -88,24 +88,24 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryInde
|
|
|
88
88
|
* (From a record to an array of items, akin to normalizing shorthand)
|
|
89
89
|
*/
|
|
90
90
|
function generateSidebar(fsModel) {
|
|
91
|
-
function createDocItem(id) {
|
|
91
|
+
function createDocItem(id, fullPath, fileName) {
|
|
92
92
|
const { sidebarPosition: position, frontMatter: { sidebar_label: label, sidebar_class_name: className }, } = getDoc(id);
|
|
93
93
|
return {
|
|
94
94
|
type: 'doc',
|
|
95
95
|
id,
|
|
96
96
|
position,
|
|
97
|
+
source: fileName,
|
|
97
98
|
// We don't want these fields to magically appear in the generated
|
|
98
99
|
// sidebar
|
|
99
100
|
...(label !== undefined && { label }),
|
|
100
101
|
...(className !== undefined && { className }),
|
|
101
102
|
};
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
-
var _a, _b;
|
|
104
|
+
function createCategoryItem(dir, fullPath, folderName) {
|
|
105
105
|
const categoryMetadata = categoriesMetadata[(0, utils_1.posixPath)(path_1.default.join(autogenDir, fullPath))];
|
|
106
|
-
const className = categoryMetadata
|
|
106
|
+
const className = categoryMetadata?.className;
|
|
107
107
|
const { filename, numberPrefix } = numberPrefixParser(folderName);
|
|
108
|
-
const allItems =
|
|
108
|
+
const allItems = Object.entries(dir).map(([key, content]) => dirToItem(content, key, `${fullPath}/${key}`));
|
|
109
109
|
// Try to match a doc inside the category folder,
|
|
110
110
|
// using the "local id" (myDoc) or "qualified id" (dirName/myDoc)
|
|
111
111
|
function findDocByLocalId(localId) {
|
|
@@ -121,18 +121,17 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryInde
|
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
function getCategoryLinkedDocId() {
|
|
124
|
-
|
|
125
|
-
const link = categoryMetadata === null || categoryMetadata === void 0 ? void 0 : categoryMetadata.link;
|
|
124
|
+
const link = categoryMetadata?.link;
|
|
126
125
|
if (link !== undefined) {
|
|
127
126
|
if (link && link.type === 'doc') {
|
|
128
|
-
return
|
|
127
|
+
return findDocByLocalId(link.id)?.id || getDoc(link.id).id;
|
|
129
128
|
}
|
|
130
129
|
// If a link is explicitly specified, we won't apply conventions
|
|
131
130
|
return undefined;
|
|
132
131
|
}
|
|
133
132
|
// Apply default convention to pick index.md, README.md or
|
|
134
133
|
// <categoryName>.md as the category doc
|
|
135
|
-
return
|
|
134
|
+
return findConventionalCategoryDocLink()?.id;
|
|
136
135
|
}
|
|
137
136
|
const categoryLinkedDocId = getCategoryLinkedDocId();
|
|
138
137
|
const link = categoryLinkedDocId
|
|
@@ -140,28 +139,29 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryInde
|
|
|
140
139
|
type: 'doc',
|
|
141
140
|
id: categoryLinkedDocId, // We "remap" a potentially "local id" to a "qualified id"
|
|
142
141
|
}
|
|
143
|
-
: categoryMetadata
|
|
142
|
+
: categoryMetadata?.link;
|
|
144
143
|
// If a doc is linked, remove it from the category subItems
|
|
145
144
|
const items = allItems.filter((item) => !(item.type === 'doc' && item.id === categoryLinkedDocId));
|
|
146
145
|
return {
|
|
147
146
|
type: 'category',
|
|
148
|
-
label:
|
|
149
|
-
collapsible: categoryMetadata
|
|
150
|
-
collapsed: categoryMetadata
|
|
151
|
-
position:
|
|
147
|
+
label: categoryMetadata?.label ?? filename,
|
|
148
|
+
collapsible: categoryMetadata?.collapsible,
|
|
149
|
+
collapsed: categoryMetadata?.collapsed,
|
|
150
|
+
position: categoryMetadata?.position ?? numberPrefix,
|
|
151
|
+
source: folderName,
|
|
152
152
|
...(className !== undefined && { className }),
|
|
153
153
|
items,
|
|
154
154
|
...(link && { link }),
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
|
-
|
|
158
|
-
itemKey, //
|
|
157
|
+
function dirToItem(dir, // The directory item to be transformed.
|
|
158
|
+
itemKey, // File/folder name; for categories, it's used to generate the next `relativePath`.
|
|
159
159
|
fullPath) {
|
|
160
|
-
return dir
|
|
160
|
+
return typeof dir === 'object'
|
|
161
161
|
? createCategoryItem(dir, fullPath, itemKey)
|
|
162
|
-
: createDocItem(itemKey
|
|
162
|
+
: createDocItem(dir, fullPath, itemKey);
|
|
163
163
|
}
|
|
164
|
-
return
|
|
164
|
+
return Object.entries(fsModel).map(([key, content]) => dirToItem(content, key, key));
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
167
|
* Step 4. Recursively sort the categories/docs + remove the "position"
|
|
@@ -177,13 +177,16 @@ const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryInde
|
|
|
177
177
|
}
|
|
178
178
|
return item;
|
|
179
179
|
});
|
|
180
|
-
const sortedSidebarItems = lodash_1.default.sortBy(processedSidebarItems,
|
|
181
|
-
|
|
180
|
+
const sortedSidebarItems = lodash_1.default.sortBy(processedSidebarItems, [
|
|
181
|
+
'position',
|
|
182
|
+
'source',
|
|
183
|
+
]);
|
|
184
|
+
return sortedSidebarItems.map(({ position, source, ...item }) => item);
|
|
182
185
|
}
|
|
183
186
|
// TODO: the whole code is designed for pipeline operator
|
|
184
187
|
const docs = getAutogenDocs();
|
|
185
188
|
const fsModel = treeify(docs);
|
|
186
|
-
const sidebarWithPosition =
|
|
189
|
+
const sidebarWithPosition = generateSidebar(fsModel);
|
|
187
190
|
const sortedSidebar = sortItems(sidebarWithPosition);
|
|
188
191
|
return sortedSidebar;
|
|
189
192
|
};
|
package/lib/sidebars/index.js
CHANGED
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
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
|
-
const fs_extra_1 =
|
|
12
|
-
const import_fresh_1 =
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
13
13
|
const validation_1 = require("./validation");
|
|
14
14
|
const normalization_1 = require("./normalization");
|
|
15
15
|
const processor_1 = require("./processor");
|
|
16
16
|
const postProcessor_1 = require("./postProcessor");
|
|
17
|
-
const path_1 =
|
|
17
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
18
18
|
const utils_1 = require("@docusaurus/utils");
|
|
19
|
-
const logger_1 =
|
|
20
|
-
const js_yaml_1 =
|
|
21
|
-
const lodash_1 =
|
|
22
|
-
const combine_promises_1 =
|
|
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
|
{
|
|
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.normalizeSidebars = exports.normalizeItem = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
|
-
const lodash_1 =
|
|
13
|
-
const logger_1 =
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
14
|
function normalizeCategoriesShorthand(sidebar) {
|
|
15
15
|
return Object.entries(sidebar).map(([label, items]) => ({
|
|
16
16
|
type: 'category',
|
|
@@ -9,13 +9,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.postProcessSidebars = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const lodash_1 =
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
13
|
function normalizeCategoryLink(category, params) {
|
|
14
|
-
|
|
15
|
-
if (((_a = category.link) === null || _a === void 0 ? void 0 : _a.type) === 'generated-index') {
|
|
14
|
+
if (category.link?.type === 'generated-index') {
|
|
16
15
|
// default slug logic can be improved
|
|
17
16
|
const getDefaultSlug = () => `/category/${params.categoryLabelSlugger.slug(category.label)}`;
|
|
18
|
-
const slug =
|
|
17
|
+
const slug = category.link.slug ?? getDefaultSlug();
|
|
19
18
|
const permalink = (0, utils_1.normalizeUrl)([params.version.versionPath, slug]);
|
|
20
19
|
return {
|
|
21
20
|
...category.link,
|
|
@@ -26,12 +25,11 @@ function normalizeCategoryLink(category, params) {
|
|
|
26
25
|
return category.link;
|
|
27
26
|
}
|
|
28
27
|
function postProcessSidebarItem(item, params) {
|
|
29
|
-
var _a, _b;
|
|
30
28
|
if (item.type === 'category') {
|
|
31
29
|
const category = {
|
|
32
30
|
...item,
|
|
33
|
-
collapsed:
|
|
34
|
-
collapsible:
|
|
31
|
+
collapsed: item.collapsed ?? params.sidebarOptions.sidebarCollapsed,
|
|
32
|
+
collapsible: item.collapsible ?? params.sidebarOptions.sidebarCollapsible,
|
|
35
33
|
link: normalizeCategoryLink(item, params),
|
|
36
34
|
items: item.items.map((subItem) => postProcessSidebarItem(subItem, params)),
|
|
37
35
|
};
|
|
@@ -10,8 +10,8 @@ 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 =
|
|
14
|
-
const combine_promises_1 =
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
+
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
15
15
|
const docs_1 = require("../docs");
|
|
16
16
|
function toSidebarItemsGeneratorDoc(doc) {
|
|
17
17
|
return lodash_1.default.pick(doc, [
|
package/lib/sidebars/utils.js
CHANGED
|
@@ -8,7 +8,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
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const lodash_1 =
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
function isCategoriesShorthand(item) {
|
|
14
14
|
return typeof item === 'object' && !item.type;
|
|
@@ -58,9 +58,8 @@ exports.collectSidebarLinks = collectSidebarLinks;
|
|
|
58
58
|
// /!\ docId order matters for navigation!
|
|
59
59
|
function collectSidebarDocIds(sidebar) {
|
|
60
60
|
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
61
|
-
var _a;
|
|
62
61
|
if (item.type === 'category') {
|
|
63
|
-
return
|
|
62
|
+
return item.link?.type === 'doc' ? [item.link.id] : [];
|
|
64
63
|
}
|
|
65
64
|
if (item.type === 'doc') {
|
|
66
65
|
return [item.id];
|
|
@@ -95,8 +94,7 @@ function createSidebarsUtils(sidebars) {
|
|
|
95
94
|
// Reverse mapping
|
|
96
95
|
const docIdToSidebarName = Object.fromEntries(Object.entries(sidebarNameToDocIds).flatMap(([sidebarName, docIds]) => docIds.map((docId) => [docId, sidebarName])));
|
|
97
96
|
function getFirstDocIdOfFirstSidebar() {
|
|
98
|
-
|
|
99
|
-
return (_a = Object.values(sidebarNameToDocIds)[0]) === null || _a === void 0 ? void 0 : _a[0];
|
|
97
|
+
return Object.values(sidebarNameToDocIds)[0]?.[0];
|
|
100
98
|
}
|
|
101
99
|
function getSidebarNameByDocId(docId) {
|
|
102
100
|
return docIdToSidebarName[docId];
|
|
@@ -155,14 +153,12 @@ function createSidebarsUtils(sidebars) {
|
|
|
155
153
|
* unique). More reliable than using object identity
|
|
156
154
|
*/
|
|
157
155
|
function getCategoryGeneratedIndexNavigation(categoryGeneratedIndexPermalink) {
|
|
158
|
-
var _a;
|
|
159
156
|
function isCurrentCategoryGeneratedIndexItem(item) {
|
|
160
|
-
var _a;
|
|
161
157
|
return (item.type === 'category' &&
|
|
162
|
-
|
|
158
|
+
item.link?.type === 'generated-index' &&
|
|
163
159
|
item.link.permalink === categoryGeneratedIndexPermalink);
|
|
164
160
|
}
|
|
165
|
-
const sidebarName =
|
|
161
|
+
const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))?.[0];
|
|
166
162
|
if (!sidebarName) {
|
|
167
163
|
return emptySidebarNavigation();
|
|
168
164
|
}
|
|
@@ -184,24 +180,23 @@ Available document ids are:
|
|
|
184
180
|
}
|
|
185
181
|
}
|
|
186
182
|
function getFirstLink(sidebar) {
|
|
187
|
-
var _a, _b, _c;
|
|
188
183
|
for (const item of sidebar) {
|
|
189
184
|
if (item.type === 'doc') {
|
|
190
185
|
return {
|
|
191
186
|
type: 'doc',
|
|
192
187
|
id: item.id,
|
|
193
|
-
label:
|
|
188
|
+
label: item.label ?? item.id,
|
|
194
189
|
};
|
|
195
190
|
}
|
|
196
191
|
else if (item.type === 'category') {
|
|
197
|
-
if (
|
|
192
|
+
if (item.link?.type === 'doc') {
|
|
198
193
|
return {
|
|
199
194
|
type: 'doc',
|
|
200
195
|
id: item.link.id,
|
|
201
196
|
label: item.label,
|
|
202
197
|
};
|
|
203
198
|
}
|
|
204
|
-
else if (
|
|
199
|
+
else if (item.link?.type === 'generated-index') {
|
|
205
200
|
return {
|
|
206
201
|
type: 'generated-index',
|
|
207
202
|
slug: item.link.slug,
|
|
@@ -229,9 +224,8 @@ Available document ids are:
|
|
|
229
224
|
}
|
|
230
225
|
exports.createSidebarsUtils = createSidebarsUtils;
|
|
231
226
|
function toDocNavigationLink(doc) {
|
|
232
|
-
var _a;
|
|
233
227
|
const { title, permalink, frontMatter: { pagination_label: paginationLabel, sidebar_label: sidebarLabel, }, } = doc;
|
|
234
|
-
return { title:
|
|
228
|
+
return { title: paginationLabel ?? sidebarLabel ?? title, permalink };
|
|
235
229
|
}
|
|
236
230
|
exports.toDocNavigationLink = toDocNavigationLink;
|
|
237
231
|
function toNavigationLink(navigationItem, docsById) {
|
package/lib/slug.js
CHANGED
|
@@ -20,7 +20,7 @@ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumbe
|
|
|
20
20
|
return resolveDirname;
|
|
21
21
|
}
|
|
22
22
|
function computeSlug() {
|
|
23
|
-
if (frontMatterSlug
|
|
23
|
+
if (frontMatterSlug?.startsWith('/')) {
|
|
24
24
|
return frontMatterSlug;
|
|
25
25
|
}
|
|
26
26
|
const dirNameSlug = getDirNameSlug();
|
package/lib/tags.js
CHANGED
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.getVersionTags = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
-
const lodash_1 =
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
13
|
function getVersionTags(docs) {
|
|
14
14
|
const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
|
|
15
15
|
return lodash_1.default.mapValues(groups, (group) => ({
|
package/lib/translations.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const lodash_1 =
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const utils_1 = require("./sidebars/utils");
|
|
13
13
|
const utils_2 = require("@docusaurus/utils");
|
|
14
14
|
const constants_1 = require("./constants");
|
|
@@ -120,13 +120,12 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
120
120
|
}
|
|
121
121
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
122
122
|
function transformSidebarCategoryLink(category) {
|
|
123
|
-
var _a, _b, _c, _d;
|
|
124
123
|
if (!category.link) {
|
|
125
124
|
return undefined;
|
|
126
125
|
}
|
|
127
126
|
if (category.link.type === 'generated-index') {
|
|
128
|
-
const title =
|
|
129
|
-
const description =
|
|
127
|
+
const title = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.title`]?.message ?? category.link.title;
|
|
128
|
+
const description = sidebarsTranslations[`sidebar.${sidebarName}.category.${category.label}.link.generated-index.description`]?.message ?? category.link.description;
|
|
130
129
|
return {
|
|
131
130
|
...category.link,
|
|
132
131
|
title,
|
|
@@ -136,19 +135,20 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
|
136
135
|
return category.link;
|
|
137
136
|
}
|
|
138
137
|
return (0, utils_1.transformSidebarItems)(sidebar, (item) => {
|
|
139
|
-
var _a, _b, _c, _d;
|
|
140
138
|
if (item.type === 'category') {
|
|
141
139
|
const link = transformSidebarCategoryLink(item);
|
|
142
140
|
return {
|
|
143
141
|
...item,
|
|
144
|
-
label:
|
|
142
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.category.${item.label}`]
|
|
143
|
+
?.message ?? item.label,
|
|
145
144
|
...(link && { link }),
|
|
146
145
|
};
|
|
147
146
|
}
|
|
148
147
|
if (item.type === 'link') {
|
|
149
148
|
return {
|
|
150
149
|
...item,
|
|
151
|
-
label:
|
|
150
|
+
label: sidebarsTranslations[`sidebar.${sidebarName}.link.${item.label}`]
|
|
151
|
+
?.message ?? item.label,
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
return item;
|
|
@@ -195,11 +195,10 @@ function getVersionTranslationFiles(version) {
|
|
|
195
195
|
];
|
|
196
196
|
}
|
|
197
197
|
function translateVersion(version, translationFiles) {
|
|
198
|
-
var _a;
|
|
199
198
|
const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
|
|
200
199
|
return {
|
|
201
200
|
...version,
|
|
202
|
-
versionLabel:
|
|
201
|
+
versionLabel: versionTranslations['version.label']?.message,
|
|
203
202
|
sidebars: translateSidebars(version, versionTranslations),
|
|
204
203
|
// docs: translateDocs(version.docs, versionTranslations),
|
|
205
204
|
};
|
package/lib/versions.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getDocsDirPaths = exports.readVersionsMetadata = exports.filterVersions = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getVersionedSidebarsDirPath = exports.getVersionedDocsDirPath = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 =
|
|
12
|
-
const fs_extra_1 =
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const fs_extra_1 = 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 =
|
|
15
|
+
const lodash_1 = 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) {
|
|
@@ -62,7 +62,7 @@ async function readVersionNames(siteDir, options) {
|
|
|
62
62
|
if (!versionFileContent && options.disableVersioning) {
|
|
63
63
|
throw new Error(`Docs: using "disableVersioning: ${options.disableVersioning}" option on a non-versioned site does not make sense.`);
|
|
64
64
|
}
|
|
65
|
-
const versions = options.disableVersioning ? [] : versionFileContent
|
|
65
|
+
const versions = options.disableVersioning ? [] : versionFileContent ?? [];
|
|
66
66
|
// We add the current version at the beginning, unless:
|
|
67
67
|
// - user don't want to; or
|
|
68
68
|
// - it's already been explicitly added to versions.json
|
|
@@ -154,8 +154,7 @@ function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }
|
|
|
154
154
|
}
|
|
155
155
|
exports.getDefaultVersionBanner = getDefaultVersionBanner;
|
|
156
156
|
function getVersionBanner({ versionName, versionNames, lastVersionName, options, }) {
|
|
157
|
-
|
|
158
|
-
const versionBannerOption = (_a = options.versions[versionName]) === null || _a === void 0 ? void 0 : _a.banner;
|
|
157
|
+
const versionBannerOption = options.versions[versionName]?.banner;
|
|
159
158
|
if (versionBannerOption) {
|
|
160
159
|
return versionBannerOption === 'none' ? null : versionBannerOption;
|
|
161
160
|
}
|
|
@@ -167,23 +166,20 @@ function getVersionBanner({ versionName, versionNames, lastVersionName, options,
|
|
|
167
166
|
}
|
|
168
167
|
exports.getVersionBanner = getVersionBanner;
|
|
169
168
|
function getVersionBadge({ versionName, versionNames, options, }) {
|
|
170
|
-
|
|
171
|
-
const versionBadgeOption = (_a = options.versions[versionName]) === null || _a === void 0 ? void 0 : _a.badge;
|
|
169
|
+
const versionBadgeOption = options.versions[versionName]?.badge;
|
|
172
170
|
// If site is not versioned or only one version is included
|
|
173
171
|
// we don't show the version badge by default
|
|
174
172
|
// See https://github.com/facebook/docusaurus/issues/3362
|
|
175
173
|
const versionBadgeDefault = versionNames.length !== 1;
|
|
176
|
-
return versionBadgeOption
|
|
174
|
+
return versionBadgeOption ?? versionBadgeDefault;
|
|
177
175
|
}
|
|
178
176
|
exports.getVersionBadge = getVersionBadge;
|
|
179
177
|
function getVersionClassName({ versionName, options, }) {
|
|
180
|
-
|
|
181
|
-
const versionClassNameOption = (_a = options.versions[versionName]) === null || _a === void 0 ? void 0 : _a.className;
|
|
178
|
+
const versionClassNameOption = options.versions[versionName]?.className;
|
|
182
179
|
const versionClassNameDefault = `docs-version-${versionName}`;
|
|
183
|
-
return versionClassNameOption
|
|
180
|
+
return versionClassNameOption ?? versionClassNameDefault;
|
|
184
181
|
}
|
|
185
182
|
function createVersionMetadata({ versionName, versionNames, lastVersionName, context, options, }) {
|
|
186
|
-
var _a, _b, _c;
|
|
187
183
|
const { sidebarFilePath, contentPath, contentPathLocalized } = getVersionMetadataPaths({ versionName, context, options });
|
|
188
184
|
const isLast = versionName === lastVersionName;
|
|
189
185
|
// retro-compatible values
|
|
@@ -195,9 +191,9 @@ function createVersionMetadata({ versionName, versionNames, lastVersionName, con
|
|
|
195
191
|
return versionName === constants_1.CURRENT_VERSION_NAME ? 'next' : versionName;
|
|
196
192
|
}
|
|
197
193
|
const defaultVersionPathPart = getDefaultVersionPathPart();
|
|
198
|
-
const versionOptions =
|
|
199
|
-
const versionLabel =
|
|
200
|
-
const versionPathPart =
|
|
194
|
+
const versionOptions = options.versions[versionName] ?? {};
|
|
195
|
+
const versionLabel = versionOptions.label ?? defaultVersionLabel;
|
|
196
|
+
const versionPathPart = versionOptions.path ?? defaultVersionPathPart;
|
|
201
197
|
const versionPath = (0, utils_1.normalizeUrl)([
|
|
202
198
|
context.baseUrl,
|
|
203
199
|
options.routeBasePath,
|
|
@@ -219,8 +215,8 @@ function createVersionMetadata({ versionName, versionNames, lastVersionName, con
|
|
|
219
215
|
versionLabel,
|
|
220
216
|
versionPath,
|
|
221
217
|
tagsPath,
|
|
222
|
-
versionEditUrl: versionEditUrls
|
|
223
|
-
versionEditUrlLocalized: versionEditUrls
|
|
218
|
+
versionEditUrl: versionEditUrls?.versionEditUrl,
|
|
219
|
+
versionEditUrlLocalized: versionEditUrls?.versionEditUrlLocalized,
|
|
224
220
|
versionBanner: getVersionBanner({
|
|
225
221
|
versionName,
|
|
226
222
|
versionNames,
|
|
@@ -304,11 +300,10 @@ function filterVersions(versionNamesUnfiltered, options) {
|
|
|
304
300
|
}
|
|
305
301
|
exports.filterVersions = filterVersions;
|
|
306
302
|
async function readVersionsMetadata({ context, options, }) {
|
|
307
|
-
var _a;
|
|
308
303
|
const versionNamesUnfiltered = await readVersionNames(context.siteDir, options);
|
|
309
304
|
checkVersionsOptions(versionNamesUnfiltered, options);
|
|
310
305
|
const versionNames = filterVersions(versionNamesUnfiltered, options);
|
|
311
|
-
const lastVersionName =
|
|
306
|
+
const lastVersionName = options.lastVersion ?? getDefaultLastVersionName(versionNames);
|
|
312
307
|
const versionsMetadata = versionNames.map((versionName) => createVersionMetadata({
|
|
313
308
|
versionName,
|
|
314
309
|
versionNames,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.17",
|
|
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": "2.0.0-beta.
|
|
27
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
28
|
-
"@docusaurus/mdx-loader": "2.0.0-beta.
|
|
29
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
30
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
26
|
+
"@docusaurus/core": "2.0.0-beta.17",
|
|
27
|
+
"@docusaurus/logger": "2.0.0-beta.17",
|
|
28
|
+
"@docusaurus/mdx-loader": "2.0.0-beta.17",
|
|
29
|
+
"@docusaurus/utils": "2.0.0-beta.17",
|
|
30
|
+
"@docusaurus/utils-validation": "2.0.0-beta.17",
|
|
31
31
|
"combine-promises": "^1.1.0",
|
|
32
32
|
"fs-extra": "^10.0.1",
|
|
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": "2.0.0-beta.
|
|
43
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
42
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.17",
|
|
43
|
+
"@docusaurus/types": "2.0.0-beta.17",
|
|
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": "0032c0b0480083227af2e1b4da2d3ee6ce992403"
|
|
60
60
|
}
|
|
@@ -20,8 +20,6 @@ import path from 'path';
|
|
|
20
20
|
import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
|
|
21
21
|
|
|
22
22
|
const BreadcrumbSeparator = '/';
|
|
23
|
-
// To avoid possible name clashes with a folder of the same name as the ID
|
|
24
|
-
const docIdPrefix = '$doc$/';
|
|
25
23
|
|
|
26
24
|
// Just an alias to the make code more explicit
|
|
27
25
|
function getLocalDocId(docId: string): string {
|
|
@@ -31,16 +29,20 @@ function getLocalDocId(docId: string): string {
|
|
|
31
29
|
export const CategoryMetadataFilenameBase = '_category_';
|
|
32
30
|
export const CategoryMetadataFilenamePattern = '_category_.{json,yml,yaml}';
|
|
33
31
|
|
|
34
|
-
type WithPosition<T> = T & {
|
|
32
|
+
type WithPosition<T> = T & {
|
|
33
|
+
position?: number;
|
|
34
|
+
/** The source is the file/folder name */
|
|
35
|
+
source?: string;
|
|
36
|
+
};
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
39
|
* A representation of the fs structure. For each object entry:
|
|
38
40
|
* If it's a folder, the key is the directory name, and value is the directory
|
|
39
|
-
* content; If it's a doc file, the key is the doc
|
|
40
|
-
*
|
|
41
|
+
* content; If it's a doc file, the key is the doc's source file name, and value
|
|
42
|
+
* is the doc ID
|
|
41
43
|
*/
|
|
42
44
|
type Dir = {
|
|
43
|
-
[item: string]: Dir |
|
|
45
|
+
[item: string]: Dir | string;
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
// Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
|
|
@@ -108,14 +110,16 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
|
|
|
108
110
|
const treeRoot: Dir = {};
|
|
109
111
|
docs.forEach((doc) => {
|
|
110
112
|
const breadcrumb = getRelativeBreadcrumb(doc);
|
|
111
|
-
|
|
113
|
+
// We walk down the file's path to generate the fs structure
|
|
114
|
+
let currentDir = treeRoot;
|
|
112
115
|
breadcrumb.forEach((dir) => {
|
|
113
116
|
if (typeof currentDir[dir] === 'undefined') {
|
|
114
117
|
currentDir[dir] = {}; // Create new folder.
|
|
115
118
|
}
|
|
116
|
-
currentDir = currentDir[dir]
|
|
119
|
+
currentDir = currentDir[dir] as Dir; // Go into the subdirectory.
|
|
117
120
|
});
|
|
118
|
-
|
|
121
|
+
// We've walked through the path. Register the file in this directory.
|
|
122
|
+
currentDir[path.basename(doc.source)] = doc.id;
|
|
119
123
|
});
|
|
120
124
|
return treeRoot;
|
|
121
125
|
}
|
|
@@ -126,8 +130,12 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
|
|
|
126
130
|
*/
|
|
127
131
|
function generateSidebar(
|
|
128
132
|
fsModel: Dir,
|
|
129
|
-
):
|
|
130
|
-
function createDocItem(
|
|
133
|
+
): WithPosition<NormalizedSidebarItem>[] {
|
|
134
|
+
function createDocItem(
|
|
135
|
+
id: string,
|
|
136
|
+
fullPath: string,
|
|
137
|
+
fileName: string,
|
|
138
|
+
): WithPosition<SidebarItemDoc> {
|
|
131
139
|
const {
|
|
132
140
|
sidebarPosition: position,
|
|
133
141
|
frontMatter: {sidebar_label: label, sidebar_class_name: className},
|
|
@@ -136,25 +144,24 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
|
|
|
136
144
|
type: 'doc',
|
|
137
145
|
id,
|
|
138
146
|
position,
|
|
147
|
+
source: fileName,
|
|
139
148
|
// We don't want these fields to magically appear in the generated
|
|
140
149
|
// sidebar
|
|
141
150
|
...(label !== undefined && {label}),
|
|
142
151
|
...(className !== undefined && {className}),
|
|
143
152
|
};
|
|
144
153
|
}
|
|
145
|
-
|
|
154
|
+
function createCategoryItem(
|
|
146
155
|
dir: Dir,
|
|
147
156
|
fullPath: string,
|
|
148
157
|
folderName: string,
|
|
149
|
-
):
|
|
158
|
+
): WithPosition<NormalizedSidebarItemCategory> {
|
|
150
159
|
const categoryMetadata =
|
|
151
160
|
categoriesMetadata[posixPath(path.join(autogenDir, fullPath))];
|
|
152
161
|
const className = categoryMetadata?.className;
|
|
153
162
|
const {filename, numberPrefix} = numberPrefixParser(folderName);
|
|
154
|
-
const allItems =
|
|
155
|
-
|
|
156
|
-
dirToItem(content, key, `${fullPath}/${key}`),
|
|
157
|
-
),
|
|
163
|
+
const allItems = Object.entries(dir).map(([key, content]) =>
|
|
164
|
+
dirToItem(content, key, `${fullPath}/${key}`),
|
|
158
165
|
);
|
|
159
166
|
|
|
160
167
|
// Try to match a doc inside the category folder,
|
|
@@ -211,24 +218,23 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
|
|
|
211
218
|
collapsible: categoryMetadata?.collapsible,
|
|
212
219
|
collapsed: categoryMetadata?.collapsed,
|
|
213
220
|
position: categoryMetadata?.position ?? numberPrefix,
|
|
221
|
+
source: folderName,
|
|
214
222
|
...(className !== undefined && {className}),
|
|
215
223
|
items,
|
|
216
224
|
...(link && {link}),
|
|
217
225
|
};
|
|
218
226
|
}
|
|
219
|
-
|
|
220
|
-
dir: Dir |
|
|
221
|
-
itemKey: string, //
|
|
227
|
+
function dirToItem(
|
|
228
|
+
dir: Dir | string, // The directory item to be transformed.
|
|
229
|
+
itemKey: string, // File/folder name; for categories, it's used to generate the next `relativePath`.
|
|
222
230
|
fullPath: string, // `dir`'s full path relative to the autogen dir.
|
|
223
|
-
):
|
|
224
|
-
return dir
|
|
231
|
+
): WithPosition<NormalizedSidebarItem> {
|
|
232
|
+
return typeof dir === 'object'
|
|
225
233
|
? createCategoryItem(dir, fullPath, itemKey)
|
|
226
|
-
: createDocItem(itemKey
|
|
234
|
+
: createDocItem(dir, fullPath, itemKey);
|
|
227
235
|
}
|
|
228
|
-
return
|
|
229
|
-
|
|
230
|
-
dirToItem(content, key, key),
|
|
231
|
-
),
|
|
236
|
+
return Object.entries(fsModel).map(([key, content]) =>
|
|
237
|
+
dirToItem(content, key, key),
|
|
232
238
|
);
|
|
233
239
|
}
|
|
234
240
|
|
|
@@ -248,16 +254,16 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
|
|
|
248
254
|
}
|
|
249
255
|
return item;
|
|
250
256
|
});
|
|
251
|
-
const sortedSidebarItems = _.sortBy(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
);
|
|
255
|
-
return sortedSidebarItems.map(({position, ...item}) => item);
|
|
257
|
+
const sortedSidebarItems = _.sortBy(processedSidebarItems, [
|
|
258
|
+
'position',
|
|
259
|
+
'source',
|
|
260
|
+
]);
|
|
261
|
+
return sortedSidebarItems.map(({position, source, ...item}) => item);
|
|
256
262
|
}
|
|
257
263
|
// TODO: the whole code is designed for pipeline operator
|
|
258
264
|
const docs = getAutogenDocs();
|
|
259
265
|
const fsModel = treeify(docs);
|
|
260
|
-
const sidebarWithPosition =
|
|
266
|
+
const sidebarWithPosition = generateSidebar(fsModel);
|
|
261
267
|
const sortedSidebar = sortItems(sidebarWithPosition);
|
|
262
268
|
return sortedSidebar;
|
|
263
269
|
};
|