@apify/docusaurus-plugin-typedoc-api 3.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/LICENSE +21 -0
- package/README.md +290 -0
- package/assets/styles-8ad572ec.css +303 -0
- package/lib/components/AnchorLink.js +22 -0
- package/lib/components/AnchorLink.js.map +1 -0
- package/lib/components/ApiChangelog.js +28 -0
- package/lib/components/ApiChangelog.js.map +1 -0
- package/lib/components/ApiDataContext.js +16 -0
- package/lib/components/ApiDataContext.js.map +1 -0
- package/lib/components/ApiIndex.js +80 -0
- package/lib/components/ApiIndex.js.map +1 -0
- package/lib/components/ApiItem.js +86 -0
- package/lib/components/ApiItem.js.map +1 -0
- package/lib/components/ApiItemLayout.js +69 -0
- package/lib/components/ApiItemLayout.js.map +1 -0
- package/lib/components/ApiPage.js +69 -0
- package/lib/components/ApiPage.js.map +1 -0
- package/lib/components/Breadcrumb.js +38 -0
- package/lib/components/Breadcrumb.js.map +1 -0
- package/lib/components/Comment.js +56 -0
- package/lib/components/Comment.js.map +1 -0
- package/lib/components/CommentBadges.js +35 -0
- package/lib/components/CommentBadges.js.map +1 -0
- package/lib/components/DefaultValue.js +49 -0
- package/lib/components/DefaultValue.js.map +1 -0
- package/lib/components/Flags.js +27 -0
- package/lib/components/Flags.js.map +1 -0
- package/lib/components/Footer.js +18 -0
- package/lib/components/Footer.js.map +1 -0
- package/lib/components/Hierarchy.js +27 -0
- package/lib/components/Hierarchy.js.map +1 -0
- package/lib/components/Icon.js +27 -0
- package/lib/components/Icon.js.map +1 -0
- package/lib/components/Index.js +87 -0
- package/lib/components/Index.js.map +1 -0
- package/lib/components/Markdown.js +204 -0
- package/lib/components/Markdown.js.map +1 -0
- package/lib/components/Member.js +68 -0
- package/lib/components/Member.js.map +1 -0
- package/lib/components/MemberDeclaration.js +64 -0
- package/lib/components/MemberDeclaration.js.map +1 -0
- package/lib/components/MemberGetterSetter.js +61 -0
- package/lib/components/MemberGetterSetter.js.map +1 -0
- package/lib/components/MemberReference.js +38 -0
- package/lib/components/MemberReference.js.map +1 -0
- package/lib/components/MemberSignatureBody.js +91 -0
- package/lib/components/MemberSignatureBody.js.map +1 -0
- package/lib/components/MemberSignatureTitle.js +52 -0
- package/lib/components/MemberSignatureTitle.js.map +1 -0
- package/lib/components/MemberSignatures.js +61 -0
- package/lib/components/MemberSignatures.js.map +1 -0
- package/lib/components/MemberSources.js +33 -0
- package/lib/components/MemberSources.js.map +1 -0
- package/lib/components/Members.js +51 -0
- package/lib/components/Members.js.map +1 -0
- package/lib/components/MembersGroup.js +39 -0
- package/lib/components/MembersGroup.js.map +1 -0
- package/lib/components/Parameter.js +145 -0
- package/lib/components/Parameter.js.map +1 -0
- package/lib/components/Reflection.js +112 -0
- package/lib/components/Reflection.js.map +1 -0
- package/lib/components/SourceLink.js +37 -0
- package/lib/components/SourceLink.js.map +1 -0
- package/lib/components/Type.js +341 -0
- package/lib/components/Type.js.map +1 -0
- package/lib/components/TypeAndParent.js +27 -0
- package/lib/components/TypeAndParent.js.map +1 -0
- package/lib/components/TypeParameters.js +36 -0
- package/lib/components/TypeParameters.js.map +1 -0
- package/lib/components/TypeParametersGeneric.js +27 -0
- package/lib/components/TypeParametersGeneric.js.map +1 -0
- package/lib/components/VersionBanner.js +39 -0
- package/lib/components/VersionBanner.js.map +1 -0
- package/lib/hooks/useBreadcrumbs.js +9 -0
- package/lib/hooks/useBreadcrumbs.js.map +1 -0
- package/lib/hooks/useGitRefName.js +9 -0
- package/lib/hooks/useGitRefName.js.map +1 -0
- package/lib/hooks/useMinimalLayout.js +9 -0
- package/lib/hooks/useMinimalLayout.js.map +1 -0
- package/lib/hooks/useReflection.js +19 -0
- package/lib/hooks/useReflection.js.map +1 -0
- package/lib/hooks/useReflectionMap.js +9 -0
- package/lib/hooks/useReflectionMap.js.map +1 -0
- package/lib/index.js +320 -0
- package/lib/index.js.map +1 -0
- package/lib/markdownLoader.js +11 -0
- package/lib/markdownLoader.js.map +1 -0
- package/lib/plugin/data.js +332 -0
- package/lib/plugin/data.js.map +1 -0
- package/lib/plugin/sidebar.js +105 -0
- package/lib/plugin/sidebar.js.map +1 -0
- package/lib/plugin/structure/0.23.js +48 -0
- package/lib/plugin/structure/0.23.js.map +1 -0
- package/lib/plugin/url.js +49 -0
- package/lib/plugin/url.js.map +1 -0
- package/lib/plugin/version.js +83 -0
- package/lib/plugin/version.js.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/hierarchy.js +35 -0
- package/lib/utils/hierarchy.js.map +1 -0
- package/lib/utils/icons.js +124 -0
- package/lib/utils/icons.js.map +1 -0
- package/lib/utils/links.js +10 -0
- package/lib/utils/links.js.map +1 -0
- package/lib/utils/markdown.js +69 -0
- package/lib/utils/markdown.js.map +1 -0
- package/lib/utils/visibility.js +25 -0
- package/lib/utils/visibility.js.map +1 -0
- package/package.json +57 -0
- package/src/components/AnchorLink.tsx +14 -0
- package/src/components/ApiChangelog.tsx +26 -0
- package/src/components/ApiDataContext.ts +17 -0
- package/src/components/ApiIndex.tsx +109 -0
- package/src/components/ApiItem.tsx +110 -0
- package/src/components/ApiItemLayout.tsx +96 -0
- package/src/components/ApiPage.tsx +78 -0
- package/src/components/Breadcrumb.tsx +41 -0
- package/src/components/Comment.tsx +74 -0
- package/src/components/CommentBadges.tsx +40 -0
- package/src/components/DefaultValue.tsx +48 -0
- package/src/components/Flags.tsx +29 -0
- package/src/components/Footer.tsx +13 -0
- package/src/components/Hierarchy.tsx +27 -0
- package/src/components/Icon.tsx +20 -0
- package/src/components/Index.tsx +109 -0
- package/src/components/Markdown.tsx +241 -0
- package/src/components/Member.tsx +64 -0
- package/src/components/MemberDeclaration.tsx +67 -0
- package/src/components/MemberGetterSetter.tsx +69 -0
- package/src/components/MemberReference.tsx +43 -0
- package/src/components/MemberSignatureBody.tsx +121 -0
- package/src/components/MemberSignatureTitle.tsx +65 -0
- package/src/components/MemberSignatures.tsx +64 -0
- package/src/components/MemberSources.tsx +42 -0
- package/src/components/Members.tsx +62 -0
- package/src/components/MembersGroup.tsx +47 -0
- package/src/components/Parameter.tsx +165 -0
- package/src/components/README.md +9 -0
- package/src/components/Reflection.tsx +136 -0
- package/src/components/SourceLink.tsx +46 -0
- package/src/components/Type.tsx +377 -0
- package/src/components/TypeAndParent.tsx +26 -0
- package/src/components/TypeParameters.tsx +37 -0
- package/src/components/TypeParametersGeneric.tsx +25 -0
- package/src/components/VersionBanner.tsx +44 -0
- package/src/components/styles.css +303 -0
- package/src/hooks/useBreadcrumbs.ts +6 -0
- package/src/hooks/useGitRefName.ts +6 -0
- package/src/hooks/useMinimalLayout.ts +6 -0
- package/src/hooks/useReflection.ts +18 -0
- package/src/hooks/useReflectionMap.ts +7 -0
- package/src/index.ts +420 -0
- package/src/markdownLoader.ts +10 -0
- package/src/plugin/data.ts +389 -0
- package/src/plugin/sidebar.ts +139 -0
- package/src/plugin/structure/0.23.ts +58 -0
- package/src/plugin/url.ts +49 -0
- package/src/plugin/version.ts +118 -0
- package/src/types.ts +165 -0
- package/src/utils/hierarchy.ts +46 -0
- package/src/utils/icons.ts +103 -0
- package/src/utils/links.ts +10 -0
- package/src/utils/markdown.ts +82 -0
- package/src/utils/visibility.ts +31 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/* eslint-disable no-console, sort-keys */
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import type { JSONOutput } from 'typedoc';
|
|
6
|
+
import type { PropVersionDocs, PropVersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
7
|
+
import { CURRENT_VERSION_NAME } from '@docusaurus/plugin-content-docs/server';
|
|
8
|
+
import type { LoadContext, Plugin, RouteConfig } from '@docusaurus/types';
|
|
9
|
+
import { DEFAULT_PLUGIN_ID, normalizeUrl } from '@docusaurus/utils';
|
|
10
|
+
import {
|
|
11
|
+
flattenAndGroupPackages,
|
|
12
|
+
formatPackagesWithoutHostInfo,
|
|
13
|
+
generateJson,
|
|
14
|
+
loadPackageJsonAndDocs,
|
|
15
|
+
} from './plugin/data';
|
|
16
|
+
import { extractSidebar } from './plugin/sidebar';
|
|
17
|
+
import { getVersionedDocsDirPath, readVersionsMetadata } from './plugin/version';
|
|
18
|
+
import type {
|
|
19
|
+
ApiOptions,
|
|
20
|
+
DocusaurusPluginTypeDocApiOptions,
|
|
21
|
+
LoadedContent,
|
|
22
|
+
PackageEntryConfig,
|
|
23
|
+
PackageReflectionGroup,
|
|
24
|
+
ResolvedPackageConfig,
|
|
25
|
+
VersionMetadata,
|
|
26
|
+
} from './types';
|
|
27
|
+
|
|
28
|
+
const DEFAULT_OPTIONS: Required<DocusaurusPluginTypeDocApiOptions> = {
|
|
29
|
+
banner: '',
|
|
30
|
+
breadcrumbs: true,
|
|
31
|
+
changelogName: 'CHANGELOG.md',
|
|
32
|
+
changelogs: false,
|
|
33
|
+
debug: false,
|
|
34
|
+
disableVersioning: false,
|
|
35
|
+
exclude: [],
|
|
36
|
+
gitRefName: 'master',
|
|
37
|
+
id: DEFAULT_PLUGIN_ID,
|
|
38
|
+
includeCurrentVersion: true,
|
|
39
|
+
lastVersion: '',
|
|
40
|
+
minimal: false,
|
|
41
|
+
onlyIncludeVersions: [],
|
|
42
|
+
packageJsonName: 'package.json',
|
|
43
|
+
packages: [],
|
|
44
|
+
pathToCurrentVersionTypedocJSON: '',
|
|
45
|
+
projectRoot: '.',
|
|
46
|
+
sortPackages: (a, d) => a.packageName.localeCompare(d.packageName),
|
|
47
|
+
sortSidebar: (a, d) => a.localeCompare(d),
|
|
48
|
+
readmeName: 'README.md',
|
|
49
|
+
readmes: false,
|
|
50
|
+
removeScopes: [],
|
|
51
|
+
routeBasePath: 'api',
|
|
52
|
+
tsconfigName: 'tsconfig.json',
|
|
53
|
+
typedocOptions: {},
|
|
54
|
+
versions: {},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
async function importFile<T>(file: string): Promise<T> {
|
|
58
|
+
const data = await fs.promises.readFile(file, 'utf8');
|
|
59
|
+
|
|
60
|
+
if (file.endsWith('.json')) {
|
|
61
|
+
return JSON.parse(data) as T;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return data as unknown as T;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default function typedocApiPlugin(
|
|
68
|
+
context: LoadContext,
|
|
69
|
+
pluginOptions: DocusaurusPluginTypeDocApiOptions,
|
|
70
|
+
): Plugin<LoadedContent> {
|
|
71
|
+
const options: Required<DocusaurusPluginTypeDocApiOptions> = {
|
|
72
|
+
...DEFAULT_OPTIONS,
|
|
73
|
+
...pluginOptions,
|
|
74
|
+
};
|
|
75
|
+
const {
|
|
76
|
+
banner,
|
|
77
|
+
breadcrumbs,
|
|
78
|
+
changelogs,
|
|
79
|
+
id: pluginId,
|
|
80
|
+
gitRefName,
|
|
81
|
+
minimal,
|
|
82
|
+
projectRoot,
|
|
83
|
+
readmes,
|
|
84
|
+
removeScopes,
|
|
85
|
+
} = options;
|
|
86
|
+
const isDefaultPluginId = pluginId === DEFAULT_PLUGIN_ID;
|
|
87
|
+
const versionsMetadata = readVersionsMetadata(context, options);
|
|
88
|
+
const versionsDocsDir = getVersionedDocsDirPath(context.siteDir, pluginId);
|
|
89
|
+
|
|
90
|
+
// Determine entry points from configs
|
|
91
|
+
const entryPoints: string[] = [];
|
|
92
|
+
const packageConfigs: ResolvedPackageConfig[] = options.packages.map((pkgItem) => {
|
|
93
|
+
const pkgConfig = typeof pkgItem === 'string' ? { path: pkgItem } : pkgItem;
|
|
94
|
+
const entries: Record<string, PackageEntryConfig> = {};
|
|
95
|
+
|
|
96
|
+
if (!pkgConfig.entry || typeof pkgConfig.entry === 'string') {
|
|
97
|
+
entries.index = {
|
|
98
|
+
label: 'Index',
|
|
99
|
+
path: pkgConfig.entry ?? 'src/index.ts',
|
|
100
|
+
};
|
|
101
|
+
} else {
|
|
102
|
+
Object.entries(pkgConfig.entry).forEach(([importPath, entryConfig]) => {
|
|
103
|
+
entries[importPath] =
|
|
104
|
+
typeof entryConfig === 'string'
|
|
105
|
+
? {
|
|
106
|
+
label: 'Index',
|
|
107
|
+
path: entryConfig,
|
|
108
|
+
}
|
|
109
|
+
: entryConfig;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Object.values(entries).forEach((entryConfig) => {
|
|
114
|
+
entryPoints.push(path.join(pkgConfig.path, entryConfig.path));
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
entryPoints: entries,
|
|
119
|
+
packagePath: pkgConfig.path || '.',
|
|
120
|
+
packageSlug: pkgConfig.slug ?? path.basename(pkgConfig.path),
|
|
121
|
+
// Load later on
|
|
122
|
+
packageName: '',
|
|
123
|
+
packageVersion: '',
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
name: 'docusaurus-plugin-typedoc-api',
|
|
129
|
+
|
|
130
|
+
extendCli(cli) {
|
|
131
|
+
const command = isDefaultPluginId ? 'api:version' : `api:version:${pluginId}`;
|
|
132
|
+
const commandDescription = isDefaultPluginId
|
|
133
|
+
? 'Tag a new API version'
|
|
134
|
+
: `Tag a new API version (${pluginId})`;
|
|
135
|
+
|
|
136
|
+
cli
|
|
137
|
+
.command(command)
|
|
138
|
+
.arguments('<version>')
|
|
139
|
+
.description(commandDescription)
|
|
140
|
+
.action(async (version) => {
|
|
141
|
+
const outDir = path.join(versionsDocsDir, `version-${version}`);
|
|
142
|
+
const prefix = isDefaultPluginId ? 'api' : pluginId;
|
|
143
|
+
|
|
144
|
+
console.log(`[${prefix}]:`, 'Generating docs...');
|
|
145
|
+
|
|
146
|
+
await generateJson(
|
|
147
|
+
projectRoot,
|
|
148
|
+
entryPoints,
|
|
149
|
+
path.join(outDir, 'api-typedoc.json'),
|
|
150
|
+
options,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
console.log(`[${prefix}]:`, 'Persisting packages...');
|
|
154
|
+
|
|
155
|
+
// Load info from `package.json`s
|
|
156
|
+
packageConfigs.forEach((cfg) => {
|
|
157
|
+
const { packageJson } = loadPackageJsonAndDocs(
|
|
158
|
+
path.join(options.projectRoot, cfg.packagePath),
|
|
159
|
+
options.packageJsonName,
|
|
160
|
+
options.readmeName,
|
|
161
|
+
options.changelogName,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// eslint-disable-next-line no-param-reassign
|
|
165
|
+
cfg.packageName = packageJson.name;
|
|
166
|
+
// eslint-disable-next-line no-param-reassign
|
|
167
|
+
cfg.packageVersion = packageJson.version;
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
await fs.promises.writeFile(
|
|
171
|
+
path.join(outDir, 'api-packages.json'),
|
|
172
|
+
JSON.stringify(packageConfigs),
|
|
173
|
+
'utf8',
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
console.log(`[${prefix}]:`, `version ${version} created!`);
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
async loadContent() {
|
|
181
|
+
const versionsMetadataList = await versionsMetadata;
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
loadedVersions: await Promise.all(
|
|
185
|
+
versionsMetadataList.map(async (metadata: VersionMetadata) => {
|
|
186
|
+
let packages: PackageReflectionGroup[] = [];
|
|
187
|
+
|
|
188
|
+
// Current data needs to be generated on demand
|
|
189
|
+
if (metadata.versionName === CURRENT_VERSION_NAME) {
|
|
190
|
+
const outFile = path.join(context.generatedFilesDir, `api-typedoc-${pluginId}.json`);
|
|
191
|
+
|
|
192
|
+
if (options.pathToCurrentVersionTypedocJSON) {
|
|
193
|
+
if (!fs.existsSync(context.generatedFilesDir)){
|
|
194
|
+
fs.mkdirSync(context.generatedFilesDir, { recursive: true });
|
|
195
|
+
}
|
|
196
|
+
fs.copyFileSync(options.pathToCurrentVersionTypedocJSON, outFile);
|
|
197
|
+
} else {
|
|
198
|
+
await generateJson(projectRoot, entryPoints, outFile, options);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
packages = flattenAndGroupPackages(
|
|
202
|
+
packageConfigs,
|
|
203
|
+
await importFile(outFile),
|
|
204
|
+
metadata.versionPath,
|
|
205
|
+
options,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
// Versioned data is stored in the file system
|
|
209
|
+
} else {
|
|
210
|
+
const outDir = path.join(versionsDocsDir, `version-${metadata.versionName}`);
|
|
211
|
+
|
|
212
|
+
packages = flattenAndGroupPackages(
|
|
213
|
+
await importFile(path.join(outDir, 'api-packages.json')),
|
|
214
|
+
await importFile(path.join(outDir, 'api-typedoc.json')),
|
|
215
|
+
metadata.versionPath,
|
|
216
|
+
options,
|
|
217
|
+
true,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
packages.sort((a, d) => options.sortPackages(a, d));
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
...metadata,
|
|
225
|
+
packages,
|
|
226
|
+
sidebars: await extractSidebar(
|
|
227
|
+
packages,
|
|
228
|
+
removeScopes,
|
|
229
|
+
changelogs,
|
|
230
|
+
options.sortSidebar,
|
|
231
|
+
),
|
|
232
|
+
};
|
|
233
|
+
}),
|
|
234
|
+
),
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
async contentLoaded({ content, actions }) {
|
|
239
|
+
if (!content) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const { createData, addRoute } = actions;
|
|
244
|
+
const docs: PropVersionDocs = {};
|
|
245
|
+
|
|
246
|
+
// Create an index of versions for quick lookups.
|
|
247
|
+
// This is hacky, but it works, so shrug.
|
|
248
|
+
content.loadedVersions.forEach((loadedVersion) => {
|
|
249
|
+
if (loadedVersion.versionName !== CURRENT_VERSION_NAME) {
|
|
250
|
+
docs[loadedVersion.versionName] = {
|
|
251
|
+
id: loadedVersion.versionPath,
|
|
252
|
+
title: loadedVersion.versionLabel,
|
|
253
|
+
description: loadedVersion.versionLabel,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
await Promise.all(
|
|
259
|
+
content.loadedVersions.map(async (loadedVersion) => {
|
|
260
|
+
const version = loadedVersion.versionName;
|
|
261
|
+
|
|
262
|
+
// Define version metadata for all pages. We need to use the same structure as
|
|
263
|
+
// "docs" so that we can utilize the same React components.
|
|
264
|
+
// https://github.com/facebook/docusaurus/blob/master/packages/docusaurus-plugin-content-docs/src/index.ts#L337
|
|
265
|
+
const versionMetadata = await createData(
|
|
266
|
+
`version-${version}.json`,
|
|
267
|
+
JSON.stringify({
|
|
268
|
+
badge: loadedVersion.versionBadge,
|
|
269
|
+
banner: loadedVersion.versionBanner,
|
|
270
|
+
className: loadedVersion.versionClassName,
|
|
271
|
+
docs,
|
|
272
|
+
docsSidebars: { api: loadedVersion.sidebars },
|
|
273
|
+
isLast: loadedVersion.isLast,
|
|
274
|
+
label: loadedVersion.versionLabel,
|
|
275
|
+
noIndex: false,
|
|
276
|
+
pluginId,
|
|
277
|
+
version: loadedVersion.versionName,
|
|
278
|
+
} as PropVersionMetadata),
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
const packagesData = await createData(
|
|
282
|
+
`packages-${version}.json`,
|
|
283
|
+
JSON.stringify(formatPackagesWithoutHostInfo(loadedVersion.packages)),
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
const optionsContextData: ApiOptions = {
|
|
287
|
+
banner,
|
|
288
|
+
breadcrumbs,
|
|
289
|
+
gitRefName,
|
|
290
|
+
minimal,
|
|
291
|
+
pluginId,
|
|
292
|
+
scopes: removeScopes,
|
|
293
|
+
};
|
|
294
|
+
const optionsData = await createData('options.json', JSON.stringify(optionsContextData));
|
|
295
|
+
|
|
296
|
+
function createRoute(
|
|
297
|
+
info: JSONOutput.Reflection,
|
|
298
|
+
modules?: Record<string, string>,
|
|
299
|
+
): RouteConfig {
|
|
300
|
+
return {
|
|
301
|
+
path: info.permalink,
|
|
302
|
+
exact: true,
|
|
303
|
+
component: path.join(__dirname, './components/ApiItem.js'),
|
|
304
|
+
modules,
|
|
305
|
+
sidebar: 'api',
|
|
306
|
+
// Map the ID here instead of creating a JSON data file,
|
|
307
|
+
// otherwise this will create thousands of files!
|
|
308
|
+
id: info.id,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const routes: RouteConfig[] = [];
|
|
313
|
+
|
|
314
|
+
loadedVersion.packages.forEach((pkg) => {
|
|
315
|
+
pkg.entryPoints.forEach((entry) => {
|
|
316
|
+
const children =
|
|
317
|
+
entry.reflection.children?.filter((child) => !child.permalink?.includes('#')) ?? [];
|
|
318
|
+
|
|
319
|
+
// Map a route for every declaration in the package (the exported APIs)
|
|
320
|
+
const subRoutes = children.map((child) => createRoute(child));
|
|
321
|
+
|
|
322
|
+
// Map a top-level package route, otherwise `DocPage` shows a page not found
|
|
323
|
+
subRoutes.push(
|
|
324
|
+
createRoute(
|
|
325
|
+
entry.reflection,
|
|
326
|
+
entry.index && readmes && pkg.readmePath ? { readme: pkg.readmePath } : undefined,
|
|
327
|
+
),
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
if (entry.index && changelogs && pkg.changelogPath) {
|
|
331
|
+
subRoutes.push({
|
|
332
|
+
path: normalizeUrl([entry.reflection.permalink, 'changelog']),
|
|
333
|
+
exact: true,
|
|
334
|
+
component: path.join(__dirname, './components/ApiChangelog.js'),
|
|
335
|
+
modules: { changelog: pkg.changelogPath },
|
|
336
|
+
sidebar: 'api',
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
routes.push(...subRoutes);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const indexPermalink = normalizeUrl([loadedVersion.versionPath]);
|
|
345
|
+
|
|
346
|
+
if (loadedVersion.packages.length > 1) {
|
|
347
|
+
// Only write out the ApiIndex only when we have multiple packages
|
|
348
|
+
// otherwise we will have 2 top-level entries in the route entries
|
|
349
|
+
routes.push({
|
|
350
|
+
path: indexPermalink,
|
|
351
|
+
exact: true,
|
|
352
|
+
component: path.join(__dirname, './components/ApiIndex.js'),
|
|
353
|
+
modules: {
|
|
354
|
+
options: optionsData,
|
|
355
|
+
packages: packagesData,
|
|
356
|
+
versionMetadata,
|
|
357
|
+
},
|
|
358
|
+
sidebar: 'api',
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
addRoute({
|
|
363
|
+
path: indexPermalink,
|
|
364
|
+
exact: false,
|
|
365
|
+
component: path.join(__dirname, './components/ApiPage.js'),
|
|
366
|
+
routes,
|
|
367
|
+
modules: {
|
|
368
|
+
options: optionsData,
|
|
369
|
+
packages: packagesData,
|
|
370
|
+
versionMetadata,
|
|
371
|
+
},
|
|
372
|
+
priority: loadedVersion.routePriority,
|
|
373
|
+
});
|
|
374
|
+
}),
|
|
375
|
+
);
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
configureWebpack(config, isServer, utils) {
|
|
379
|
+
if (!readmes && !changelogs) {
|
|
380
|
+
return {};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Whitelist the folders that this webpack rule applies to, otherwise we collide with the native
|
|
384
|
+
// docs/blog plugins. We need to include the specific files only, as in polyrepo mode, the `cfg.packagePath`
|
|
385
|
+
// can be project root (where the regular docs are too).
|
|
386
|
+
const include = packageConfigs.flatMap((cfg) => [
|
|
387
|
+
path.join(options.projectRoot, cfg.packagePath, options.readmeName),
|
|
388
|
+
path.join(options.projectRoot, cfg.packagePath, options.changelogName),
|
|
389
|
+
]);
|
|
390
|
+
|
|
391
|
+
return {
|
|
392
|
+
module: {
|
|
393
|
+
rules: [
|
|
394
|
+
{
|
|
395
|
+
test: /\.mdx?$/,
|
|
396
|
+
include,
|
|
397
|
+
use: [
|
|
398
|
+
utils.getJSLoader({ isServer }),
|
|
399
|
+
{
|
|
400
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
401
|
+
options: {
|
|
402
|
+
admonitions: true,
|
|
403
|
+
staticDir: path.join(context.siteDir, 'static'),
|
|
404
|
+
// Since this isnt a doc/blog page, we can get
|
|
405
|
+
// away with it being a partial!
|
|
406
|
+
isMDXPartial: () => true,
|
|
407
|
+
markdownConfig: context.siteConfig.markdown,
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
loader: path.resolve(__dirname, './markdownLoader.js'),
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
},
|
|
415
|
+
],
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
},
|
|
419
|
+
};
|
|
420
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Callback = (error: Error | null, result: string) => unknown;
|
|
2
|
+
|
|
3
|
+
export default function markdownLoader(this: { async: () => Callback }, markdown: string) {
|
|
4
|
+
const resolve = this.async();
|
|
5
|
+
|
|
6
|
+
// Remove the #/h1 titles as we handle it within our templates
|
|
7
|
+
const markdownWithoutTitle = markdown.replace(/^#\s+([^\n]+)/i, '');
|
|
8
|
+
|
|
9
|
+
return resolve?.(null, markdownWithoutTitle);
|
|
10
|
+
}
|