@docusaurus/plugin-content-docs 2.0.0-beta.20 → 2.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/categoryGeneratedIndex.d.ts +1 -1
- package/lib/cli.d.ts +1 -1
- package/lib/cli.js +8 -13
- package/lib/client/docsClientUtils.js +12 -20
- package/lib/client/index.js +29 -42
- package/lib/docs.d.ts +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -3
- package/lib/markdown/index.js +1 -1
- package/lib/options.d.ts +1 -1
- package/lib/options.js +1 -1
- package/lib/props.js +1 -1
- package/lib/routes.js +1 -1
- package/lib/sidebars/generator.js +3 -3
- package/lib/sidebars/index.d.ts +1 -1
- package/lib/sidebars/index.js +6 -6
- package/lib/sidebars/normalization.js +1 -1
- package/lib/sidebars/postProcessor.d.ts +3 -0
- package/lib/sidebars/postProcessor.js +33 -17
- package/lib/sidebars/processor.js +5 -16
- package/lib/sidebars/types.d.ts +2 -2
- package/lib/sidebars/utils.js +1 -1
- package/lib/sidebars/validation.js +5 -1
- package/lib/slug.js +1 -1
- package/lib/tags.js +1 -1
- package/lib/translations.js +8 -8
- package/lib/versions/files.d.ts +7 -0
- package/lib/versions/files.js +3 -2
- package/lib/versions/index.js +1 -1
- package/lib/versions/validation.js +1 -1
- package/package.json +13 -13
- package/src/categoryGeneratedIndex.ts +2 -2
- package/src/cli.ts +11 -15
- package/src/client/docsClientUtils.ts +1 -1
- package/src/client/index.ts +5 -2
- package/src/docs.ts +3 -3
- package/src/globalData.ts +1 -1
- package/src/index.ts +21 -17
- package/src/markdown/index.ts +1 -1
- package/src/markdown/linkify.ts +1 -1
- package/src/options.ts +5 -6
- package/src/plugin-content-docs.d.ts +19 -2
- package/src/props.ts +3 -3
- package/src/routes.ts +3 -3
- package/src/sidebars/README.md +1 -0
- package/src/sidebars/generator.ts +6 -6
- package/src/sidebars/index.ts +7 -7
- package/src/sidebars/normalization.ts +3 -3
- package/src/sidebars/postProcessor.ts +47 -24
- package/src/sidebars/processor.ts +8 -24
- package/src/sidebars/types.ts +2 -2
- package/src/sidebars/utils.ts +3 -4
- package/src/sidebars/validation.ts +6 -2
- package/src/slug.ts +1 -1
- package/src/tags.ts +1 -1
- package/src/translations.ts +8 -9
- package/src/types.ts +0 -2
- package/src/versions/files.ts +3 -3
- package/src/versions/index.ts +1 -1
- package/src/versions/validation.ts +3 -1
package/lib/tags.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getVersionTags = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const utils_1 = require("@docusaurus/utils");
|
|
12
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
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
|
@@ -9,9 +9,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
-
const utils_1 = require("
|
|
13
|
-
const utils_2 = require("@docusaurus/utils");
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
13
|
const constants_1 = require("./constants");
|
|
14
|
+
const utils_2 = require("./sidebars/utils");
|
|
15
15
|
function getVersionFileName(versionName) {
|
|
16
16
|
if (versionName === constants_1.CURRENT_VERSION_NAME) {
|
|
17
17
|
return versionName;
|
|
@@ -31,7 +31,7 @@ function getNormalizedSidebarName({ versionName, sidebarName, }) {
|
|
|
31
31
|
return rest.join('/');
|
|
32
32
|
}
|
|
33
33
|
function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
34
|
-
const categories = (0,
|
|
34
|
+
const categories = (0, utils_2.collectSidebarCategories)(sidebar);
|
|
35
35
|
const categoryContent = Object.fromEntries(categories.flatMap((category) => {
|
|
36
36
|
const entries = [];
|
|
37
37
|
entries.push([
|
|
@@ -63,7 +63,7 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
63
63
|
}
|
|
64
64
|
return entries;
|
|
65
65
|
}));
|
|
66
|
-
const links = (0,
|
|
66
|
+
const links = (0, utils_2.collectSidebarLinks)(sidebar);
|
|
67
67
|
const linksContent = Object.fromEntries(links.map((link) => [
|
|
68
68
|
`sidebar.${sidebarName}.link.${link.label}`,
|
|
69
69
|
{
|
|
@@ -71,7 +71,7 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
|
|
|
71
71
|
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
|
|
72
72
|
},
|
|
73
73
|
]));
|
|
74
|
-
return (0,
|
|
74
|
+
return (0, utils_1.mergeTranslations)([categoryContent, linksContent]);
|
|
75
75
|
}
|
|
76
76
|
function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
77
77
|
function transformSidebarCategoryLink(category) {
|
|
@@ -89,7 +89,7 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
|
89
89
|
}
|
|
90
90
|
return category.link;
|
|
91
91
|
}
|
|
92
|
-
return (0,
|
|
92
|
+
return (0, utils_2.transformSidebarItems)(sidebar, (item) => {
|
|
93
93
|
if (item.type === 'category') {
|
|
94
94
|
const link = transformSidebarCategoryLink(item);
|
|
95
95
|
return {
|
|
@@ -110,7 +110,7 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
function getSidebarsTranslations(version) {
|
|
113
|
-
return (0,
|
|
113
|
+
return (0, utils_1.mergeTranslations)(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
|
|
114
114
|
const normalizedSidebarName = getNormalizedSidebarName({
|
|
115
115
|
sidebarName,
|
|
116
116
|
versionName: version.versionName,
|
|
@@ -139,7 +139,7 @@ function getVersionTranslationFiles(version) {
|
|
|
139
139
|
return [
|
|
140
140
|
{
|
|
141
141
|
path: getVersionFileName(version.versionName),
|
|
142
|
-
content: (0,
|
|
142
|
+
content: (0, utils_1.mergeTranslations)([versionTranslations, sidebarsTranslations]),
|
|
143
143
|
},
|
|
144
144
|
];
|
|
145
145
|
}
|
package/lib/versions/files.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ export declare function getDocsDirPathLocalized({ siteDir, locale, pluginId, ver
|
|
|
18
18
|
}): string;
|
|
19
19
|
/** `community` => `[siteDir]/community_versions.json` */
|
|
20
20
|
export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Reads the plugin's respective `versions.json` file, and returns its content.
|
|
23
|
+
*
|
|
24
|
+
* @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
|
|
25
|
+
* array of valid version names.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readVersionsFile(siteDir: string, pluginId: string): Promise<string[] | null>;
|
|
21
28
|
/**
|
|
22
29
|
* Reads the `versions.json` file, and returns an ordered list of version names.
|
|
23
30
|
*
|
package/lib/versions/files.js
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getVersionMetadataPaths = exports.readVersionNames = exports.getVersionsFilePath = exports.getDocsDirPathLocalized = exports.getVersionSidebarsPath = exports.getVersionDocsDirPath = void 0;
|
|
9
|
+
exports.getVersionMetadataPaths = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getDocsDirPathLocalized = exports.getVersionSidebarsPath = exports.getVersionDocsDirPath = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
14
|
const constants_1 = require("../constants");
|
|
14
15
|
const validation_1 = require("./validation");
|
|
15
|
-
const utils_1 = require("@docusaurus/utils");
|
|
16
16
|
/** Add a prefix like `community_version-1.0.0`. No-op for default instance. */
|
|
17
17
|
function addPluginIdPrefix(fileOrDir, pluginId) {
|
|
18
18
|
return pluginId === utils_1.DEFAULT_PLUGIN_ID
|
|
@@ -63,6 +63,7 @@ async function readVersionsFile(siteDir, pluginId) {
|
|
|
63
63
|
}
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
|
+
exports.readVersionsFile = readVersionsFile;
|
|
66
67
|
/**
|
|
67
68
|
* Reads the `versions.json` file, and returns an ordered list of version names.
|
|
68
69
|
*
|
package/lib/versions/index.js
CHANGED
|
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.readVersionsMetadata = exports.filterVersions = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
-
const constants_1 = require("../constants");
|
|
13
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
14
|
const validation_1 = require("./validation");
|
|
15
15
|
const files_1 = require("./files");
|
|
16
16
|
function getVersionEditUrls({ contentPath, contentPathLocalized, context, options, }) {
|
|
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
function validateVersionName(name) {
|
|
13
13
|
if (typeof name !== 'string') {
|
|
14
|
-
throw new Error(`Versions should be strings. Found type "${typeof name}" for version
|
|
14
|
+
throw new Error(`Versions should be strings. Found type "${typeof name}" for version ${JSON.stringify(name)}.`);
|
|
15
15
|
}
|
|
16
16
|
if (!name.trim()) {
|
|
17
17
|
throw new Error(`Invalid version name "${name}": version name must contain at least one non-whitespace character.`);
|
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.21",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"types": "src/plugin-content-docs.d.ts",
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "tsc",
|
|
16
|
-
"watch": "tsc --watch"
|
|
15
|
+
"build": "tsc --build",
|
|
16
|
+
"watch": "tsc --build --watch"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
29
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
30
|
-
"@docusaurus/mdx-loader": "2.0.0-beta.
|
|
31
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
32
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
28
|
+
"@docusaurus/core": "2.0.0-beta.21",
|
|
29
|
+
"@docusaurus/logger": "2.0.0-beta.21",
|
|
30
|
+
"@docusaurus/mdx-loader": "2.0.0-beta.21",
|
|
31
|
+
"@docusaurus/utils": "2.0.0-beta.21",
|
|
32
|
+
"@docusaurus/utils-validation": "2.0.0-beta.21",
|
|
33
33
|
"combine-promises": "^1.1.0",
|
|
34
34
|
"fs-extra": "^10.1.0",
|
|
35
35
|
"import-fresh": "^3.3.0",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"remark-admonitions": "^1.2.1",
|
|
39
39
|
"tslib": "^2.4.0",
|
|
40
40
|
"utility-types": "^3.10.0",
|
|
41
|
-
"webpack": "^5.72.
|
|
41
|
+
"webpack": "^5.72.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
45
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
44
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.21",
|
|
45
|
+
"@docusaurus/types": "2.0.0-beta.21",
|
|
46
46
|
"@types/js-yaml": "^4.0.5",
|
|
47
47
|
"@types/picomatch": "^2.3.0",
|
|
48
48
|
"commander": "^5.1.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
|
-
"node": ">=14"
|
|
59
|
+
"node": ">=16.14"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "69ac49fc6909517f13615ee40290c4bd00c39df4"
|
|
62
62
|
}
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {type SidebarsUtils, toNavigationLink} from './sidebars/utils';
|
|
9
|
+
import {createDocsByIdIndex} from './docs';
|
|
8
10
|
import type {
|
|
9
11
|
CategoryGeneratedIndexMetadata,
|
|
10
12
|
DocMetadataBase,
|
|
11
13
|
} from '@docusaurus/plugin-content-docs';
|
|
12
14
|
import type {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
|
|
13
|
-
import {type SidebarsUtils, toNavigationLink} from './sidebars/utils';
|
|
14
|
-
import {createDocsByIdIndex} from './docs';
|
|
15
15
|
|
|
16
16
|
function getCategoryGeneratedIndexMetadata({
|
|
17
17
|
category,
|
package/src/cli.ts
CHANGED
|
@@ -5,20 +5,21 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import logger from '@docusaurus/logger';
|
|
11
|
+
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
|
|
8
12
|
import {
|
|
9
13
|
getVersionsFilePath,
|
|
10
14
|
getVersionDocsDirPath,
|
|
11
15
|
getVersionSidebarsPath,
|
|
12
16
|
getDocsDirPathLocalized,
|
|
17
|
+
readVersionsFile,
|
|
13
18
|
} from './versions/files';
|
|
14
19
|
import {validateVersionName} from './versions/validation';
|
|
15
|
-
import fs from 'fs-extra';
|
|
16
|
-
import path from 'path';
|
|
17
|
-
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
|
|
18
20
|
import {loadSidebarsFileUnsafe} from './sidebars';
|
|
19
21
|
import {CURRENT_VERSION_NAME} from './constants';
|
|
20
|
-
import {
|
|
21
|
-
import logger from '@docusaurus/logger';
|
|
22
|
+
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
|
|
22
23
|
import type {LoadContext} from '@docusaurus/types';
|
|
23
24
|
|
|
24
25
|
async function createVersionedSidebarFile({
|
|
@@ -53,7 +54,7 @@ async function createVersionedSidebarFile({
|
|
|
53
54
|
|
|
54
55
|
// Tests depend on non-default export for mocking.
|
|
55
56
|
export async function cliDocsVersionCommand(
|
|
56
|
-
version:
|
|
57
|
+
version: unknown,
|
|
57
58
|
{id: pluginId, path: docsPath, sidebarPath}: PluginOptions,
|
|
58
59
|
{siteDir, i18n}: LoadContext,
|
|
59
60
|
): Promise<void> {
|
|
@@ -64,17 +65,12 @@ export async function cliDocsVersionCommand(
|
|
|
64
65
|
|
|
65
66
|
try {
|
|
66
67
|
validateVersionName(version);
|
|
67
|
-
} catch (
|
|
68
|
+
} catch (err) {
|
|
68
69
|
logger.info`${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
|
|
69
|
-
throw
|
|
70
|
+
throw err;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
let versions = [];
|
|
74
|
-
const versionsJSONFile = getVersionsFilePath(siteDir, pluginId);
|
|
75
|
-
if (await fs.pathExists(versionsJSONFile)) {
|
|
76
|
-
versions = await fs.readJSON(versionsJSONFile);
|
|
77
|
-
}
|
|
73
|
+
const versions = (await readVersionsFile(siteDir, pluginId)) ?? [];
|
|
78
74
|
|
|
79
75
|
// Check if version already exists.
|
|
80
76
|
if (versions.includes(version)) {
|
|
@@ -137,7 +133,7 @@ export async function cliDocsVersionCommand(
|
|
|
137
133
|
// Update versions.json file.
|
|
138
134
|
versions.unshift(version);
|
|
139
135
|
await fs.outputFile(
|
|
140
|
-
|
|
136
|
+
getVersionsFilePath(siteDir, pluginId),
|
|
141
137
|
`${JSON.stringify(versions, null, 2)}\n`,
|
|
142
138
|
);
|
|
143
139
|
|
|
@@ -126,6 +126,6 @@ export function getDocVersionSuggestions(
|
|
|
126
126
|
const latestVersion = getLatestVersion(data);
|
|
127
127
|
const activeDocContext = getActiveDocContext(data, pathname);
|
|
128
128
|
const latestDocSuggestion: GlobalDoc | undefined =
|
|
129
|
-
activeDocContext
|
|
129
|
+
activeDocContext.alternateDocVersions[latestVersion.name];
|
|
130
130
|
return {latestDocSuggestion, latestVersionSuggestion: latestVersion};
|
|
131
131
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -34,8 +34,11 @@ const StableEmptyObject = {};
|
|
|
34
34
|
// In blog-only mode, docs hooks are still used by the theme. We need a fail-
|
|
35
35
|
// safe fallback when the docs plugin is not in use
|
|
36
36
|
export const useAllDocsData = (): {[pluginId: string]: GlobalPluginData} =>
|
|
37
|
-
useAllPluginInstancesData('docusaurus-plugin-content-docs')
|
|
38
|
-
|
|
37
|
+
(useAllPluginInstancesData('docusaurus-plugin-content-docs') as
|
|
38
|
+
| {
|
|
39
|
+
[pluginId: string]: GlobalPluginData;
|
|
40
|
+
}
|
|
41
|
+
| undefined) ?? StableEmptyObject;
|
|
39
42
|
|
|
40
43
|
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
|
41
44
|
usePluginData('docusaurus-plugin-content-docs', pluginId, {
|
package/src/docs.ts
CHANGED
|
@@ -19,15 +19,12 @@ import {
|
|
|
19
19
|
Globby,
|
|
20
20
|
normalizeFrontMatterTags,
|
|
21
21
|
} from '@docusaurus/utils';
|
|
22
|
-
import type {LoadContext} from '@docusaurus/types';
|
|
23
22
|
|
|
24
23
|
import {getFileLastUpdate} from './lastUpdate';
|
|
25
|
-
import type {DocFile} from './types';
|
|
26
24
|
import getSlug from './slug';
|
|
27
25
|
import {CURRENT_VERSION_NAME} from './constants';
|
|
28
26
|
import {stripPathNumberPrefixes} from './numberPrefix';
|
|
29
27
|
import {validateDocFrontMatter} from './frontMatter';
|
|
30
|
-
import type {SidebarsUtils} from './sidebars/utils';
|
|
31
28
|
import {toDocNavigationLink, toNavigationLink} from './sidebars/utils';
|
|
32
29
|
import type {
|
|
33
30
|
MetadataOptions,
|
|
@@ -41,6 +38,9 @@ import type {
|
|
|
41
38
|
DocFrontMatter,
|
|
42
39
|
LoadedVersion,
|
|
43
40
|
} from '@docusaurus/plugin-content-docs';
|
|
41
|
+
import type {LoadContext} from '@docusaurus/types';
|
|
42
|
+
import type {SidebarsUtils} from './sidebars/utils';
|
|
43
|
+
import type {DocFile} from './types';
|
|
44
44
|
|
|
45
45
|
type LastUpdateOptions = Pick<
|
|
46
46
|
PluginOptions,
|
package/src/globalData.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import _ from 'lodash';
|
|
9
|
-
import type {Sidebars} from './sidebars/types';
|
|
10
9
|
import {getMainDocId} from './docs';
|
|
11
10
|
import type {FullVersion} from './types';
|
|
12
11
|
import type {
|
|
@@ -18,6 +17,7 @@ import type {
|
|
|
18
17
|
GlobalSidebar,
|
|
19
18
|
GlobalDoc,
|
|
20
19
|
} from '@docusaurus/plugin-content-docs/client';
|
|
20
|
+
import type {Sidebars} from './sidebars/types';
|
|
21
21
|
|
|
22
22
|
function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
|
23
23
|
return {
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
|
-
|
|
9
|
+
import _ from 'lodash';
|
|
10
|
+
import logger from '@docusaurus/logger';
|
|
10
11
|
import {
|
|
11
12
|
normalizeUrl,
|
|
12
13
|
docuHash,
|
|
@@ -19,20 +20,15 @@ import {
|
|
|
19
20
|
createSlugger,
|
|
20
21
|
DEFAULT_PLUGIN_ID,
|
|
21
22
|
} from '@docusaurus/utils';
|
|
22
|
-
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
23
23
|
import {loadSidebars, resolveSidebarPathOption} from './sidebars';
|
|
24
24
|
import {CategoryMetadataFilenamePattern} from './sidebars/generator';
|
|
25
|
-
import
|
|
26
|
-
|
|
25
|
+
import {
|
|
26
|
+
readVersionDocs,
|
|
27
|
+
processDocMetadata,
|
|
28
|
+
addDocNavigation,
|
|
29
|
+
type DocEnv,
|
|
30
|
+
} from './docs';
|
|
27
31
|
import {readVersionsMetadata} from './versions';
|
|
28
|
-
import type {
|
|
29
|
-
SourceToPermalink,
|
|
30
|
-
DocFile,
|
|
31
|
-
DocsMarkdownOption,
|
|
32
|
-
VersionTag,
|
|
33
|
-
FullVersion,
|
|
34
|
-
} from './types';
|
|
35
|
-
import type {RuleSetRule} from 'webpack';
|
|
36
32
|
import {cliDocsVersionCommand} from './cli';
|
|
37
33
|
import {VERSIONS_JSON_FILE} from './constants';
|
|
38
34
|
import {toGlobalDataVersion} from './globalData';
|
|
@@ -42,9 +38,10 @@ import {
|
|
|
42
38
|
translateLoadedContent,
|
|
43
39
|
getLoadedContentTranslationFiles,
|
|
44
40
|
} from './translations';
|
|
45
|
-
import logger from '@docusaurus/logger';
|
|
46
41
|
import {getVersionTags} from './tags';
|
|
47
42
|
import {createVersionRoutes} from './routes';
|
|
43
|
+
import {createSidebarsUtils} from './sidebars/utils';
|
|
44
|
+
|
|
48
45
|
import type {
|
|
49
46
|
PropTagsListPage,
|
|
50
47
|
PluginOptions,
|
|
@@ -54,8 +51,15 @@ import type {
|
|
|
54
51
|
LoadedContent,
|
|
55
52
|
LoadedVersion,
|
|
56
53
|
} from '@docusaurus/plugin-content-docs';
|
|
57
|
-
import {
|
|
58
|
-
import
|
|
54
|
+
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
55
|
+
import type {
|
|
56
|
+
SourceToPermalink,
|
|
57
|
+
DocFile,
|
|
58
|
+
DocsMarkdownOption,
|
|
59
|
+
VersionTag,
|
|
60
|
+
FullVersion,
|
|
61
|
+
} from './types';
|
|
62
|
+
import type {RuleSetRule} from 'webpack';
|
|
59
63
|
|
|
60
64
|
export default async function pluginContentDocs(
|
|
61
65
|
context: LoadContext,
|
|
@@ -96,7 +100,7 @@ export default async function pluginContentDocs(
|
|
|
96
100
|
.command(command)
|
|
97
101
|
.arguments('<version>')
|
|
98
102
|
.description(commandDescription)
|
|
99
|
-
.action((version) => {
|
|
103
|
+
.action((version: unknown) => {
|
|
100
104
|
cliDocsVersionCommand(version, options, context);
|
|
101
105
|
});
|
|
102
106
|
},
|
|
@@ -139,7 +143,7 @@ export default async function pluginContentDocs(
|
|
|
139
143
|
)}".`,
|
|
140
144
|
);
|
|
141
145
|
}
|
|
142
|
-
|
|
146
|
+
function processVersionDoc(docFile: DocFile) {
|
|
143
147
|
return processDocMetadata({
|
|
144
148
|
docFile,
|
|
145
149
|
versionMetadata,
|
package/src/markdown/index.ts
CHANGED
|
@@ -16,5 +16,5 @@ export default function markdownLoader(
|
|
|
16
16
|
const fileString = source;
|
|
17
17
|
const callback = this.async();
|
|
18
18
|
const options = this.getOptions();
|
|
19
|
-
return callback
|
|
19
|
+
return callback(null, linkify(fileString, this.resourcePath, options));
|
|
20
20
|
}
|
package/src/markdown/linkify.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {DocsMarkdownOption} from '../types';
|
|
9
8
|
import {replaceMarkdownLinks, getContentPathList} from '@docusaurus/utils';
|
|
9
|
+
import type {DocsMarkdownOption} from '../types';
|
|
10
10
|
|
|
11
11
|
function getVersion(filePath: string, options: DocsMarkdownOption) {
|
|
12
12
|
const versionFound = options.versionsMetadata.find((version) =>
|
package/src/options.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 logger from '@docusaurus/logger';
|
|
9
9
|
import {
|
|
10
10
|
Joi,
|
|
11
11
|
RemarkPluginsSchema,
|
|
@@ -14,15 +14,14 @@ import {
|
|
|
14
14
|
URISchema,
|
|
15
15
|
} from '@docusaurus/utils-validation';
|
|
16
16
|
import {GlobExcludeDefault} from '@docusaurus/utils';
|
|
17
|
-
|
|
18
|
-
import type {OptionValidationContext} from '@docusaurus/types';
|
|
19
|
-
import logger from '@docusaurus/logger';
|
|
20
17
|
import admonitions from 'remark-admonitions';
|
|
21
18
|
import {DefaultSidebarItemsGenerator} from './sidebars/generator';
|
|
22
19
|
import {
|
|
23
20
|
DefaultNumberPrefixParser,
|
|
24
21
|
DisabledNumberPrefixParser,
|
|
25
22
|
} from './numberPrefix';
|
|
23
|
+
import type {OptionValidationContext} from '@docusaurus/types';
|
|
24
|
+
import type {PluginOptions, Options} from '@docusaurus/plugin-content-docs';
|
|
26
25
|
|
|
27
26
|
export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
|
|
28
27
|
path: 'docs', // Path to data on filesystem, relative to site dir.
|
|
@@ -99,7 +98,7 @@ const OptionsSchema = Joi.object<PluginOptions>({
|
|
|
99
98
|
Joi.function(),
|
|
100
99
|
// Convert boolean values to functions
|
|
101
100
|
Joi.alternatives().conditional(Joi.boolean(), {
|
|
102
|
-
then: Joi.custom((val) =>
|
|
101
|
+
then: Joi.custom((val: boolean) =>
|
|
103
102
|
val ? DefaultNumberPrefixParser : DisabledNumberPrefixParser,
|
|
104
103
|
),
|
|
105
104
|
}),
|
|
@@ -166,7 +165,7 @@ export function validateOptions({
|
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
167
|
|
|
169
|
-
const normalizedOptions = validate(OptionsSchema, options)
|
|
168
|
+
const normalizedOptions = validate(OptionsSchema, options);
|
|
170
169
|
|
|
171
170
|
if (normalizedOptions.admonitions) {
|
|
172
171
|
normalizedOptions.remarkPlugins = normalizedOptions.remarkPlugins.concat([
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/// <reference types="@docusaurus/module-type-aliases" />
|
|
9
|
+
|
|
8
10
|
declare module '@docusaurus/plugin-content-docs' {
|
|
9
11
|
import type {MDXOptions} from '@docusaurus/mdx-loader';
|
|
10
12
|
import type {
|
|
@@ -15,7 +17,7 @@ declare module '@docusaurus/plugin-content-docs' {
|
|
|
15
17
|
Tag,
|
|
16
18
|
} from '@docusaurus/utils';
|
|
17
19
|
import type {Plugin, LoadContext} from '@docusaurus/types';
|
|
18
|
-
import type {Required} from 'utility-types';
|
|
20
|
+
import type {Overwrite, Required} from 'utility-types';
|
|
19
21
|
|
|
20
22
|
export type Assets = {
|
|
21
23
|
image?: string;
|
|
@@ -204,7 +206,22 @@ declare module '@docusaurus/plugin-content-docs' {
|
|
|
204
206
|
*/
|
|
205
207
|
tagsBasePath: string;
|
|
206
208
|
};
|
|
207
|
-
export type Options = Partial<
|
|
209
|
+
export type Options = Partial<
|
|
210
|
+
Overwrite<
|
|
211
|
+
PluginOptions,
|
|
212
|
+
{
|
|
213
|
+
/**
|
|
214
|
+
* Custom parsing logic to extract number prefixes from file names. Use
|
|
215
|
+
* `false` to disable this behavior and leave the docs untouched, and
|
|
216
|
+
* `true` to use the default parser.
|
|
217
|
+
*
|
|
218
|
+
* @param filename One segment of the path, without any slashes.
|
|
219
|
+
* @see https://docusaurus.io/docs/sidebar#using-number-prefixes
|
|
220
|
+
*/
|
|
221
|
+
numberPrefixParser: PluginOptions['numberPrefixParser'] | boolean;
|
|
222
|
+
}
|
|
223
|
+
>
|
|
224
|
+
>;
|
|
208
225
|
export type SidebarsConfig = import('./sidebars/types').SidebarsConfig;
|
|
209
226
|
|
|
210
227
|
export type VersionMetadata = ContentPaths & {
|
package/src/props.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import _ from 'lodash';
|
|
9
|
+
import {createDocsByIdIndex} from './docs';
|
|
8
10
|
import type {VersionTag} from './types';
|
|
9
11
|
import type {
|
|
10
12
|
SidebarItemDoc,
|
|
@@ -24,8 +26,6 @@ import type {
|
|
|
24
26
|
DocMetadata,
|
|
25
27
|
LoadedVersion,
|
|
26
28
|
} from '@docusaurus/plugin-content-docs';
|
|
27
|
-
import _ from 'lodash';
|
|
28
|
-
import {createDocsByIdIndex} from './docs';
|
|
29
29
|
|
|
30
30
|
export function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars {
|
|
31
31
|
const docsById = createDocsByIdIndex(loadedVersion.docs);
|
|
@@ -51,7 +51,7 @@ Available document ids are:
|
|
|
51
51
|
} = docMetadata;
|
|
52
52
|
return {
|
|
53
53
|
type: 'link',
|
|
54
|
-
label: sidebarLabel
|
|
54
|
+
label: sidebarLabel ?? item.label ?? title,
|
|
55
55
|
href: permalink,
|
|
56
56
|
className: item.className,
|
|
57
57
|
customProps:
|
package/src/routes.ts
CHANGED
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import logger from '@docusaurus/logger';
|
|
9
9
|
import {docuHash, createSlugger} from '@docusaurus/utils';
|
|
10
|
+
import {toVersionMetadataProp} from './props';
|
|
11
|
+
import type {PluginContentLoadedActions, RouteConfig} from '@docusaurus/types';
|
|
10
12
|
import type {FullVersion} from './types';
|
|
11
13
|
import type {
|
|
12
14
|
CategoryGeneratedIndexMetadata,
|
|
13
15
|
DocMetadata,
|
|
14
16
|
} from '@docusaurus/plugin-content-docs';
|
|
15
|
-
import {toVersionMetadataProp} from './props';
|
|
16
|
-
import logger from '@docusaurus/logger';
|
|
17
17
|
|
|
18
18
|
export async function createCategoryGeneratedIndexRoutes({
|
|
19
19
|
version,
|
package/src/sidebars/README.md
CHANGED
|
@@ -6,4 +6,5 @@ This part is very complicated and hard to navigate. Sidebars are loaded through
|
|
|
6
6
|
2. **Normalization**. The shorthands are expanded. This step is very lenient about the sidebars' shapes. Returns `NormalizedSidebars`.
|
|
7
7
|
3. **Validation**. The normalized sidebars are validated. This step happens after normalization, because the normalized sidebars are easier to validate, and allows us to repeatedly validate & generate in the future.
|
|
8
8
|
4. **Generation**. This step is done through the "processor" (naming is hard). The `autogenerated` items are unwrapped. In the future, steps 3 and 4 may be repeatedly done until all autogenerated items are unwrapped. Returns `ProcessedSidebars`.
|
|
9
|
+
- **Important**: this step should only care about unwrapping autogenerated items, not filtering them, writing additional metadata, applying defaults, etc.—everything will be handled in the post-processor. Important because the generator is exposed to the end-user and we want it to be easy to be reasoned about.
|
|
9
10
|
5. **Post-processing**. Defaults are applied (collapsed states), category links are resolved, empty categories are flattened. Returns `Sidebars`.
|
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import _ from 'lodash';
|
|
10
|
+
import logger from '@docusaurus/logger';
|
|
11
|
+
import {addTrailingSlash} from '@docusaurus/utils';
|
|
12
|
+
import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
|
|
8
13
|
import type {
|
|
9
14
|
SidebarItemDoc,
|
|
10
15
|
SidebarItemsGenerator,
|
|
@@ -13,11 +18,6 @@ import type {
|
|
|
13
18
|
NormalizedSidebarItem,
|
|
14
19
|
SidebarItemCategoryLinkConfig,
|
|
15
20
|
} from './types';
|
|
16
|
-
import _ from 'lodash';
|
|
17
|
-
import {addTrailingSlash} from '@docusaurus/utils';
|
|
18
|
-
import logger from '@docusaurus/logger';
|
|
19
|
-
import path from 'path';
|
|
20
|
-
import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
|
|
21
21
|
|
|
22
22
|
const BreadcrumbSeparator = '/';
|
|
23
23
|
|
|
@@ -46,7 +46,7 @@ type Dir = {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
// Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
|
|
49
|
-
export const DefaultSidebarItemsGenerator: SidebarItemsGenerator =
|
|
49
|
+
export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = ({
|
|
50
50
|
numberPrefixParser,
|
|
51
51
|
isCategoryIndex,
|
|
52
52
|
docs: allDocs,
|
package/src/sidebars/index.ts
CHANGED
|
@@ -6,19 +6,19 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import fs from 'fs-extra';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import _ from 'lodash';
|
|
11
|
+
import logger from '@docusaurus/logger';
|
|
12
|
+
import {Globby} from '@docusaurus/utils';
|
|
13
|
+
import Yaml from 'js-yaml';
|
|
14
|
+
import combinePromises from 'combine-promises';
|
|
9
15
|
import importFresh from 'import-fresh';
|
|
10
|
-
import type {SidebarsConfig, Sidebars, SidebarProcessorParams} from './types';
|
|
11
16
|
import {validateSidebars, validateCategoryMetadataFile} from './validation';
|
|
12
17
|
import {normalizeSidebars} from './normalization';
|
|
13
18
|
import {processSidebars} from './processor';
|
|
14
19
|
import {postProcessSidebars} from './postProcessor';
|
|
15
|
-
import path from 'path';
|
|
16
|
-
import {Globby} from '@docusaurus/utils';
|
|
17
|
-
import logger from '@docusaurus/logger';
|
|
18
20
|
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
|
|
19
|
-
import
|
|
20
|
-
import _ from 'lodash';
|
|
21
|
-
import combinePromises from 'combine-promises';
|
|
21
|
+
import type {SidebarsConfig, Sidebars, SidebarProcessorParams} from './types';
|
|
22
22
|
|
|
23
23
|
export const DefaultSidebars: SidebarsConfig = {
|
|
24
24
|
defaultSidebar: [
|