@docusaurus/plugin-content-docs 2.4.0 → 3.0.0-alpha.0
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/client/index.d.ts +9 -8
- package/lib/docs.d.ts +6 -2
- package/lib/docs.js +21 -10
- package/lib/frontMatter.js +3 -2
- package/lib/globalData.js +3 -0
- package/lib/index.js +20 -75
- package/lib/options.js +7 -6
- package/lib/props.d.ts +8 -2
- package/lib/props.js +35 -11
- package/lib/routes.d.ts +12 -19
- package/lib/routes.js +107 -35
- package/lib/sidebars/postProcessor.d.ts +1 -1
- package/lib/sidebars/types.d.ts +49 -47
- package/lib/sidebars/utils.d.ts +8 -3
- package/lib/sidebars/utils.js +14 -2
- package/lib/tags.js +12 -5
- package/lib/types.d.ts +8 -7
- package/lib/versions/index.d.ts +4 -2
- package/lib/versions/index.js +15 -1
- package/package.json +14 -14
- package/src/client/index.ts +2 -1
- package/src/docs.ts +32 -29
- package/src/frontMatter.ts +4 -2
- package/src/globalData.ts +5 -0
- package/src/index.ts +22 -105
- package/src/options.ts +10 -6
- package/src/plugin-content-docs.d.ts +45 -6
- package/src/props.ts +59 -16
- package/src/routes.ts +164 -68
- package/src/sidebars/types.ts +7 -0
- package/src/sidebars/utils.ts +34 -11
- package/src/tags.ts +13 -6
- package/src/types.ts +1 -0
- package/src/versions/index.ts +17 -1
package/lib/client/index.d.ts
CHANGED
|
@@ -5,18 +5,18 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { UseDataOptions } from '@docusaurus/types';
|
|
8
|
-
export
|
|
8
|
+
export type ActivePlugin = {
|
|
9
9
|
pluginId: string;
|
|
10
10
|
pluginData: GlobalPluginData;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type ActiveDocContext = {
|
|
13
13
|
activeVersion?: GlobalVersion;
|
|
14
14
|
activeDoc?: GlobalDoc;
|
|
15
15
|
alternateDocVersions: {
|
|
16
16
|
[versionName: string]: GlobalDoc;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type GlobalDoc = {
|
|
20
20
|
/**
|
|
21
21
|
* For generated index pages, this is the `slug`, **not** `permalink`
|
|
22
22
|
* (without base URL). Because slugs have leading slashes but IDs don't,
|
|
@@ -24,9 +24,10 @@ export declare type GlobalDoc = {
|
|
|
24
24
|
*/
|
|
25
25
|
id: string;
|
|
26
26
|
path: string;
|
|
27
|
-
sidebar
|
|
27
|
+
sidebar?: string;
|
|
28
|
+
unlisted?: boolean;
|
|
28
29
|
};
|
|
29
|
-
export
|
|
30
|
+
export type GlobalVersion = {
|
|
30
31
|
name: string;
|
|
31
32
|
label: string;
|
|
32
33
|
isLast: boolean;
|
|
@@ -40,18 +41,18 @@ export declare type GlobalVersion = {
|
|
|
40
41
|
[sidebarId: string]: GlobalSidebar;
|
|
41
42
|
};
|
|
42
43
|
};
|
|
43
|
-
export
|
|
44
|
+
export type GlobalSidebar = {
|
|
44
45
|
link?: {
|
|
45
46
|
label: string;
|
|
46
47
|
path: string;
|
|
47
48
|
};
|
|
48
49
|
};
|
|
49
|
-
export
|
|
50
|
+
export type GlobalPluginData = {
|
|
50
51
|
path: string;
|
|
51
52
|
versions: GlobalVersion[];
|
|
52
53
|
breadcrumbs: boolean;
|
|
53
54
|
};
|
|
54
|
-
export
|
|
55
|
+
export type DocVersionSuggestions = {
|
|
55
56
|
/** Suggest the latest version */
|
|
56
57
|
latestVersionSuggestion: GlobalVersion;
|
|
57
58
|
/** Suggest the same doc, in latest version (if one exists) */
|
package/lib/docs.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { SidebarsUtils } from './sidebars/utils';
|
|
|
10
10
|
import type { DocFile } from './types';
|
|
11
11
|
export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string): Promise<DocFile>;
|
|
12
12
|
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
|
13
|
-
export
|
|
13
|
+
export type DocEnv = 'production' | 'development';
|
|
14
14
|
export declare function processDocMetadata(args: {
|
|
15
15
|
docFile: DocFile;
|
|
16
16
|
versionMetadata: VersionMetadata;
|
|
@@ -18,7 +18,11 @@ export declare function processDocMetadata(args: {
|
|
|
18
18
|
options: MetadataOptions;
|
|
19
19
|
env: DocEnv;
|
|
20
20
|
}): Promise<DocMetadataBase>;
|
|
21
|
-
export declare function addDocNavigation(
|
|
21
|
+
export declare function addDocNavigation({ docs, sidebarsUtils, sidebarFilePath, }: {
|
|
22
|
+
docs: DocMetadataBase[];
|
|
23
|
+
sidebarsUtils: SidebarsUtils;
|
|
24
|
+
sidebarFilePath: string;
|
|
25
|
+
}): LoadedVersion['docs'];
|
|
22
26
|
/**
|
|
23
27
|
* The "main doc" is the "version entry point"
|
|
24
28
|
* We browse this doc by clicking on a version:
|
package/lib/docs.js
CHANGED
|
@@ -64,10 +64,6 @@ async function readVersionDocs(versionMetadata, options) {
|
|
|
64
64
|
return Promise.all(sources.map((source) => readDocFile(versionMetadata, source)));
|
|
65
65
|
}
|
|
66
66
|
exports.readVersionDocs = readVersionDocs;
|
|
67
|
-
/** Docs with draft front matter are only considered draft in production. */
|
|
68
|
-
function isDraftForEnvironment({ env, frontMatter, }) {
|
|
69
|
-
return (env === 'production' && frontMatter.draft) ?? false;
|
|
70
|
-
}
|
|
71
67
|
async function doProcessDocMetadata({ docFile, versionMetadata, context, options, env, }) {
|
|
72
68
|
const { source, content, contentPath, filePath } = docFile;
|
|
73
69
|
const { siteDir, i18n } = context;
|
|
@@ -150,7 +146,8 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
|
|
|
150
146
|
}
|
|
151
147
|
return undefined;
|
|
152
148
|
}
|
|
153
|
-
const draft =
|
|
149
|
+
const draft = (0, utils_1.isDraft)({ env, frontMatter });
|
|
150
|
+
const unlisted = (0, utils_1.isUnlisted)({ env, frontMatter });
|
|
154
151
|
const formatDate = (locale, date, calendar) => {
|
|
155
152
|
try {
|
|
156
153
|
return new Intl.DateTimeFormat(locale, {
|
|
@@ -180,6 +177,7 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
|
|
|
180
177
|
slug: docSlug,
|
|
181
178
|
permalink,
|
|
182
179
|
draft,
|
|
180
|
+
unlisted,
|
|
183
181
|
editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
|
|
184
182
|
tags: (0, utils_1.normalizeFrontMatterTags)(versionMetadata.tagsPath, frontMatter.tags),
|
|
185
183
|
version: versionMetadata.versionName,
|
|
@@ -201,12 +199,21 @@ async function processDocMetadata(args) {
|
|
|
201
199
|
}
|
|
202
200
|
}
|
|
203
201
|
exports.processDocMetadata = processDocMetadata;
|
|
204
|
-
function
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
function getUnlistedIds(docs) {
|
|
203
|
+
return new Set(docs.filter((doc) => doc.unlisted).map((doc) => doc.id));
|
|
204
|
+
}
|
|
205
|
+
function addDocNavigation({ docs, sidebarsUtils, sidebarFilePath, }) {
|
|
206
|
+
const docsById = createDocsByIdIndex(docs);
|
|
207
|
+
const unlistedIds = getUnlistedIds(docs);
|
|
208
|
+
sidebarsUtils.checkSidebarsDocIds(docs.flatMap(getDocIds), sidebarFilePath);
|
|
207
209
|
// Add sidebar/next/previous to the docs
|
|
208
210
|
function addNavData(doc) {
|
|
209
|
-
const navigation = sidebarsUtils.getDocNavigation(
|
|
211
|
+
const navigation = sidebarsUtils.getDocNavigation({
|
|
212
|
+
unversionedId: doc.unversionedId,
|
|
213
|
+
versionedId: doc.id,
|
|
214
|
+
displayedSidebar: doc.frontMatter.displayed_sidebar,
|
|
215
|
+
unlistedIds,
|
|
216
|
+
});
|
|
210
217
|
const toNavigationLinkByDocId = (docId, type) => {
|
|
211
218
|
if (!docId) {
|
|
212
219
|
return undefined;
|
|
@@ -216,6 +223,10 @@ function addDocNavigation(docsBase, sidebarsUtils, sidebarFilePath) {
|
|
|
216
223
|
// This could only happen if user provided the ID through front matter
|
|
217
224
|
throw new Error(`Error when loading ${doc.id} in ${doc.sourceDirName}: the pagination_${type} front matter points to a non-existent ID ${docId}.`);
|
|
218
225
|
}
|
|
226
|
+
// Gracefully handle explicitly providing an unlisted doc ID in production
|
|
227
|
+
if (navDoc.unlisted) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
219
230
|
return (0, utils_2.toDocNavigationLink)(navDoc);
|
|
220
231
|
};
|
|
221
232
|
const previous = doc.frontMatter.pagination_prev !== undefined
|
|
@@ -226,7 +237,7 @@ function addDocNavigation(docsBase, sidebarsUtils, sidebarFilePath) {
|
|
|
226
237
|
: (0, utils_2.toNavigationLink)(navigation.next, docsById);
|
|
227
238
|
return { ...doc, sidebar: navigation.sidebarName, previous, next };
|
|
228
239
|
}
|
|
229
|
-
const docsWithNavigation =
|
|
240
|
+
const docsWithNavigation = docs.map(addNavData);
|
|
230
241
|
// Sort to ensure consistent output for tests
|
|
231
242
|
docsWithNavigation.sort((a, b) => a.id.localeCompare(b.id));
|
|
232
243
|
return docsWithNavigation;
|
package/lib/frontMatter.js
CHANGED
|
@@ -35,7 +35,6 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
35
35
|
parse_number_prefixes: utils_validation_1.JoiFrontMatter.boolean(),
|
|
36
36
|
pagination_next: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
37
37
|
pagination_prev: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
38
|
-
draft: utils_validation_1.JoiFrontMatter.boolean(),
|
|
39
38
|
...utils_validation_1.FrontMatterTOCHeadingLevels,
|
|
40
39
|
last_update: utils_validation_1.JoiFrontMatter.object({
|
|
41
40
|
author: utils_validation_1.JoiFrontMatter.string(),
|
|
@@ -46,7 +45,9 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
46
45
|
'object.missing': FrontMatterLastUpdateErrorMessage,
|
|
47
46
|
'object.base': FrontMatterLastUpdateErrorMessage,
|
|
48
47
|
}),
|
|
49
|
-
})
|
|
48
|
+
})
|
|
49
|
+
.unknown()
|
|
50
|
+
.concat(utils_validation_1.ContentVisibilitySchema);
|
|
50
51
|
function validateDocFrontMatter(frontMatter) {
|
|
51
52
|
return (0, utils_validation_1.validateFrontMatter)(frontMatter, DocFrontMatterSchema);
|
|
52
53
|
}
|
package/lib/globalData.js
CHANGED
|
@@ -14,6 +14,9 @@ function toGlobalDataDoc(doc) {
|
|
|
14
14
|
return {
|
|
15
15
|
id: doc.unversionedId,
|
|
16
16
|
path: doc.permalink,
|
|
17
|
+
// optimize global data size: do not add unlisted: false/undefined
|
|
18
|
+
...(doc.unlisted && { unlisted: doc.unlisted }),
|
|
19
|
+
// TODO optimize size? remove attribute when no sidebar (breaking change?)
|
|
17
20
|
sidebar: doc.sidebar,
|
|
18
21
|
};
|
|
19
22
|
}
|
package/lib/index.js
CHANGED
|
@@ -19,10 +19,7 @@ const versions_1 = require("./versions");
|
|
|
19
19
|
const cli_1 = require("./cli");
|
|
20
20
|
const constants_1 = require("./constants");
|
|
21
21
|
const globalData_1 = require("./globalData");
|
|
22
|
-
const props_1 = require("./props");
|
|
23
|
-
const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
|
|
24
22
|
const translations_1 = require("./translations");
|
|
25
|
-
const tags_1 = require("./tags");
|
|
26
23
|
const routes_1 = require("./routes");
|
|
27
24
|
const utils_2 = require("./sidebars/utils");
|
|
28
25
|
async function pluginContentDocs(context, options) {
|
|
@@ -34,6 +31,8 @@ async function pluginContentDocs(context, options) {
|
|
|
34
31
|
const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
|
|
35
32
|
const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
|
|
36
33
|
const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
|
|
34
|
+
// TODO env should be injected into all plugins
|
|
35
|
+
const env = process.env.NODE_ENV;
|
|
37
36
|
return {
|
|
38
37
|
name: 'docusaurus-plugin-content-docs',
|
|
39
38
|
extendCli(cli) {
|
|
@@ -80,13 +79,16 @@ async function pluginContentDocs(context, options) {
|
|
|
80
79
|
versionMetadata,
|
|
81
80
|
context,
|
|
82
81
|
options,
|
|
83
|
-
env
|
|
82
|
+
env,
|
|
84
83
|
});
|
|
85
84
|
}
|
|
86
85
|
return Promise.all(docFiles.map(processVersionDoc));
|
|
87
86
|
}
|
|
88
87
|
async function doLoadVersion(versionMetadata) {
|
|
89
88
|
const docsBase = await loadVersionDocsBase(versionMetadata);
|
|
89
|
+
// TODO we only ever need draftIds in further code, not full draft items
|
|
90
|
+
// To simplify and prevent mistakes, avoid exposing draft
|
|
91
|
+
// replace draft=>draftIds in content loaded
|
|
90
92
|
const [drafts, docs] = lodash_1.default.partition(docsBase, (doc) => doc.draft);
|
|
91
93
|
const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
|
|
92
94
|
sidebarItemsGenerator: options.sidebarItemsGenerator,
|
|
@@ -103,7 +105,11 @@ async function pluginContentDocs(context, options) {
|
|
|
103
105
|
const sidebarsUtils = (0, utils_2.createSidebarsUtils)(sidebars);
|
|
104
106
|
return {
|
|
105
107
|
...versionMetadata,
|
|
106
|
-
docs: (0, docs_1.addDocNavigation)(
|
|
108
|
+
docs: (0, docs_1.addDocNavigation)({
|
|
109
|
+
docs,
|
|
110
|
+
sidebarsUtils,
|
|
111
|
+
sidebarFilePath: versionMetadata.sidebarFilePath,
|
|
112
|
+
}),
|
|
107
113
|
drafts,
|
|
108
114
|
sidebars,
|
|
109
115
|
};
|
|
@@ -125,81 +131,21 @@ async function pluginContentDocs(context, options) {
|
|
|
125
131
|
return (0, translations_1.translateLoadedContent)(content, translationFiles);
|
|
126
132
|
},
|
|
127
133
|
async contentLoaded({ content, actions }) {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
...version,
|
|
135
|
-
sidebarsUtils,
|
|
136
|
-
categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
|
|
137
|
-
docs: version.docs,
|
|
138
|
-
sidebarsUtils,
|
|
139
|
-
}),
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
async function createVersionTagsRoutes(version) {
|
|
143
|
-
const versionTags = (0, tags_1.getVersionTags)(version.docs);
|
|
144
|
-
// TODO tags should be a sub route of the version route
|
|
145
|
-
async function createTagsListPage() {
|
|
146
|
-
const tagsProp = Object.values(versionTags).map((tagValue) => ({
|
|
147
|
-
label: tagValue.label,
|
|
148
|
-
permalink: tagValue.permalink,
|
|
149
|
-
count: tagValue.docIds.length,
|
|
150
|
-
}));
|
|
151
|
-
// Only create /tags page if there are tags.
|
|
152
|
-
if (tagsProp.length > 0) {
|
|
153
|
-
const tagsPropPath = await createData(`${(0, utils_1.docuHash)(`tags-list-${version.versionName}-prop`)}.json`, JSON.stringify(tagsProp, null, 2));
|
|
154
|
-
addRoute({
|
|
155
|
-
path: version.tagsPath,
|
|
156
|
-
exact: true,
|
|
157
|
-
component: options.docTagsListComponent,
|
|
158
|
-
modules: {
|
|
159
|
-
tags: aliasedSource(tagsPropPath),
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
// TODO tags should be a sub route of the version route
|
|
165
|
-
async function createTagDocListPage(tag) {
|
|
166
|
-
const tagProps = (0, props_1.toTagDocListProp)({
|
|
167
|
-
allTagsPath: version.tagsPath,
|
|
168
|
-
tag,
|
|
169
|
-
docs: version.docs,
|
|
170
|
-
});
|
|
171
|
-
const tagPropPath = await createData(`${(0, utils_1.docuHash)(`tag-${tag.permalink}`)}.json`, JSON.stringify(tagProps, null, 2));
|
|
172
|
-
addRoute({
|
|
173
|
-
path: tag.permalink,
|
|
174
|
-
component: options.docTagDocListComponent,
|
|
175
|
-
exact: true,
|
|
176
|
-
modules: {
|
|
177
|
-
tag: aliasedSource(tagPropPath),
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
await createTagsListPage();
|
|
182
|
-
await Promise.all(Object.values(versionTags).map(createTagDocListPage));
|
|
183
|
-
}
|
|
184
|
-
await Promise.all(versions.map((version) => (0, routes_1.createVersionRoutes)({
|
|
185
|
-
version,
|
|
186
|
-
docItemComponent,
|
|
187
|
-
docLayoutComponent,
|
|
188
|
-
docCategoryGeneratedIndexComponent,
|
|
189
|
-
pluginId,
|
|
190
|
-
aliasedSource,
|
|
134
|
+
const versions = content.loadedVersions.map(versions_1.toFullVersion);
|
|
135
|
+
await (0, routes_1.createAllRoutes)({
|
|
136
|
+
baseUrl,
|
|
137
|
+
versions,
|
|
138
|
+
options,
|
|
191
139
|
actions,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
setGlobalData({
|
|
140
|
+
aliasedSource,
|
|
141
|
+
});
|
|
142
|
+
actions.setGlobalData({
|
|
196
143
|
path: (0, utils_1.normalizeUrl)([baseUrl, options.routeBasePath]),
|
|
197
144
|
versions: versions.map(globalData_1.toGlobalDataVersion),
|
|
198
|
-
breadcrumbs,
|
|
145
|
+
breadcrumbs: options.breadcrumbs,
|
|
199
146
|
});
|
|
200
147
|
},
|
|
201
148
|
configureWebpack(_config, isServer, utils, content) {
|
|
202
|
-
const { getJSLoader } = utils;
|
|
203
149
|
const { rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
|
|
204
150
|
function getSourceToPermalink() {
|
|
205
151
|
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
@@ -222,7 +168,6 @@ async function pluginContentDocs(context, options) {
|
|
|
222
168
|
test: /\.mdx?$/i,
|
|
223
169
|
include: contentDirs,
|
|
224
170
|
use: [
|
|
225
|
-
getJSLoader({ isServer }),
|
|
226
171
|
{
|
|
227
172
|
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
228
173
|
options: {
|
package/lib/options.js
CHANGED
|
@@ -21,7 +21,9 @@ exports.DEFAULT_OPTIONS = {
|
|
|
21
21
|
exclude: utils_1.GlobExcludeDefault,
|
|
22
22
|
sidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
|
|
23
23
|
numberPrefixParser: numberPrefix_1.DefaultNumberPrefixParser,
|
|
24
|
-
|
|
24
|
+
docsRootComponent: '@theme/DocsRoot',
|
|
25
|
+
docVersionRootComponent: '@theme/DocVersionRoot',
|
|
26
|
+
docRootComponent: '@theme/DocRoot',
|
|
25
27
|
docItemComponent: '@theme/DocItem',
|
|
26
28
|
docTagDocListComponent: '@theme/DocTagDocListPage',
|
|
27
29
|
docTagsListComponent: '@theme/DocTagsListPage',
|
|
@@ -59,10 +61,7 @@ const OptionsSchema = utils_validation_1.Joi.object({
|
|
|
59
61
|
editUrl: utils_validation_1.Joi.alternatives().try(utils_validation_1.URISchema, utils_validation_1.Joi.function()),
|
|
60
62
|
editCurrentVersion: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.editCurrentVersion),
|
|
61
63
|
editLocalizedFiles: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.editLocalizedFiles),
|
|
62
|
-
routeBasePath: utils_validation_1.
|
|
63
|
-
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
|
|
64
|
-
// .allow('') ""
|
|
65
|
-
.default(exports.DEFAULT_OPTIONS.routeBasePath),
|
|
64
|
+
routeBasePath: utils_validation_1.RouteBasePathSchema.default(exports.DEFAULT_OPTIONS.routeBasePath),
|
|
66
65
|
tagsBasePath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.tagsBasePath),
|
|
67
66
|
// @ts-expect-error: deprecated
|
|
68
67
|
homePageId: utils_validation_1.Joi.any().forbidden().messages({
|
|
@@ -81,7 +80,9 @@ const OptionsSchema = utils_validation_1.Joi.object({
|
|
|
81
80
|
then: utils_validation_1.Joi.custom((val) => val ? numberPrefix_1.DefaultNumberPrefixParser : numberPrefix_1.DisabledNumberPrefixParser),
|
|
82
81
|
}))
|
|
83
82
|
.default(() => exports.DEFAULT_OPTIONS.numberPrefixParser),
|
|
84
|
-
|
|
83
|
+
docsRootComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docsRootComponent),
|
|
84
|
+
docVersionRootComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docVersionRootComponent),
|
|
85
|
+
docRootComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docRootComponent),
|
|
85
86
|
docItemComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docItemComponent),
|
|
86
87
|
docTagsListComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docTagsListComponent),
|
|
87
88
|
docTagDocListComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docTagDocListComponent),
|
package/lib/props.d.ts
CHANGED
|
@@ -4,8 +4,13 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type { VersionTag } from './types';
|
|
8
|
-
import type {
|
|
7
|
+
import type { VersionTag, VersionTags } from './types';
|
|
8
|
+
import type { SidebarItemDoc } from './sidebars/types';
|
|
9
|
+
import type { PropSidebars, PropVersionMetadata, PropTagDocList, PropTagsListPage, PropSidebarItemLink, DocMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
|
|
10
|
+
export declare function toSidebarDocItemLinkProp({ item, doc, }: {
|
|
11
|
+
item: SidebarItemDoc;
|
|
12
|
+
doc: Pick<DocMetadata, 'id' | 'title' | 'permalink' | 'unlisted' | 'frontMatter' | 'unversionedId'>;
|
|
13
|
+
}): PropSidebarItemLink;
|
|
9
14
|
export declare function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars;
|
|
10
15
|
export declare function toVersionMetadataProp(pluginId: string, loadedVersion: LoadedVersion): PropVersionMetadata;
|
|
11
16
|
export declare function toTagDocListProp({ allTagsPath, tag, docs, }: {
|
|
@@ -13,3 +18,4 @@ export declare function toTagDocListProp({ allTagsPath, tag, docs, }: {
|
|
|
13
18
|
tag: VersionTag;
|
|
14
19
|
docs: DocMetadata[];
|
|
15
20
|
}): PropTagDocList;
|
|
21
|
+
export declare function toTagsListTagsProp(versionTags: VersionTags): PropTagsListPage['tags'];
|
package/lib/props.js
CHANGED
|
@@ -6,10 +6,23 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.toTagDocListProp = exports.toVersionMetadataProp = exports.toSidebarsProp = void 0;
|
|
9
|
+
exports.toTagsListTagsProp = exports.toTagDocListProp = exports.toVersionMetadataProp = exports.toSidebarsProp = exports.toSidebarDocItemLinkProp = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const docs_1 = require("./docs");
|
|
13
|
+
function toSidebarDocItemLinkProp({ item, doc, }) {
|
|
14
|
+
const { title, permalink, frontMatter: { sidebar_label: sidebarLabel, sidebar_custom_props: customProps, }, unlisted, unversionedId, } = doc;
|
|
15
|
+
return {
|
|
16
|
+
type: 'link',
|
|
17
|
+
label: sidebarLabel ?? item.label ?? title,
|
|
18
|
+
href: permalink,
|
|
19
|
+
className: item.className,
|
|
20
|
+
customProps: item.customProps ?? customProps,
|
|
21
|
+
docId: unversionedId,
|
|
22
|
+
unlisted,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.toSidebarDocItemLinkProp = toSidebarDocItemLinkProp;
|
|
13
26
|
function toSidebarsProp(loadedVersion) {
|
|
14
27
|
const docsById = (0, docs_1.createDocsByIdIndex)(loadedVersion.docs);
|
|
15
28
|
function getDocById(docId) {
|
|
@@ -22,16 +35,8 @@ Available document ids are:
|
|
|
22
35
|
return docMetadata;
|
|
23
36
|
}
|
|
24
37
|
const convertDocLink = (item) => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
type: 'link',
|
|
29
|
-
label: sidebarLabel ?? item.label ?? title,
|
|
30
|
-
href: permalink,
|
|
31
|
-
className: item.className,
|
|
32
|
-
customProps: item.customProps ?? docMetadata.frontMatter.sidebar_custom_props,
|
|
33
|
-
docId: docMetadata.unversionedId,
|
|
34
|
-
};
|
|
38
|
+
const doc = getDocById(item.id);
|
|
39
|
+
return toSidebarDocItemLinkProp({ item, doc });
|
|
35
40
|
};
|
|
36
41
|
function getCategoryLinkHref(link) {
|
|
37
42
|
switch (link?.type) {
|
|
@@ -43,6 +48,12 @@ Available document ids are:
|
|
|
43
48
|
return undefined;
|
|
44
49
|
}
|
|
45
50
|
}
|
|
51
|
+
function getCategoryLinkUnlisted(link) {
|
|
52
|
+
if (link?.type === 'doc') {
|
|
53
|
+
return getDocById(link.id).unlisted;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
46
57
|
function getCategoryLinkCustomProps(link) {
|
|
47
58
|
switch (link?.type) {
|
|
48
59
|
case 'doc':
|
|
@@ -54,11 +65,13 @@ Available document ids are:
|
|
|
54
65
|
function convertCategory(item) {
|
|
55
66
|
const { link, ...rest } = item;
|
|
56
67
|
const href = getCategoryLinkHref(link);
|
|
68
|
+
const linkUnlisted = getCategoryLinkUnlisted(link);
|
|
57
69
|
const customProps = item.customProps ?? getCategoryLinkCustomProps(link);
|
|
58
70
|
return {
|
|
59
71
|
...rest,
|
|
60
72
|
items: item.items.map(normalizeItem),
|
|
61
73
|
...(href && { href }),
|
|
74
|
+
...(linkUnlisted && { linkUnlisted }),
|
|
62
75
|
...(customProps && { customProps }),
|
|
63
76
|
};
|
|
64
77
|
}
|
|
@@ -124,6 +137,17 @@ function toTagDocListProp({ allTagsPath, tag, docs, }) {
|
|
|
124
137
|
allTagsPath,
|
|
125
138
|
count: tag.docIds.length,
|
|
126
139
|
items: toDocListProp(),
|
|
140
|
+
unlisted: tag.unlisted,
|
|
127
141
|
};
|
|
128
142
|
}
|
|
129
143
|
exports.toTagDocListProp = toTagDocListProp;
|
|
144
|
+
function toTagsListTagsProp(versionTags) {
|
|
145
|
+
return Object.values(versionTags)
|
|
146
|
+
.filter((tagValue) => !tagValue.unlisted)
|
|
147
|
+
.map((tagValue) => ({
|
|
148
|
+
label: tagValue.label,
|
|
149
|
+
permalink: tagValue.permalink,
|
|
150
|
+
count: tagValue.docIds.length,
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
exports.toTagsListTagsProp = toTagsListTagsProp;
|
package/lib/routes.d.ts
CHANGED
|
@@ -6,24 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { PluginContentLoadedActions, RouteConfig } from '@docusaurus/types';
|
|
8
8
|
import type { FullVersion } from './types';
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
10
|
+
type BuildAllRoutesParam = Omit<CreateAllRoutesParam, 'actions'> & {
|
|
11
|
+
actions: Omit<PluginContentLoadedActions, 'addRoute' | 'setGlobalData'>;
|
|
12
|
+
};
|
|
13
|
+
export declare function buildAllRoutes(param: BuildAllRoutesParam): Promise<RouteConfig[]>;
|
|
14
|
+
type CreateAllRoutesParam = {
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
versions: FullVersion[];
|
|
17
|
+
options: PluginOptions;
|
|
12
18
|
actions: PluginContentLoadedActions;
|
|
13
|
-
docCategoryGeneratedIndexComponent: string;
|
|
14
19
|
aliasedSource: (str: string) => string;
|
|
15
|
-
}
|
|
16
|
-
export declare function
|
|
17
|
-
|
|
18
|
-
actions: PluginContentLoadedActions;
|
|
19
|
-
docItemComponent: string;
|
|
20
|
-
}): Promise<RouteConfig[]>;
|
|
21
|
-
export declare function createVersionRoutes({ version, actions, docItemComponent, docLayoutComponent, docCategoryGeneratedIndexComponent, pluginId, aliasedSource, }: {
|
|
22
|
-
version: FullVersion;
|
|
23
|
-
actions: PluginContentLoadedActions;
|
|
24
|
-
docLayoutComponent: string;
|
|
25
|
-
docItemComponent: string;
|
|
26
|
-
docCategoryGeneratedIndexComponent: string;
|
|
27
|
-
pluginId: string;
|
|
28
|
-
aliasedSource: (str: string) => string;
|
|
29
|
-
}): Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
export declare function createAllRoutes(param: CreateAllRoutesParam): Promise<void>;
|
|
22
|
+
export {};
|