@docusaurus/plugin-content-docs 0.0.0-4859 → 0.0.0-4864
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/docs.d.ts +2 -0
- package/lib/docs.js +7 -1
- package/lib/frontMatter.js +1 -0
- package/lib/globalData.js +1 -0
- package/lib/index.js +6 -1
- package/lib/sidebars/processor.js +14 -3
- package/lib/sidebars/types.d.ts +1 -0
- package/lib/types.d.ts +1 -0
- package/package.json +9 -9
- package/src/docs.ts +20 -0
- package/src/frontMatter.ts +1 -0
- package/src/globalData.ts +1 -0
- package/src/index.ts +8 -1
- package/src/plugin-content-docs.d.ts +8 -0
- package/src/sidebars/processor.ts +20 -4
- package/src/sidebars/types.ts +1 -0
- package/src/types.ts +1 -0
package/lib/docs.d.ts
CHANGED
|
@@ -11,11 +11,13 @@ import type { MetadataOptions, PluginOptions, CategoryIndexMatcher, DocMetadataB
|
|
|
11
11
|
declare type LastUpdateOptions = Pick<PluginOptions, 'showLastUpdateAuthor' | 'showLastUpdateTime'>;
|
|
12
12
|
export declare function readDocFile(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>, source: string, options: LastUpdateOptions): Promise<DocFile>;
|
|
13
13
|
export declare function readVersionDocs(versionMetadata: VersionMetadata, options: Pick<PluginOptions, 'include' | 'exclude' | 'showLastUpdateAuthor' | 'showLastUpdateTime'>): Promise<DocFile[]>;
|
|
14
|
+
export declare type DocEnv = 'production' | 'development';
|
|
14
15
|
export declare function processDocMetadata(args: {
|
|
15
16
|
docFile: DocFile;
|
|
16
17
|
versionMetadata: VersionMetadata;
|
|
17
18
|
context: LoadContext;
|
|
18
19
|
options: MetadataOptions;
|
|
20
|
+
env: DocEnv;
|
|
19
21
|
}): DocMetadataBase;
|
|
20
22
|
export declare function addDocNavigation(docsBase: DocMetadataBase[], sidebarsUtils: SidebarsUtils, sidebarFilePath: string): LoadedVersion['docs'];
|
|
21
23
|
/**
|
package/lib/docs.js
CHANGED
|
@@ -56,7 +56,11 @@ async function readVersionDocs(versionMetadata, options) {
|
|
|
56
56
|
return Promise.all(sources.map((source) => readDocFile(versionMetadata, source, options)));
|
|
57
57
|
}
|
|
58
58
|
exports.readVersionDocs = readVersionDocs;
|
|
59
|
-
|
|
59
|
+
/** Docs with draft front matter are only considered draft in production. */
|
|
60
|
+
function isDraftForEnvironment({ env, frontMatter, }) {
|
|
61
|
+
return (env === 'production' && frontMatter.draft) ?? false;
|
|
62
|
+
}
|
|
63
|
+
function doProcessDocMetadata({ docFile, versionMetadata, context, options, env, }) {
|
|
60
64
|
const { source, content, lastUpdate, contentPath, filePath } = docFile;
|
|
61
65
|
const { siteDir, i18n } = context;
|
|
62
66
|
const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = (0, utils_1.parseMarkdownString)(content);
|
|
@@ -139,6 +143,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
139
143
|
}
|
|
140
144
|
return undefined;
|
|
141
145
|
}
|
|
146
|
+
const draft = isDraftForEnvironment({ env, frontMatter });
|
|
142
147
|
// Assign all of object properties during instantiation (if possible) for
|
|
143
148
|
// NodeJS optimization.
|
|
144
149
|
// Adding properties to object after instantiation will cause hidden
|
|
@@ -152,6 +157,7 @@ function doProcessDocMetadata({ docFile, versionMetadata, context, options, }) {
|
|
|
152
157
|
sourceDirName,
|
|
153
158
|
slug: docSlug,
|
|
154
159
|
permalink,
|
|
160
|
+
draft,
|
|
155
161
|
editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
|
|
156
162
|
tags: (0, utils_1.normalizeFrontMatterTags)(versionMetadata.tagsPath, frontMatter.tags),
|
|
157
163
|
version: versionMetadata.versionName,
|
package/lib/frontMatter.js
CHANGED
|
@@ -32,6 +32,7 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
32
32
|
parse_number_prefixes: utils_validation_1.JoiFrontMatter.boolean(),
|
|
33
33
|
pagination_next: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
34
34
|
pagination_prev: utils_validation_1.JoiFrontMatter.string().allow(null),
|
|
35
|
+
draft: utils_validation_1.JoiFrontMatter.boolean(),
|
|
35
36
|
...utils_validation_1.FrontMatterTOCHeadingLevels,
|
|
36
37
|
}).unknown();
|
|
37
38
|
function validateDocFrontMatter(frontMatter) {
|
package/lib/globalData.js
CHANGED
|
@@ -51,6 +51,7 @@ function toGlobalDataVersion(version) {
|
|
|
51
51
|
docs: version.docs
|
|
52
52
|
.map(toGlobalDataDoc)
|
|
53
53
|
.concat(version.categoryGeneratedIndices.map(toGlobalDataGeneratedIndex)),
|
|
54
|
+
draftIds: version.drafts.map((doc) => doc.unversionedId),
|
|
54
55
|
sidebars: toGlobalSidebars(version.sidebars, version),
|
|
55
56
|
};
|
|
56
57
|
}
|
package/lib/index.js
CHANGED
|
@@ -24,6 +24,7 @@ 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
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
27
28
|
async function pluginContentDocs(context, options) {
|
|
28
29
|
const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
|
|
29
30
|
// Mutate options to resolve sidebar path according to siteDir
|
|
@@ -81,16 +82,19 @@ async function pluginContentDocs(context, options) {
|
|
|
81
82
|
versionMetadata,
|
|
82
83
|
context,
|
|
83
84
|
options,
|
|
85
|
+
env: process.env.NODE_ENV,
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
88
|
return Promise.all(docFiles.map(processVersionDoc));
|
|
87
89
|
}
|
|
88
90
|
async function doLoadVersion(versionMetadata) {
|
|
89
|
-
const
|
|
91
|
+
const docsBase = await loadVersionDocsBase(versionMetadata);
|
|
92
|
+
const [drafts, docs] = lodash_1.default.partition(docsBase, (doc) => doc.draft);
|
|
90
93
|
const sidebars = await (0, sidebars_1.loadSidebars)(versionMetadata.sidebarFilePath, {
|
|
91
94
|
sidebarItemsGenerator: options.sidebarItemsGenerator,
|
|
92
95
|
numberPrefixParser: options.numberPrefixParser,
|
|
93
96
|
docs,
|
|
97
|
+
drafts,
|
|
94
98
|
version: versionMetadata,
|
|
95
99
|
sidebarOptions: {
|
|
96
100
|
sidebarCollapsed: options.sidebarCollapsed,
|
|
@@ -102,6 +106,7 @@ async function pluginContentDocs(context, options) {
|
|
|
102
106
|
return {
|
|
103
107
|
...versionMetadata,
|
|
104
108
|
docs: (0, docs_1.addDocNavigation)(docs, sidebarsUtils, versionMetadata.sidebarFilePath),
|
|
109
|
+
drafts,
|
|
105
110
|
sidebars,
|
|
106
111
|
mainDocId: (0, docs_1.getMainDocId)({ docs, sidebarsUtils }),
|
|
107
112
|
categoryGeneratedIndices: (0, categoryGeneratedIndex_1.getCategoryGeneratedIndexMetadataList)({
|
|
@@ -30,7 +30,7 @@ function toSidebarItemsGeneratorVersion(version) {
|
|
|
30
30
|
// Handle the generation of autogenerated sidebar items and other
|
|
31
31
|
// post-processing checks
|
|
32
32
|
async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
33
|
-
const { sidebarItemsGenerator, numberPrefixParser, docs, version } = params;
|
|
33
|
+
const { sidebarItemsGenerator, numberPrefixParser, docs, drafts, version } = params;
|
|
34
34
|
// Just a minor lazy transformation optimization
|
|
35
35
|
const getSidebarItemsGeneratorDocsAndVersion = lodash_1.default.memoize(() => ({
|
|
36
36
|
docs: docs.map(toSidebarItemsGeneratorDoc),
|
|
@@ -51,12 +51,23 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
|
51
51
|
// more autogenerated items, or when loop count (e.g. 10) is reached
|
|
52
52
|
return processItems(generatedItems);
|
|
53
53
|
}
|
|
54
|
+
const draftIds = new Set(drafts.flatMap(docs_1.getDocIds));
|
|
55
|
+
const isDraftItem = (item) => {
|
|
56
|
+
if (item.type === 'doc' || item.type === 'ref') {
|
|
57
|
+
return draftIds.has(item.id);
|
|
58
|
+
}
|
|
59
|
+
// If a category only contains draft items, it should be filtered entirely.
|
|
60
|
+
if (item.type === 'category') {
|
|
61
|
+
return item.items.every(isDraftItem);
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
};
|
|
54
65
|
async function processItem(item) {
|
|
55
66
|
if (item.type === 'category') {
|
|
56
67
|
return [
|
|
57
68
|
{
|
|
58
69
|
...item,
|
|
59
|
-
items:
|
|
70
|
+
items: await processItems(item.items),
|
|
60
71
|
},
|
|
61
72
|
];
|
|
62
73
|
}
|
|
@@ -66,7 +77,7 @@ async function processSidebar(unprocessedSidebar, categoriesMetadata, params) {
|
|
|
66
77
|
return [item];
|
|
67
78
|
}
|
|
68
79
|
async function processItems(items) {
|
|
69
|
-
return (await Promise.all(items.map(processItem))).flat();
|
|
80
|
+
return (await Promise.all(items.filter((i) => !isDraftItem(i)).map(processItem))).flat();
|
|
70
81
|
}
|
|
71
82
|
const processedSidebar = await processItems(unprocessedSidebar);
|
|
72
83
|
return processedSidebar;
|
package/lib/sidebars/types.d.ts
CHANGED
|
@@ -170,6 +170,7 @@ export declare type SidebarProcessorParams = {
|
|
|
170
170
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
171
171
|
numberPrefixParser: NumberPrefixParser;
|
|
172
172
|
docs: DocMetadataBase[];
|
|
173
|
+
drafts: DocMetadataBase[];
|
|
173
174
|
version: VersionMetadata;
|
|
174
175
|
categoryLabelSlugger: Slugger;
|
|
175
176
|
sidebarOptions: SidebarOptions;
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4864",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@docusaurus/core": "0.0.0-
|
|
28
|
-
"@docusaurus/logger": "0.0.0-
|
|
29
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
30
|
-
"@docusaurus/utils": "0.0.0-
|
|
31
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
27
|
+
"@docusaurus/core": "0.0.0-4864",
|
|
28
|
+
"@docusaurus/logger": "0.0.0-4864",
|
|
29
|
+
"@docusaurus/mdx-loader": "0.0.0-4864",
|
|
30
|
+
"@docusaurus/utils": "0.0.0-4864",
|
|
31
|
+
"@docusaurus/utils-validation": "0.0.0-4864",
|
|
32
32
|
"combine-promises": "^1.1.0",
|
|
33
33
|
"fs-extra": "^10.0.1",
|
|
34
34
|
"import-fresh": "^3.3.0",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"webpack": "^5.72.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
44
|
-
"@docusaurus/types": "0.0.0-
|
|
43
|
+
"@docusaurus/module-type-aliases": "0.0.0-4864",
|
|
44
|
+
"@docusaurus/types": "0.0.0-4864",
|
|
45
45
|
"@types/js-yaml": "^4.0.5",
|
|
46
46
|
"@types/picomatch": "^2.3.0",
|
|
47
47
|
"commander": "^5.1.0",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=14"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "ae6d7c8caecd661cd85ab05c9d7e9ecd935725a1"
|
|
61
61
|
}
|
package/src/docs.ts
CHANGED
|
@@ -38,6 +38,7 @@ import type {
|
|
|
38
38
|
PropNavigationLink,
|
|
39
39
|
LastUpdateData,
|
|
40
40
|
VersionMetadata,
|
|
41
|
+
DocFrontMatter,
|
|
41
42
|
} from '@docusaurus/plugin-content-docs';
|
|
42
43
|
|
|
43
44
|
type LastUpdateOptions = Pick<
|
|
@@ -110,16 +111,31 @@ export async function readVersionDocs(
|
|
|
110
111
|
);
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
export type DocEnv = 'production' | 'development';
|
|
115
|
+
|
|
116
|
+
/** Docs with draft front matter are only considered draft in production. */
|
|
117
|
+
function isDraftForEnvironment({
|
|
118
|
+
env,
|
|
119
|
+
frontMatter,
|
|
120
|
+
}: {
|
|
121
|
+
frontMatter: DocFrontMatter;
|
|
122
|
+
env: DocEnv;
|
|
123
|
+
}): boolean {
|
|
124
|
+
return (env === 'production' && frontMatter.draft) ?? false;
|
|
125
|
+
}
|
|
126
|
+
|
|
113
127
|
function doProcessDocMetadata({
|
|
114
128
|
docFile,
|
|
115
129
|
versionMetadata,
|
|
116
130
|
context,
|
|
117
131
|
options,
|
|
132
|
+
env,
|
|
118
133
|
}: {
|
|
119
134
|
docFile: DocFile;
|
|
120
135
|
versionMetadata: VersionMetadata;
|
|
121
136
|
context: LoadContext;
|
|
122
137
|
options: MetadataOptions;
|
|
138
|
+
env: DocEnv;
|
|
123
139
|
}): DocMetadataBase {
|
|
124
140
|
const {source, content, lastUpdate, contentPath, filePath} = docFile;
|
|
125
141
|
const {siteDir, i18n} = context;
|
|
@@ -235,6 +251,8 @@ function doProcessDocMetadata({
|
|
|
235
251
|
return undefined;
|
|
236
252
|
}
|
|
237
253
|
|
|
254
|
+
const draft = isDraftForEnvironment({env, frontMatter});
|
|
255
|
+
|
|
238
256
|
// Assign all of object properties during instantiation (if possible) for
|
|
239
257
|
// NodeJS optimization.
|
|
240
258
|
// Adding properties to object after instantiation will cause hidden
|
|
@@ -248,6 +266,7 @@ function doProcessDocMetadata({
|
|
|
248
266
|
sourceDirName,
|
|
249
267
|
slug: docSlug,
|
|
250
268
|
permalink,
|
|
269
|
+
draft,
|
|
251
270
|
editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
|
|
252
271
|
tags: normalizeFrontMatterTags(versionMetadata.tagsPath, frontMatter.tags),
|
|
253
272
|
version: versionMetadata.versionName,
|
|
@@ -268,6 +287,7 @@ export function processDocMetadata(args: {
|
|
|
268
287
|
versionMetadata: VersionMetadata;
|
|
269
288
|
context: LoadContext;
|
|
270
289
|
options: MetadataOptions;
|
|
290
|
+
env: DocEnv;
|
|
271
291
|
}): DocMetadataBase {
|
|
272
292
|
try {
|
|
273
293
|
return doProcessDocMetadata(args);
|
package/src/frontMatter.ts
CHANGED
|
@@ -38,6 +38,7 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
|
|
|
38
38
|
parse_number_prefixes: Joi.boolean(),
|
|
39
39
|
pagination_next: Joi.string().allow(null),
|
|
40
40
|
pagination_prev: Joi.string().allow(null),
|
|
41
|
+
draft: Joi.boolean(),
|
|
41
42
|
...FrontMatterTOCHeadingLevels,
|
|
42
43
|
}).unknown();
|
|
43
44
|
|
package/src/globalData.ts
CHANGED
|
@@ -72,6 +72,7 @@ export function toGlobalDataVersion(version: LoadedVersion): GlobalVersion {
|
|
|
72
72
|
docs: version.docs
|
|
73
73
|
.map(toGlobalDataDoc)
|
|
74
74
|
.concat(version.categoryGeneratedIndices.map(toGlobalDataGeneratedIndex)),
|
|
75
|
+
draftIds: version.drafts.map((doc) => doc.unversionedId),
|
|
75
76
|
sidebars: toGlobalSidebars(version.sidebars, version),
|
|
76
77
|
};
|
|
77
78
|
}
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
23
23
|
import {loadSidebars, resolveSidebarPathOption} from './sidebars';
|
|
24
24
|
import {CategoryMetadataFilenamePattern} from './sidebars/generator';
|
|
25
|
+
import type {DocEnv} from './docs';
|
|
25
26
|
import {
|
|
26
27
|
readVersionDocs,
|
|
27
28
|
processDocMetadata,
|
|
@@ -58,6 +59,7 @@ import type {
|
|
|
58
59
|
} from '@docusaurus/plugin-content-docs';
|
|
59
60
|
import {createSidebarsUtils} from './sidebars/utils';
|
|
60
61
|
import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
|
|
62
|
+
import _ from 'lodash';
|
|
61
63
|
|
|
62
64
|
export default async function pluginContentDocs(
|
|
63
65
|
context: LoadContext,
|
|
@@ -147,6 +149,7 @@ export default async function pluginContentDocs(
|
|
|
147
149
|
versionMetadata,
|
|
148
150
|
context,
|
|
149
151
|
options,
|
|
152
|
+
env: process.env.NODE_ENV as DocEnv,
|
|
150
153
|
});
|
|
151
154
|
}
|
|
152
155
|
return Promise.all(docFiles.map(processVersionDoc));
|
|
@@ -155,14 +158,17 @@ export default async function pluginContentDocs(
|
|
|
155
158
|
async function doLoadVersion(
|
|
156
159
|
versionMetadata: VersionMetadata,
|
|
157
160
|
): Promise<LoadedVersion> {
|
|
158
|
-
const
|
|
161
|
+
const docsBase: DocMetadataBase[] = await loadVersionDocsBase(
|
|
159
162
|
versionMetadata,
|
|
160
163
|
);
|
|
161
164
|
|
|
165
|
+
const [drafts, docs] = _.partition(docsBase, (doc) => doc.draft);
|
|
166
|
+
|
|
162
167
|
const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, {
|
|
163
168
|
sidebarItemsGenerator: options.sidebarItemsGenerator,
|
|
164
169
|
numberPrefixParser: options.numberPrefixParser,
|
|
165
170
|
docs,
|
|
171
|
+
drafts,
|
|
166
172
|
version: versionMetadata,
|
|
167
173
|
sidebarOptions: {
|
|
168
174
|
sidebarCollapsed: options.sidebarCollapsed,
|
|
@@ -180,6 +186,7 @@ export default async function pluginContentDocs(
|
|
|
180
186
|
sidebarsUtils,
|
|
181
187
|
versionMetadata.sidebarFilePath as string,
|
|
182
188
|
),
|
|
189
|
+
drafts,
|
|
183
190
|
sidebars,
|
|
184
191
|
mainDocId: getMainDocId({docs, sidebarsUtils}),
|
|
185
192
|
categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
|
|
@@ -346,6 +346,8 @@ declare module '@docusaurus/plugin-content-docs' {
|
|
|
346
346
|
* @see {@link DocMetadata.prev}
|
|
347
347
|
*/
|
|
348
348
|
pagination_prev?: string | null;
|
|
349
|
+
/** Should this doc be excluded from production builds? */
|
|
350
|
+
draft?: boolean;
|
|
349
351
|
};
|
|
350
352
|
|
|
351
353
|
export type LastUpdateData = {
|
|
@@ -390,6 +392,10 @@ declare module '@docusaurus/plugin-content-docs' {
|
|
|
390
392
|
slug: string;
|
|
391
393
|
/** Full URL to this doc, with base URL and version path. */
|
|
392
394
|
permalink: string;
|
|
395
|
+
/**
|
|
396
|
+
* Draft docs will be excluded for production environment.
|
|
397
|
+
*/
|
|
398
|
+
draft: boolean;
|
|
393
399
|
/**
|
|
394
400
|
* Position in an autogenerated sidebar slice, acquired through front matter
|
|
395
401
|
* or number prefix.
|
|
@@ -597,6 +603,8 @@ declare module '@docusaurus/plugin-content-docs/client' {
|
|
|
597
603
|
/** The doc with `slug: /`, or first doc in first sidebar */
|
|
598
604
|
mainDocId: string;
|
|
599
605
|
docs: GlobalDoc[];
|
|
606
|
+
/** Unversioned IDs. In development, this list is empty. */
|
|
607
|
+
draftIds: string[];
|
|
600
608
|
sidebars?: {[sidebarId: string]: GlobalSidebar};
|
|
601
609
|
};
|
|
602
610
|
|
|
@@ -26,7 +26,7 @@ import {DefaultSidebarItemsGenerator} from './generator';
|
|
|
26
26
|
import {validateSidebars} from './validation';
|
|
27
27
|
import _ from 'lodash';
|
|
28
28
|
import combinePromises from 'combine-promises';
|
|
29
|
-
import {isCategoryIndex} from '../docs';
|
|
29
|
+
import {getDocIds, isCategoryIndex} from '../docs';
|
|
30
30
|
|
|
31
31
|
function toSidebarItemsGeneratorDoc(
|
|
32
32
|
doc: DocMetadataBase,
|
|
@@ -55,7 +55,8 @@ async function processSidebar(
|
|
|
55
55
|
categoriesMetadata: {[filePath: string]: CategoryMetadataFile},
|
|
56
56
|
params: SidebarProcessorParams,
|
|
57
57
|
): Promise<ProcessedSidebar> {
|
|
58
|
-
const {sidebarItemsGenerator, numberPrefixParser, docs, version} =
|
|
58
|
+
const {sidebarItemsGenerator, numberPrefixParser, docs, drafts, version} =
|
|
59
|
+
params;
|
|
59
60
|
|
|
60
61
|
// Just a minor lazy transformation optimization
|
|
61
62
|
const getSidebarItemsGeneratorDocsAndVersion = _.memoize(() => ({
|
|
@@ -81,6 +82,19 @@ async function processSidebar(
|
|
|
81
82
|
return processItems(generatedItems);
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
const draftIds = new Set(drafts.flatMap(getDocIds));
|
|
86
|
+
|
|
87
|
+
const isDraftItem = (item: NormalizedSidebarItem): boolean => {
|
|
88
|
+
if (item.type === 'doc' || item.type === 'ref') {
|
|
89
|
+
return draftIds.has(item.id);
|
|
90
|
+
}
|
|
91
|
+
// If a category only contains draft items, it should be filtered entirely.
|
|
92
|
+
if (item.type === 'category') {
|
|
93
|
+
return item.items.every(isDraftItem);
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
};
|
|
97
|
+
|
|
84
98
|
async function processItem(
|
|
85
99
|
item: NormalizedSidebarItem,
|
|
86
100
|
): Promise<ProcessedSidebarItem[]> {
|
|
@@ -88,7 +102,7 @@ async function processSidebar(
|
|
|
88
102
|
return [
|
|
89
103
|
{
|
|
90
104
|
...item,
|
|
91
|
-
items:
|
|
105
|
+
items: await processItems(item.items),
|
|
92
106
|
},
|
|
93
107
|
];
|
|
94
108
|
}
|
|
@@ -101,7 +115,9 @@ async function processSidebar(
|
|
|
101
115
|
async function processItems(
|
|
102
116
|
items: NormalizedSidebarItem[],
|
|
103
117
|
): Promise<ProcessedSidebarItem[]> {
|
|
104
|
-
return (
|
|
118
|
+
return (
|
|
119
|
+
await Promise.all(items.filter((i) => !isDraftItem(i)).map(processItem))
|
|
120
|
+
).flat();
|
|
105
121
|
}
|
|
106
122
|
|
|
107
123
|
const processedSidebar = await processItems(unprocessedSidebar);
|
package/src/sidebars/types.ts
CHANGED
|
@@ -269,6 +269,7 @@ export type SidebarProcessorParams = {
|
|
|
269
269
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
|
270
270
|
numberPrefixParser: NumberPrefixParser;
|
|
271
271
|
docs: DocMetadataBase[];
|
|
272
|
+
drafts: DocMetadataBase[];
|
|
272
273
|
version: VersionMetadata;
|
|
273
274
|
categoryLabelSlugger: Slugger;
|
|
274
275
|
sidebarOptions: SidebarOptions;
|
package/src/types.ts
CHANGED