-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathdocusaurus.config.js
More file actions
359 lines (332 loc) · 11.4 KB
/
Copy pathdocusaurus.config.js
File metadata and controls
359 lines (332 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
// @ts-check
// `@type` JSDoc annotations allow editor autocompletion and type checking
// (when paired with `@ts-check`).
// There are various equivalent ways to declare your Docusaurus config.
// See: https://docusaurus.io/docs/api/docusaurus-config
import { readFileSync, existsSync } from 'fs';
import { resolve } from 'path';
import { themes as prismThemes } from 'prism-react-renderer';
import { generateDocusaurusPlugins, generateNavbarDropdowns, PRODUCTS, versionToUrl, getDefaultVersion, getLatestVersionUrlMap } from './src/config/products.js';
// Strip TypeScript syntax from a generated sidebar.ts and return its apisidebar array.
// Returns [] if the file doesn't exist yet (before gen-api-docs has run).
// Runs in Node.js only (docusaurus.config.js is never bundled for the browser).
function loadApiSidebarItems(sidebarTsPath) {
if (!existsSync(sidebarTsPath)) return [];
let content = readFileSync(sidebarTsPath, 'utf8');
content = content
.replace(/^import type[^\n]*\n/m, '')
.replace(/const sidebar:\s+\w+\s*=\s*\{/, 'const sidebar = {')
.replace(/export default sidebar\.apisidebar;/, 'return sidebar.apisidebar;');
return (new Function(content))();
}
const apiSidebars = {};
PRODUCTS.forEach(product => {
product.versions.forEach(version => {
if (version.apiSidebarPath) {
apiSidebars[version.apiSidebarPath] = loadApiSidebarItems(resolve(version.apiSidebarPath));
}
});
});
const latestVersionMap = getLatestVersionUrlMap();
/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'Netwrix Product Documentation',
tagline: 'Documentation for Netwrix Products',
favicon: 'branding/favicon.ico',
// Set the production url of your site here
// Use environment variable for dynamic URL configuration
projectName: 'docs',
url: process.env.APP_EXTERNAL_URL || 'http://localhost:4500',
// Set the /<baseUrl>/ pathname under which your site is served
baseUrl: '/',
// throw on anything that is not configured correctly
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'throw',
onBrokenAnchors: 'throw',
// Set Mermaid
markdown: {
mermaid: true,
// Strip trailing periods from title/sidebar_label in generated API operation pages.
// The OpenAPI summaries often end with a period; Docusaurus uses title as the
// prev/next pagination label, so this cleans up navigation text site-wide.
parseFrontMatter: async (params) => {
const result = await params.defaultParseFrontMatter(params);
if (params.filePath.includes('/api/reference/')) {
if (result.frontMatter.title) {
result.frontMatter.title = result.frontMatter.title.replace(/\.$/, '');
}
if (result.frontMatter.sidebar_label) {
result.frontMatter.sidebar_label = result.frontMatter.sidebar_label.replace(/\.$/, '');
}
}
return result;
},
},
themes: ['@docusaurus/theme-mermaid', 'docusaurus-theme-openapi-docs'],
// Performance optimizations with Docusaurus Faster
future: {
faster: {
swcJsLoader: true,
swcJsMinimizer: true,
swcHtmlMinimizer: true,
lightningCssMinimizer: true,
rspackBundler: true,
rspackPersistentCache: true,
mdxCrossCompilerCache: true,
ssgWorkerThreads: false,
},
v4: {
removeLegacyPostBuildHeadAttribute: true,
},
},
// Even if you don't use internationalization, you can use this field to set
// useful metadata like html lang. For example, if your site is Chinese, you
// may want to replace "en" with "zh-Hans".
i18n: {
defaultLocale: 'en',
locales: ['en'],
},
presets: [
[
'classic',
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: false,
blog: false,
theme: {
customCss: './src/css/custom.css',
},
}),
],
],
plugins: [
// Disable scope hoisting to prevent O(n²) hang on large module graphs
function customRspackPlugin() {
return {
name: 'custom-rspack-config',
configureWebpack(_config, isServer) {
if (!isServer) {
return { optimization: { concatenateModules: false } };
}
return {};
},
};
},
// Google Analytics
[
'@docusaurus/plugin-google-gtag',
{
trackingID: 'G-FZPWSDMTEX',
anonymizeIP: true,
},
],
// Client-side redirects - redirect base product URLs to latest version
[
'@docusaurus/plugin-client-redirects',
{
redirects: PRODUCTS.filter(product => {
// Only create redirects for products with multiple versions (not just 'current')
return !(product.versions.length === 1 && product.versions[0].version === 'current');
}).map(product => {
const latestVersion = getDefaultVersion(product);
const latestVersionUrl = versionToUrl(latestVersion.version);
// Use explicit customRoutePath if specified (e.g., for multi-versioned products with 'current')
// Otherwise use standard path generation
const targetPath = latestVersion.customRoutePath
? latestVersion.customRoutePath
: `${product.path}/${latestVersionUrl}`;
return {
from: `/${product.path}`,
to: `/${targetPath}`,
};
}),
createRedirects(existingPath) {
for (const [productId, latestUrlVersion] of Object.entries(latestVersionMap)) {
const versionedPrefix = `/docs/${productId}/${latestUrlVersion}/`;
if (existingPath.startsWith(versionedPrefix)) {
const rest = existingPath.slice(versionedPrefix.length).replace(/\/$/, '');
if (!rest) return undefined;
return [`/docs/${productId}/${rest}`];
}
}
return undefined;
},
},
],
// Generate all product documentation plugins from centralized configuration
...generateDocusaurusPlugins({ apiSidebars }).map(([pluginName, config]) => [
pluginName,
{
...config,
sidebarPath: config.sidebarPath && typeof config.sidebarPath === 'string'
? require.resolve(config.sidebarPath)
: config.sidebarPath,
},
]),
[
'docusaurus-plugin-openapi-docs',
{
id: 'openapi',
docsPluginId: 'changetracker8_1',
config: {
'changetracker-hub': {
specPath: 'static/openapi/changetracker-hub-8.1.yaml',
outputDir: 'docs/changetracker/8.1/api/reference',
sidebarOptions: {
groupPathsBy: 'tag',
categoryLinkSource: 'tag',
sidebarCollapsed: true,
},
downloadUrl: '/openapi/changetracker-hub-8.1.yaml',
version: '8.1',
label: 'ChangeTracker Hub 8.1 API',
baseUrl: '/docs/changetracker/8_1/api/reference/',
},
},
},
],
[
'docusaurus-plugin-openapi-docs',
{
id: 'openapi-8-2',
docsPluginId: 'changetracker8_2',
config: {
'changetracker-hub-8-2': {
specPath: 'static/openapi/changetracker-hub-8.2.yaml',
outputDir: 'docs/changetracker/8.2/api/reference',
sidebarOptions: {
groupPathsBy: 'tag',
categoryLinkSource: 'tag',
sidebarCollapsed: true,
},
downloadUrl: '/openapi/changetracker-hub-8.2.yaml',
version: '8.2',
label: 'ChangeTracker Hub 8.2 API',
baseUrl: '/docs/changetracker/8_2/api/reference/',
},
},
},
],
],
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
// MermaidJS Config
mermaid: {
theme: {
light: 'neutral',
dark: 'dark',
},
options: {
look: 'handDrawn',
handDrawnSeed: 1,
},
},
// Replace with your project's social card
image: 'img/Logo_RGB.svg',
docs: {
sidebar: {
hideable: true,
autoCollapseCategories: true,
},
},
algolia: {
// Your Algolia credentials
appId: 'KPMSCF6G6J',
apiKey: '1b20f30f13a874cd46f9d5c30b01d99c', // Use the search-only API key, not the admin key
indexName: 'Production Docs',
// Enable contextual search (already great that you have product/version meta tags!)
contextualSearch: true,
// Search parameters for better results
searchParameters: {
// Facet filters can be combined with contextual search
// These will be merged with the automatic facets from contextual search
facetFilters: [
// Add any default filters here if needed
// e.g., 'type:content' to exclude headers-only results
],
// Attributes to snippet in search results
attributesToSnippet: ['content:20'],
// Highlight search terms in results
highlightPreTag: '<mark>',
highlightPostTag: '</mark>',
// Number of results per page
hitsPerPage: 20,
// Add these for better relevance
distinct: true,
clickAnalytics: true,
analytics: true,
},
// Enable search insights for better analytics
insights: true,
// Path for the search page (enables full-page search experience)
searchPagePath: 'search',
// Placeholder text for the search box
placeholder: 'Search the Netwrix docs...',
// Transform items before displaying (optional)
transformItems: (items) => {
return items.map((item) => {
// Add product badges or modify display as needed
return {
...item,
// Example: Add custom badges based on product
_highlightResult: {
...item._highlightResult,
// Customize highlighted results if needed
},
};
});
},
// Replace paths if you're using different deployments
// replaceSearchResultPathname: {
// from: '/docs/',
// to: '/',
// },
},
navbar: {
logo: {
alt: 'Netwrix Logo',
src: 'branding/Netwrix_Logo_Dark.svg',
srcDark: 'branding/logo-light.svg',
href: '/',
},
items: [
// Generate category dropdowns from centralized product configuration
...generateNavbarDropdowns(),
{
href: 'https://community.netwrix.com',
label: 'Community',
position: 'right',
},
{
href: 'https://www.netwrix.com/support.html',
label: 'Support',
position: 'right',
},
{
href: 'http://github.com/netwrix',
label: 'GitHub',
position: 'right',
},
],
},
prism: {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
additionalLanguages: ['powershell', 'bash'],
},
}),
// Add preconnect for better search performance
headTags: [
{
tagName: 'link',
attributes: {
rel: 'preconnect',
href: 'https://KPMSCF6G6J-dsn.algolia.net',
crossorigin: 'anonymous',
},
},
],
stylesheets: ['https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap'],
};
export default config;