@azerion/bunosaurus-plugin-content-docs 0.0.0-stage → 4.0.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/README.md +6 -2
- package/lib/categoryGeneratedIndex.d.ts +12 -0
- package/lib/categoryGeneratedIndex.js +36 -0
- package/lib/cli.d.ts +13 -0
- package/lib/cli.js +124 -0
- package/lib/client/doc.d.ts +29 -0
- package/lib/client/doc.js +47 -0
- package/lib/client/docSidebarItemsExpandedState.d.ts +30 -0
- package/lib/client/docSidebarItemsExpandedState.js +27 -0
- package/lib/client/docsClientUtils.d.ts +15 -0
- package/lib/client/docsClientUtils.js +86 -0
- package/lib/client/docsPreferredVersion.d.ts +29 -0
- package/lib/client/docsPreferredVersion.js +124 -0
- package/lib/client/docsSearch.d.ts +19 -0
- package/lib/client/docsSearch.js +39 -0
- package/lib/client/docsSidebar.d.ts +25 -0
- package/lib/client/docsSidebar.js +29 -0
- package/lib/client/docsUtils.d.ts +112 -0
- package/lib/client/docsUtils.js +299 -0
- package/lib/client/docsVersion.d.ts +19 -0
- package/lib/client/docsVersion.js +25 -0
- package/lib/client/index.d.ts +91 -0
- package/lib/client/index.js +83 -0
- package/lib/client/structuredDataUtils.d.ts +11 -0
- package/lib/client/structuredDataUtils.js +35 -0
- package/lib/constants.d.ts +14 -0
- package/lib/constants.js +17 -0
- package/lib/contentHelpers.d.ts +12 -0
- package/lib/contentHelpers.js +31 -0
- package/lib/docs.d.ts +48 -0
- package/lib/docs.js +252 -0
- package/lib/frontMatter.d.ts +10 -0
- package/lib/frontMatter.js +46 -0
- package/lib/globalData.d.ts +9 -0
- package/lib/globalData.js +59 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +198 -0
- package/lib/numberPrefix.d.ts +11 -0
- package/lib/numberPrefix.js +50 -0
- package/lib/options.d.ts +10 -0
- package/lib/options.js +138 -0
- package/lib/props.d.ts +21 -0
- package/lib/props.js +156 -0
- package/lib/routes.d.ts +22 -0
- package/lib/routes.js +184 -0
- package/lib/server-export.d.ts +9 -0
- package/lib/server-export.js +25 -0
- package/lib/sidebars/generator.d.ts +10 -0
- package/lib/sidebars/generator.js +217 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +99 -0
- package/lib/sidebars/normalization.d.ts +13 -0
- package/lib/sidebars/normalization.js +58 -0
- package/lib/sidebars/postProcessor.d.ts +11 -0
- package/lib/sidebars/postProcessor.js +82 -0
- package/lib/sidebars/processor.d.ts +10 -0
- package/lib/sidebars/processor.js +77 -0
- package/lib/sidebars/types.d.ts +192 -0
- package/lib/sidebars/types.js +8 -0
- package/lib/sidebars/utils.d.ts +69 -0
- package/lib/sidebars/utils.js +327 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +152 -0
- package/lib/slug.d.ts +15 -0
- package/lib/slug.js +51 -0
- package/lib/translations.d.ts +10 -0
- package/lib/translations.js +243 -0
- package/lib/types.d.ts +27 -0
- package/lib/types.js +8 -0
- package/lib/versions/files.d.ts +54 -0
- package/lib/versions/files.js +152 -0
- package/lib/versions/loadVersion.d.ts +17 -0
- package/lib/versions/loadVersion.js +126 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +70 -0
- package/lib/versions/version.d.ts +40 -0
- package/lib/versions/version.js +189 -0
- package/package.json +70 -4
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +180 -0
- package/src/client/doc.tsx +71 -0
- package/src/client/docSidebarItemsExpandedState.tsx +55 -0
- package/src/client/docsClientUtils.ts +140 -0
- package/src/client/docsPreferredVersion.tsx +245 -0
- package/src/client/docsSearch.test.ts +15 -0
- package/src/client/docsSearch.ts +57 -0
- package/src/client/docsSidebar.tsx +50 -0
- package/src/client/docsUtils.tsx +442 -0
- package/src/client/docsVersion.tsx +36 -0
- package/src/client/index.ts +211 -0
- package/src/client/structuredDataUtils.ts +54 -0
- package/src/constants.ts +15 -0
- package/src/contentHelpers.ts +34 -0
- package/src/docs.ts +402 -0
- package/src/frontMatter.ts +57 -0
- package/src/globalData.ts +79 -0
- package/src/index.ts +289 -0
- package/src/numberPrefix.ts +62 -0
- package/src/options.ts +185 -0
- package/src/plugin-content-docs.d.ts +667 -0
- package/src/props.ts +223 -0
- package/src/routes.ts +263 -0
- package/src/server-export.ts +26 -0
- package/src/sidebars/README.md +10 -0
- package/src/sidebars/generator.ts +307 -0
- package/src/sidebars/index.ts +130 -0
- package/src/sidebars/normalization.ts +91 -0
- package/src/sidebars/postProcessor.ts +115 -0
- package/src/sidebars/processor.ts +122 -0
- package/src/sidebars/types.ts +293 -0
- package/src/sidebars/utils.ts +529 -0
- package/src/sidebars/validation.ts +189 -0
- package/src/slug.ts +79 -0
- package/src/translations.ts +365 -0
- package/src/types.ts +34 -0
- package/src/versions/files.ts +240 -0
- package/src/versions/loadVersion.ts +185 -0
- package/src/versions/validation.ts +115 -0
- package/src/versions/version.ts +300 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateOptions = void 0;
|
|
10
|
+
exports.default = pluginContentDocs;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const glob_1 = require("@docusaurus/glob");
|
|
15
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
|
+
const mdx_loader_1 = require("@docusaurus/mdx-loader");
|
|
17
|
+
const fs_1 = require("@docusaurus/fs");
|
|
18
|
+
const sidebars_1 = require("./sidebars");
|
|
19
|
+
const generator_1 = require("./sidebars/generator");
|
|
20
|
+
const version_1 = require("./versions/version");
|
|
21
|
+
const cli_1 = tslib_1.__importDefault(require("./cli"));
|
|
22
|
+
const constants_1 = require("./constants");
|
|
23
|
+
const globalData_1 = require("./globalData");
|
|
24
|
+
const translations_1 = require("./translations");
|
|
25
|
+
const routes_1 = require("./routes");
|
|
26
|
+
const contentHelpers_1 = require("./contentHelpers");
|
|
27
|
+
const loadVersion_1 = require("./versions/loadVersion");
|
|
28
|
+
// MDX loader is not 100% deterministic, leading to cache invalidation issue
|
|
29
|
+
// This permits to invalidate the MDX loader cache entries when content changes
|
|
30
|
+
// Problem documented here: https://github.com/facebook/docusaurus/pull/10934
|
|
31
|
+
// TODO this is not a perfect solution, find better?
|
|
32
|
+
async function createMdxLoaderDependencyFile({ dataDir, options, versionsMetadata, }) {
|
|
33
|
+
// Disabled for unit tests, the side effect produces infinite watch loops
|
|
34
|
+
// TODO find a better way :/
|
|
35
|
+
if (process.env.NODE_ENV === 'test') {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const filePath = node_path_1.default.join(dataDir, '__mdx-loader-dependency.json');
|
|
39
|
+
// the cache is invalidated whenever this file content changes
|
|
40
|
+
const fileContent = {
|
|
41
|
+
options,
|
|
42
|
+
versionsMetadata,
|
|
43
|
+
};
|
|
44
|
+
await fs_1.fs.mkdir(dataDir, { recursive: true });
|
|
45
|
+
await fs_1.fs.writeFile(filePath, JSON.stringify(fileContent));
|
|
46
|
+
return filePath;
|
|
47
|
+
}
|
|
48
|
+
async function pluginContentDocs(context, options) {
|
|
49
|
+
const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
|
|
50
|
+
// Mutate options to resolve sidebar path according to siteDir
|
|
51
|
+
options.sidebarPath = (0, sidebars_1.resolveSidebarPathOption)(siteDir, options.sidebarPath);
|
|
52
|
+
const versionsMetadata = await (0, version_1.readVersionsMetadata)({ context, options });
|
|
53
|
+
const pluginId = options.id;
|
|
54
|
+
const pluginDataDirRoot = node_path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
|
|
55
|
+
const dataDir = node_path_1.default.join(pluginDataDirRoot, pluginId);
|
|
56
|
+
// TODO Docusaurus v4 breaking change
|
|
57
|
+
// module aliasing should be automatic
|
|
58
|
+
// we should never find local absolute FS paths in the codegen registry
|
|
59
|
+
const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(node_path_1.default.relative(pluginDataDirRoot, source))}`;
|
|
60
|
+
// TODO env should be injected into all plugins
|
|
61
|
+
const env = process.env.NODE_ENV;
|
|
62
|
+
const contentHelpers = (0, contentHelpers_1.createContentHelpers)();
|
|
63
|
+
const mdxLoaderDependency = await createMdxLoaderDependencyFile({
|
|
64
|
+
dataDir,
|
|
65
|
+
options,
|
|
66
|
+
versionsMetadata,
|
|
67
|
+
});
|
|
68
|
+
function createDocsMDXLoaderRule() {
|
|
69
|
+
const { rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
|
|
70
|
+
const contentDirs = versionsMetadata
|
|
71
|
+
.flatMap(utils_1.getContentPathList)
|
|
72
|
+
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
73
|
+
.map(utils_1.addTrailingPathSeparator);
|
|
74
|
+
return (0, mdx_loader_1.createMDXLoaderRule)({
|
|
75
|
+
include: contentDirs,
|
|
76
|
+
options: {
|
|
77
|
+
dependencies: [mdxLoaderDependency].filter((d) => typeof d === 'string'),
|
|
78
|
+
admonitions: options.admonitions,
|
|
79
|
+
remarkPlugins,
|
|
80
|
+
rehypePlugins,
|
|
81
|
+
recmaPlugins,
|
|
82
|
+
beforeDefaultRehypePlugins,
|
|
83
|
+
beforeDefaultRemarkPlugins,
|
|
84
|
+
staticDirs: siteConfig.staticDirectories.map((dir) => node_path_1.default.resolve(siteDir, dir)),
|
|
85
|
+
siteDir,
|
|
86
|
+
isMDXPartial: (0, glob_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
|
|
87
|
+
metadataPath: (mdxPath) => {
|
|
88
|
+
// Note that metadataPath must be the same/in-sync as
|
|
89
|
+
// the path from createData for each MDX.
|
|
90
|
+
const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
|
|
91
|
+
return node_path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
|
|
92
|
+
},
|
|
93
|
+
// createAssets converts relative paths to require() calls
|
|
94
|
+
createAssets: ({ frontMatter }) => ({
|
|
95
|
+
image: frontMatter.image,
|
|
96
|
+
}),
|
|
97
|
+
markdownConfig: siteConfig.markdown,
|
|
98
|
+
resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
|
|
99
|
+
const version = (0, version_1.getVersionFromSourceFilePath)(sourceFilePath, versionsMetadata);
|
|
100
|
+
return (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
|
|
101
|
+
sourceFilePath,
|
|
102
|
+
sourceToPermalink: contentHelpers.sourceToPermalink,
|
|
103
|
+
siteDir,
|
|
104
|
+
contentPaths: version,
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const docsMDXLoaderRule = createDocsMDXLoaderRule();
|
|
111
|
+
return {
|
|
112
|
+
name: 'docusaurus-plugin-content-docs',
|
|
113
|
+
extendCli(cli) {
|
|
114
|
+
const isDefaultPluginId = pluginId === utils_1.DEFAULT_PLUGIN_ID;
|
|
115
|
+
// Need to create one distinct command per plugin instance
|
|
116
|
+
// otherwise 2 instances would try to execute the command!
|
|
117
|
+
const command = isDefaultPluginId
|
|
118
|
+
? 'docs:version'
|
|
119
|
+
: `docs:version:${pluginId}`;
|
|
120
|
+
const commandDescription = isDefaultPluginId
|
|
121
|
+
? 'Tag a new docs version'
|
|
122
|
+
: `Tag a new docs version (${pluginId})`;
|
|
123
|
+
cli
|
|
124
|
+
.command(command)
|
|
125
|
+
.arguments('<version>')
|
|
126
|
+
.description(commandDescription)
|
|
127
|
+
.action((version) => cli_1.default.cliDocsVersionCommand(version, options, context));
|
|
128
|
+
},
|
|
129
|
+
getTranslationFiles({ content }) {
|
|
130
|
+
return (0, translations_1.getLoadedContentTranslationFiles)(content);
|
|
131
|
+
},
|
|
132
|
+
getPathsToWatch() {
|
|
133
|
+
function getVersionPathsToWatch(version) {
|
|
134
|
+
const result = [
|
|
135
|
+
...options.include.flatMap((pattern) => (0, utils_1.getContentPathList)(version).map((docsDirPath) => `${docsDirPath}/${pattern}`)),
|
|
136
|
+
...(0, utils_validation_1.getTagsFilePathsToWatch)({
|
|
137
|
+
contentPaths: version,
|
|
138
|
+
tags: options.tags,
|
|
139
|
+
}),
|
|
140
|
+
`${version.contentPath}/**/${generator_1.CategoryMetadataFilenamePattern}`,
|
|
141
|
+
];
|
|
142
|
+
if (typeof version.sidebarFilePath === 'string') {
|
|
143
|
+
result.unshift(version.sidebarFilePath);
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
return versionsMetadata.flatMap(getVersionPathsToWatch);
|
|
148
|
+
},
|
|
149
|
+
async loadContent() {
|
|
150
|
+
return {
|
|
151
|
+
loadedVersions: await Promise.all(versionsMetadata.map((versionMetadata) => (0, loadVersion_1.loadVersion)({
|
|
152
|
+
context,
|
|
153
|
+
options,
|
|
154
|
+
env,
|
|
155
|
+
versionMetadata,
|
|
156
|
+
}))),
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
translateContent({ content, translationFiles }) {
|
|
160
|
+
return (0, translations_1.translateLoadedContent)(content, translationFiles);
|
|
161
|
+
},
|
|
162
|
+
async contentLoaded({ content, actions }) {
|
|
163
|
+
contentHelpers.updateContent(content);
|
|
164
|
+
const versions = content.loadedVersions.map(version_1.toFullVersion);
|
|
165
|
+
await (0, routes_1.createAllRoutes)({
|
|
166
|
+
baseUrl,
|
|
167
|
+
versions,
|
|
168
|
+
options,
|
|
169
|
+
actions,
|
|
170
|
+
aliasedSource,
|
|
171
|
+
});
|
|
172
|
+
actions.setGlobalData({
|
|
173
|
+
path: (0, utils_1.normalizeUrl)([baseUrl, options.routeBasePath]),
|
|
174
|
+
versions: versions.map(globalData_1.toGlobalDataVersion),
|
|
175
|
+
breadcrumbs: options.breadcrumbs,
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
configureWebpack() {
|
|
179
|
+
return {
|
|
180
|
+
ignoreWarnings: [
|
|
181
|
+
// Suppress warnings about non-existing of versions file.
|
|
182
|
+
(e) => e.message.includes("Can't resolve") &&
|
|
183
|
+
e.message.includes(constants_1.VERSIONS_JSON_FILE),
|
|
184
|
+
],
|
|
185
|
+
resolve: {
|
|
186
|
+
alias: {
|
|
187
|
+
'~docs': pluginDataDirRoot,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
module: {
|
|
191
|
+
rules: [docsMDXLoaderRule],
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
var options_1 = require("./options");
|
|
198
|
+
Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { NumberPrefixParser } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
export declare const DefaultNumberPrefixParser: NumberPrefixParser;
|
|
9
|
+
export declare const DisabledNumberPrefixParser: NumberPrefixParser;
|
|
10
|
+
export declare function stripNumberPrefix(str: string, parser: NumberPrefixParser): string;
|
|
11
|
+
export declare function stripPathNumberPrefixes(path: string, parser: NumberPrefixParser): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DisabledNumberPrefixParser = exports.DefaultNumberPrefixParser = void 0;
|
|
10
|
+
exports.stripNumberPrefix = stripNumberPrefix;
|
|
11
|
+
exports.stripPathNumberPrefixes = stripPathNumberPrefixes;
|
|
12
|
+
// Best-effort to avoid parsing some patterns as number prefix
|
|
13
|
+
// ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
|
|
14
|
+
// ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
|
|
15
|
+
// Both of them would look like 7.0-foo or 2021-11-foo
|
|
16
|
+
// note: we could try to parse float numbers in filenames, but that is probably
|
|
17
|
+
// not worth it, as a version such as "8.0" can be interpreted as either a
|
|
18
|
+
// version or a float. User can configure her own NumberPrefixParser if she
|
|
19
|
+
// wants 8.0 to be interpreted as a float
|
|
20
|
+
const ignoredPrefixPattern = /^\d+[-_.]\d+/;
|
|
21
|
+
const numberPrefixPattern = /^(?<numberPrefix>\d+)\s*[-_.]+\s*(?<suffix>[^-_.\s].*)$/;
|
|
22
|
+
// 0-myDoc => {filename: myDoc, numberPrefix: 0}
|
|
23
|
+
// 003 - myDoc => {filename: myDoc, numberPrefix: 3}
|
|
24
|
+
const DefaultNumberPrefixParser = (filename) => {
|
|
25
|
+
if (ignoredPrefixPattern.test(filename)) {
|
|
26
|
+
return { filename, numberPrefix: undefined };
|
|
27
|
+
}
|
|
28
|
+
const match = numberPrefixPattern.exec(filename);
|
|
29
|
+
if (!match) {
|
|
30
|
+
return { filename, numberPrefix: undefined };
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
filename: match.groups.suffix,
|
|
34
|
+
numberPrefix: parseInt(match.groups.numberPrefix, 10),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.DefaultNumberPrefixParser = DefaultNumberPrefixParser;
|
|
38
|
+
const DisabledNumberPrefixParser = (filename) => ({ filename, numberPrefix: undefined });
|
|
39
|
+
exports.DisabledNumberPrefixParser = DisabledNumberPrefixParser;
|
|
40
|
+
// 0-myDoc => myDoc
|
|
41
|
+
function stripNumberPrefix(str, parser) {
|
|
42
|
+
return parser(str).filename;
|
|
43
|
+
}
|
|
44
|
+
// 0-myFolder/0-mySubfolder/0-myDoc => myFolder/mySubfolder/myDoc
|
|
45
|
+
function stripPathNumberPrefixes(path, parser) {
|
|
46
|
+
return path
|
|
47
|
+
.split('/')
|
|
48
|
+
.map((segment) => stripNumberPrefix(segment, parser))
|
|
49
|
+
.join('/');
|
|
50
|
+
}
|
package/lib/options.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { OptionValidationContext } from '@docusaurus/types';
|
|
8
|
+
import type { PluginOptions, Options } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
export declare const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'>;
|
|
10
|
+
export declare function validateOptions({ validate, options: userOptions, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
|
package/lib/options.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DEFAULT_OPTIONS = void 0;
|
|
10
|
+
exports.validateOptions = validateOptions;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
14
|
+
const glob_1 = require("@docusaurus/glob");
|
|
15
|
+
const generator_1 = require("./sidebars/generator");
|
|
16
|
+
const numberPrefix_1 = require("./numberPrefix");
|
|
17
|
+
exports.DEFAULT_OPTIONS = {
|
|
18
|
+
path: 'docs', // Path to data on filesystem, relative to site dir.
|
|
19
|
+
routeBasePath: 'docs', // URL Route.
|
|
20
|
+
tagsBasePath: 'tags', // URL Tags Route.
|
|
21
|
+
include: ['**/*.{md,mdx}'], // Extensions to include.
|
|
22
|
+
exclude: glob_1.GlobExcludeDefault,
|
|
23
|
+
sidebarItemsGenerator: generator_1.DefaultSidebarItemsGenerator,
|
|
24
|
+
numberPrefixParser: numberPrefix_1.DefaultNumberPrefixParser,
|
|
25
|
+
docsRootComponent: '@theme/DocsRoot',
|
|
26
|
+
docVersionRootComponent: '@theme/DocVersionRoot',
|
|
27
|
+
docRootComponent: '@theme/DocRoot',
|
|
28
|
+
docItemComponent: '@theme/DocItem',
|
|
29
|
+
docTagDocListComponent: '@theme/DocTagDocListPage',
|
|
30
|
+
docTagsListComponent: '@theme/DocTagsListPage',
|
|
31
|
+
docCategoryGeneratedIndexComponent: '@theme/DocCategoryGeneratedIndexPage',
|
|
32
|
+
remarkPlugins: [],
|
|
33
|
+
rehypePlugins: [],
|
|
34
|
+
recmaPlugins: [],
|
|
35
|
+
beforeDefaultRemarkPlugins: [],
|
|
36
|
+
beforeDefaultRehypePlugins: [],
|
|
37
|
+
showLastUpdateTime: false,
|
|
38
|
+
showLastUpdateAuthor: false,
|
|
39
|
+
admonitions: true,
|
|
40
|
+
includeCurrentVersion: true,
|
|
41
|
+
disableVersioning: false,
|
|
42
|
+
lastVersion: undefined,
|
|
43
|
+
versions: {},
|
|
44
|
+
editCurrentVersion: false,
|
|
45
|
+
editLocalizedFiles: false,
|
|
46
|
+
sidebarCollapsible: true,
|
|
47
|
+
sidebarCollapsed: true,
|
|
48
|
+
breadcrumbs: true,
|
|
49
|
+
onInlineTags: 'warn',
|
|
50
|
+
tags: undefined,
|
|
51
|
+
};
|
|
52
|
+
const VersionOptionsSchema = utils_validation_1.Joi.object({
|
|
53
|
+
path: utils_validation_1.Joi.string().allow('').optional(),
|
|
54
|
+
label: utils_validation_1.Joi.string().optional(),
|
|
55
|
+
banner: utils_validation_1.Joi.string().equal('none', 'unreleased', 'unmaintained').optional(),
|
|
56
|
+
badge: utils_validation_1.Joi.boolean().optional(),
|
|
57
|
+
className: utils_validation_1.Joi.string().optional(),
|
|
58
|
+
noIndex: utils_validation_1.Joi.boolean().optional(),
|
|
59
|
+
});
|
|
60
|
+
const VersionsOptionsSchema = utils_validation_1.Joi.object()
|
|
61
|
+
.pattern(utils_validation_1.Joi.string().required(), VersionOptionsSchema)
|
|
62
|
+
.default(exports.DEFAULT_OPTIONS.versions);
|
|
63
|
+
const OptionsSchema = utils_validation_1.Joi.object({
|
|
64
|
+
path: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.path),
|
|
65
|
+
editUrl: utils_validation_1.Joi.alternatives().try(utils_validation_1.URISchema, utils_validation_1.Joi.function()),
|
|
66
|
+
editCurrentVersion: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.editCurrentVersion),
|
|
67
|
+
editLocalizedFiles: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.editLocalizedFiles),
|
|
68
|
+
routeBasePath: utils_validation_1.RouteBasePathSchema.default(exports.DEFAULT_OPTIONS.routeBasePath),
|
|
69
|
+
tagsBasePath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.tagsBasePath),
|
|
70
|
+
// @ts-expect-error: deprecated
|
|
71
|
+
homePageId: utils_validation_1.Joi.any().forbidden().messages({
|
|
72
|
+
'any.unknown': 'The docs plugin option homePageId is not supported anymore. To make a doc the "home", please add "slug: /" in its front matter. See: https://docusaurus.io/docs/next/docs-introduction#home-page-docs',
|
|
73
|
+
}),
|
|
74
|
+
include: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.include),
|
|
75
|
+
exclude: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.exclude),
|
|
76
|
+
sidebarPath: utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.boolean().invalid(true), utils_validation_1.Joi.string()),
|
|
77
|
+
sidebarItemsGenerator: utils_validation_1.Joi.function().default(() => exports.DEFAULT_OPTIONS.sidebarItemsGenerator),
|
|
78
|
+
sidebarCollapsible: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.sidebarCollapsible),
|
|
79
|
+
sidebarCollapsed: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.sidebarCollapsed),
|
|
80
|
+
numberPrefixParser: utils_validation_1.Joi.alternatives()
|
|
81
|
+
.try(utils_validation_1.Joi.function(),
|
|
82
|
+
// Convert boolean values to functions
|
|
83
|
+
utils_validation_1.Joi.alternatives().conditional(utils_validation_1.Joi.boolean(), {
|
|
84
|
+
then: utils_validation_1.Joi.custom((val) => val ? numberPrefix_1.DefaultNumberPrefixParser : numberPrefix_1.DisabledNumberPrefixParser),
|
|
85
|
+
}))
|
|
86
|
+
.default(() => exports.DEFAULT_OPTIONS.numberPrefixParser),
|
|
87
|
+
docsRootComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docsRootComponent),
|
|
88
|
+
docVersionRootComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docVersionRootComponent),
|
|
89
|
+
docRootComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docRootComponent),
|
|
90
|
+
docItemComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docItemComponent),
|
|
91
|
+
docTagsListComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docTagsListComponent),
|
|
92
|
+
docTagDocListComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docTagDocListComponent),
|
|
93
|
+
docCategoryGeneratedIndexComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docCategoryGeneratedIndexComponent),
|
|
94
|
+
remarkPlugins: utils_validation_1.RemarkPluginsSchema.default(exports.DEFAULT_OPTIONS.remarkPlugins),
|
|
95
|
+
rehypePlugins: utils_validation_1.RehypePluginsSchema.default(exports.DEFAULT_OPTIONS.rehypePlugins),
|
|
96
|
+
recmaPlugins: utils_validation_1.RecmaPluginsSchema.default(exports.DEFAULT_OPTIONS.recmaPlugins),
|
|
97
|
+
beforeDefaultRemarkPlugins: utils_validation_1.RemarkPluginsSchema.default(exports.DEFAULT_OPTIONS.beforeDefaultRemarkPlugins),
|
|
98
|
+
beforeDefaultRehypePlugins: utils_validation_1.RehypePluginsSchema.default(exports.DEFAULT_OPTIONS.beforeDefaultRehypePlugins),
|
|
99
|
+
admonitions: utils_validation_1.AdmonitionsSchema.default(exports.DEFAULT_OPTIONS.admonitions),
|
|
100
|
+
showLastUpdateTime: utils_validation_1.Joi.bool().default(exports.DEFAULT_OPTIONS.showLastUpdateTime),
|
|
101
|
+
showLastUpdateAuthor: utils_validation_1.Joi.bool().default(exports.DEFAULT_OPTIONS.showLastUpdateAuthor),
|
|
102
|
+
includeCurrentVersion: utils_validation_1.Joi.bool().default(exports.DEFAULT_OPTIONS.includeCurrentVersion),
|
|
103
|
+
onlyIncludeVersions: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string().required()).optional(),
|
|
104
|
+
disableVersioning: utils_validation_1.Joi.bool().default(exports.DEFAULT_OPTIONS.disableVersioning),
|
|
105
|
+
lastVersion: utils_validation_1.Joi.string().optional(),
|
|
106
|
+
versions: VersionsOptionsSchema,
|
|
107
|
+
breadcrumbs: utils_validation_1.Joi.bool().default(exports.DEFAULT_OPTIONS.breadcrumbs),
|
|
108
|
+
onInlineTags: utils_validation_1.Joi.string()
|
|
109
|
+
.equal('ignore', 'log', 'warn', 'throw')
|
|
110
|
+
.default(exports.DEFAULT_OPTIONS.onInlineTags),
|
|
111
|
+
tags: utils_validation_1.Joi.string()
|
|
112
|
+
.disallow('')
|
|
113
|
+
.allow(null, false)
|
|
114
|
+
.default(() => exports.DEFAULT_OPTIONS.tags),
|
|
115
|
+
});
|
|
116
|
+
function validateOptions({ validate, options: userOptions, }) {
|
|
117
|
+
let options = userOptions;
|
|
118
|
+
if (options.sidebarCollapsible === false) {
|
|
119
|
+
// When sidebarCollapsible=false and sidebarCollapsed=undefined, we don't
|
|
120
|
+
// want to have the inconsistency warning. We let options.sidebarCollapsible
|
|
121
|
+
// become the default value for options.sidebarCollapsed
|
|
122
|
+
if (typeof options.sidebarCollapsed === 'undefined') {
|
|
123
|
+
options = {
|
|
124
|
+
...options,
|
|
125
|
+
sidebarCollapsed: false,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (options.sidebarCollapsed) {
|
|
129
|
+
logger_1.default.warn `The docs plugin config is inconsistent. It does not make sense to use code=${'sidebarCollapsible: false'} and code=${'sidebarCollapsed: true'} at the same time. code=${'sidebarCollapsed: true'} will be ignored.`;
|
|
130
|
+
options = {
|
|
131
|
+
...options,
|
|
132
|
+
sidebarCollapsed: false,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const normalizedOptions = validate(OptionsSchema, options);
|
|
137
|
+
return normalizedOptions;
|
|
138
|
+
}
|
package/lib/props.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
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'>;
|
|
13
|
+
}): PropSidebarItemLink;
|
|
14
|
+
export declare function toSidebarsProp(loadedVersion: Pick<LoadedVersion, 'docs' | 'sidebars'>): PropSidebars;
|
|
15
|
+
export declare function toVersionMetadataProp(pluginId: string, loadedVersion: LoadedVersion): PropVersionMetadata;
|
|
16
|
+
export declare function toTagDocListProp({ allTagsPath, tag, docs, }: {
|
|
17
|
+
allTagsPath: string;
|
|
18
|
+
tag: VersionTag;
|
|
19
|
+
docs: DocMetadata[];
|
|
20
|
+
}): PropTagDocList;
|
|
21
|
+
export declare function toTagsListTagsProp(versionTags: VersionTags): PropTagsListPage['tags'];
|
package/lib/props.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.toSidebarDocItemLinkProp = toSidebarDocItemLinkProp;
|
|
10
|
+
exports.toSidebarsProp = toSidebarsProp;
|
|
11
|
+
exports.toVersionMetadataProp = toVersionMetadataProp;
|
|
12
|
+
exports.toTagDocListProp = toTagDocListProp;
|
|
13
|
+
exports.toTagsListTagsProp = toTagsListTagsProp;
|
|
14
|
+
const tslib_1 = require("tslib");
|
|
15
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
16
|
+
const docs_1 = require("./docs");
|
|
17
|
+
function toSidebarDocItemLinkProp({ item, doc, }) {
|
|
18
|
+
const { id, title, permalink, frontMatter, unlisted } = doc;
|
|
19
|
+
return {
|
|
20
|
+
type: 'link',
|
|
21
|
+
...(item.key && { key: item.key }),
|
|
22
|
+
href: permalink,
|
|
23
|
+
// Front Matter data takes precedence over sidebars.json
|
|
24
|
+
label: frontMatter.sidebar_label ?? item.label ?? title,
|
|
25
|
+
className: frontMatter.sidebar_class_name ?? item.className,
|
|
26
|
+
customProps: frontMatter.sidebar_custom_props ?? item.customProps,
|
|
27
|
+
docId: id,
|
|
28
|
+
unlisted,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function toSidebarsProp(loadedVersion) {
|
|
32
|
+
const docsById = (0, docs_1.createDocsByIdIndex)(loadedVersion.docs);
|
|
33
|
+
function getDocById(docId) {
|
|
34
|
+
const docMetadata = docsById[docId];
|
|
35
|
+
if (!docMetadata) {
|
|
36
|
+
throw new Error(`Invalid sidebars file. The document with id "${docId}" was used in the sidebar, but no document with this id could be found.
|
|
37
|
+
Available document ids are:
|
|
38
|
+
- ${Object.keys(docsById).sort().join('\n- ')}`);
|
|
39
|
+
}
|
|
40
|
+
return docMetadata;
|
|
41
|
+
}
|
|
42
|
+
const convertDocLink = (item) => {
|
|
43
|
+
const doc = getDocById(item.id);
|
|
44
|
+
return toSidebarDocItemLinkProp({ item, doc });
|
|
45
|
+
};
|
|
46
|
+
function getCategoryLinkHref(link) {
|
|
47
|
+
switch (link?.type) {
|
|
48
|
+
case 'doc':
|
|
49
|
+
return getDocById(link.id).permalink;
|
|
50
|
+
case 'generated-index':
|
|
51
|
+
return link.permalink;
|
|
52
|
+
default:
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function getCategoryLinkUnlisted(link) {
|
|
57
|
+
if (link?.type === 'doc') {
|
|
58
|
+
return getDocById(link.id).unlisted;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
function getCategoryLinkCustomProps(link) {
|
|
63
|
+
switch (link?.type) {
|
|
64
|
+
case 'doc':
|
|
65
|
+
return getDocById(link.id).frontMatter.sidebar_custom_props;
|
|
66
|
+
default:
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function convertCategory(item) {
|
|
71
|
+
const { link, ...rest } = item;
|
|
72
|
+
const href = getCategoryLinkHref(link);
|
|
73
|
+
const linkUnlisted = getCategoryLinkUnlisted(link);
|
|
74
|
+
const customProps = item.customProps ?? getCategoryLinkCustomProps(link);
|
|
75
|
+
return {
|
|
76
|
+
...rest,
|
|
77
|
+
items: item.items.map(normalizeItem),
|
|
78
|
+
...(href && { href }),
|
|
79
|
+
...(linkUnlisted && { linkUnlisted }),
|
|
80
|
+
...(customProps && { customProps }),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function normalizeItem(item) {
|
|
84
|
+
switch (item.type) {
|
|
85
|
+
case 'category':
|
|
86
|
+
return convertCategory(item);
|
|
87
|
+
case 'ref':
|
|
88
|
+
case 'doc':
|
|
89
|
+
return convertDocLink(item);
|
|
90
|
+
case 'link':
|
|
91
|
+
default:
|
|
92
|
+
return item;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Transform the sidebar so that all sidebar item will be in the
|
|
96
|
+
// form of 'link' or 'category' only.
|
|
97
|
+
// This is what will be passed as props to the UI component.
|
|
98
|
+
return lodash_1.default.mapValues(loadedVersion.sidebars, (items) => items.map(normalizeItem));
|
|
99
|
+
}
|
|
100
|
+
function toVersionDocsProp(loadedVersion) {
|
|
101
|
+
return Object.fromEntries(loadedVersion.docs.map((doc) => [
|
|
102
|
+
doc.id,
|
|
103
|
+
{
|
|
104
|
+
id: doc.id,
|
|
105
|
+
title: doc.title,
|
|
106
|
+
description: doc.description,
|
|
107
|
+
sidebar: doc.sidebar,
|
|
108
|
+
},
|
|
109
|
+
]));
|
|
110
|
+
}
|
|
111
|
+
function toVersionMetadataProp(pluginId, loadedVersion) {
|
|
112
|
+
return {
|
|
113
|
+
pluginId,
|
|
114
|
+
version: loadedVersion.versionName,
|
|
115
|
+
label: loadedVersion.label,
|
|
116
|
+
banner: loadedVersion.banner,
|
|
117
|
+
badge: loadedVersion.badge,
|
|
118
|
+
noIndex: loadedVersion.noIndex,
|
|
119
|
+
className: loadedVersion.className,
|
|
120
|
+
isLast: loadedVersion.isLast,
|
|
121
|
+
docsSidebars: toSidebarsProp(loadedVersion),
|
|
122
|
+
docs: toVersionDocsProp(loadedVersion),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function toTagDocListProp({ allTagsPath, tag, docs, }) {
|
|
126
|
+
function toDocListProp() {
|
|
127
|
+
const list = lodash_1.default.compact(tag.docIds.map((id) => docs.find((doc) => doc.id === id)));
|
|
128
|
+
// Sort docs by title
|
|
129
|
+
list.sort((doc1, doc2) => doc1.title.localeCompare(doc2.title));
|
|
130
|
+
return list.map((doc) => ({
|
|
131
|
+
id: doc.id,
|
|
132
|
+
title: doc.title,
|
|
133
|
+
description: doc.description,
|
|
134
|
+
permalink: doc.permalink,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
label: tag.label,
|
|
139
|
+
permalink: tag.permalink,
|
|
140
|
+
description: tag.description,
|
|
141
|
+
allTagsPath,
|
|
142
|
+
count: tag.docIds.length,
|
|
143
|
+
items: toDocListProp(),
|
|
144
|
+
unlisted: tag.unlisted,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function toTagsListTagsProp(versionTags) {
|
|
148
|
+
return Object.values(versionTags)
|
|
149
|
+
.filter((tagValue) => !tagValue.unlisted)
|
|
150
|
+
.map((tagValue) => ({
|
|
151
|
+
label: tagValue.label,
|
|
152
|
+
permalink: tagValue.permalink,
|
|
153
|
+
description: tagValue.description,
|
|
154
|
+
count: tagValue.docIds.length,
|
|
155
|
+
}));
|
|
156
|
+
}
|
package/lib/routes.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginContentLoadedActions, RouteConfig } from '@docusaurus/types';
|
|
8
|
+
import type { FullVersion } from './types';
|
|
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;
|
|
18
|
+
actions: PluginContentLoadedActions;
|
|
19
|
+
aliasedSource: (str: string) => string;
|
|
20
|
+
};
|
|
21
|
+
export declare function createAllRoutes(param: CreateAllRoutesParam): Promise<void>;
|
|
22
|
+
export {};
|