-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocusaurus.config.js
More file actions
386 lines (353 loc) · 11.9 KB
/
docusaurus.config.js
File metadata and controls
386 lines (353 loc) · 11.9 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
const path = require('path');
const fs = require('fs');
const AT_NOTATION_KEYS = {
short: 'Short',
type: 'Type',
descr: 'Descr',
changelog: 'Changelog',
signature: 'Signature',
params: 'Params',
returns: 'Returns',
values: 'Values'
};
const COMPONENTS_PATH = '@site/src/components';
// let components = { Disqus: "Disqus" };
let components = {};
let metaDescription = '';
const wrapDataWithComponent = (data, componentName) => {
return componentName ? `\n<${componentName}>\n${data}\n\n</${componentName}>\n\n` : data;
}
const onAtNotationMatch = (data, { key }) => {
const componentName = AT_NOTATION_KEYS[key];
if (componentName) {
components[componentName] = componentName;
}
switch(key) {
case 'default':
return `<strong>Default value: </strong> ${data}`;
case 'example':
return `**Example**\n~~~js\n${data.replace(/^(?:\n*)([^]+?)(?:\n*)$/g, '$1')}\n~~~`;
case 'metadescr':
metaDescription = data.replace(/^(?:\n*)(.+)(?:\n|.)*/, '$1');
return '';
// TODO: remove later
case 'relatedsample':
return data;
default:
return componentName
? wrapDataWithComponent(data, componentName)
: data;
}
};
const onAtNotationFunctionMatch = (data, { key, fullMatch, dir }) => {
if (data.indexOf('.md') !== -1 || data.indexOf('.mdx') !== -1 || data.indexOf('.') === -1) {
const result = readFileFromPath(dir, data);
return result ? /@short: (.*)/g.exec(result)[1] : fullMatch;
}
return fullMatch;
}
const onBraceNotationMatch = (data, { key, fullMatch }) => {
switch(key) {
case 'note':
return `:::note\n${data}\n:::`;
case 'pronote':
return `:::tip Pro version only\n${data}\n:::`;
case 'editor':
return data;
default:
return fullMatch;
}
};
const readFile = (workingDir, filePath) => {
workingDir = workingDir.replace(/\\/g, '/');
filePath = filePath.replace(/\\/g, '/');
let finalPath = workingDir + '/' + filePath;
if (finalPath.indexOf('.') === -1) {
finalPath += !fs.existsSync(finalPath + '.md') ? '.mdx' : '.md';
}
if (!fs.existsSync(finalPath)) {
const clippedFilePath = filePath.split('/');
clippedFilePath.shift();
if (!clippedFilePath.length) {
return false;
}
return readFile(workingDir, clippedFilePath.join('/'));
}
return fs.readFileSync(path.normalize(finalPath), 'utf8');
};
const getContentRelativePath = (dir, filePath) => {
// Already a docs-root-relative path (no ./ or ../ prefix) — return as-is
if (!filePath.startsWith('.')) {
return filePath;
}
const absolutePath = path.resolve(dir, filePath).replace(/\\/g, '/');
const i18nDir = path.join(__dirname, 'i18n').replace(/\\/g, '/');
const docsDir = path.join(__dirname, 'docs').replace(/\\/g, '/');
if (absolutePath.startsWith(i18nDir + '/')) {
const currentIndex = absolutePath.indexOf('/current/');
if (currentIndex !== -1) {
return absolutePath.substring(currentIndex + '/current/'.length);
}
}
if (absolutePath.startsWith(docsDir + '/')) {
return absolutePath.substring(docsDir.length + 1);
}
return filePath;
};
// Returns the content root for i18n files (i18n/XX/.../current), or null for docs/ files.
const getLocaleContentRoot = (dir) => {
const normalizedDir = dir.replace(/\\/g, '/');
const currentIndex = normalizedDir.indexOf('/current/');
if (currentIndex !== -1 && normalizedDir.includes('/i18n/')) {
return normalizedDir.substring(0, currentIndex + '/current'.length);
}
return null;
};
// Reads a file by path, supporting both relative (../foo.md) and docs-root-relative (api/foo.md) formats.
// For i18n files, tries the localized version first before falling back to docs/.
const readFileFromPath = (dir, filePath) => {
const result = readFile(dir, filePath);
if (result) return result;
// If path doesn't start with . it may be docs-root-relative
if (!filePath.startsWith('.')) {
// For i18n files: try the locale's content root first (localized version)
const localeRoot = getLocaleContentRoot(dir);
if (localeRoot) {
const localeResult = readFile(localeRoot, filePath);
if (localeResult) return localeResult;
}
// Fall back to docs/ (English)
const docsDir = path.join(__dirname, 'docs').replace(/\\/g, '/');
return readFile(docsDir, filePath);
}
return false;
};
const onEmptyLinkMatch = (data, { key, fullMatch, dir }) => {
const filePath = fullMatch.substring(fullMatch.indexOf('(') + 1, fullMatch.length - 1);
if (filePath.indexOf('.md') !== -1 || filePath.indexOf('.mdx') !== -1 || filePath.indexOf('.') === -1) {
const fileData = readFileFromPath(dir, filePath);
if (!fileData) return fullMatch;
const label = /.*sidebar_label: (.+)/g.exec(fileData)[1];
const normalizedPath = getContentRelativePath(dir, filePath);
return `[${label}](${normalizedPath})`;
}
return fullMatch;
};
const onAfterDataTransformation = (data) => {
const allAvailableComponents = Object.values(components);
let transformedData = data;
if (allAvailableComponents.length !== 0) {
const imports = `import { ${allAvailableComponents.join(', ')} } from '${COMPONENTS_PATH}';\n\n`;
const isTitles = /---((?:\r?\n|\r)|.)+?---/.test(transformedData);
transformedData = isTitles
? (transformedData.replace(/^(---((?:\s*\n)|.)+?---)/, `$1\n\n${imports}`))
: imports + transformedData;
}
if (metaDescription) {
transformedData = transformedData.replace(/^(---\s*\n)((?:\n|.)+?)(---\s*?\n*)/, (fullMatch, groupA, groupB, groupC) => {
const isDocusaurusDescriptionExist = /^description: *.*\n/m.test(fullMatch);
if (!isDocusaurusDescriptionExist) {
return `${groupA}description: ${metaDescription}\n${groupB}${groupC}`;
}
return fullMatch;
});
}
// components = { Disqus: "Disqus" };
metaDescription = '';
return transformedData;
};
/* !!! */
/** @type {import('@docusaurus/types').Config} */
const config = {
noIndex: false,
title: 'DHTMLX RichText Documentation',
tagline: 'DHTMLX RichText Documentation',
url: 'https://docs.dhtmlx.com',
baseUrl: '/richtext/',
onBrokenLinks: 'warn',
// onBrokenMarkdownLinks: 'warn', // deprecated in v3.9.1
onBrokenAnchors: 'warn',
favicon: 'img/favicon.ico',
organizationName: 'DHTMLX',
projectName: 'docs-richtext',
trailingSlash: true,
markdown: {
hooks: {
onBrokenMarkdownLinks: 'warn',
}
},
/*
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
sidebarPath: require.resolve('./sidebars.js'),
// Please change this to your repo.
editUrl: 'https://github.com/DHTMLX/docs-richtext/edit/master/',
routeBasePath: '/',
},
theme: {
customCss: require.resolve('./src/css/custom.css')
}
}
]
],
*/
scripts:[
{
src: 'https://dhtmlx.com/gtag/docs.js',
async: true
}
],
stylesheets: [
{ href:'https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@3.0.1/dist/cookieconsent.css' },
],
presets: [
[
'@docusaurus/preset-classic',
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
sidebarPath: require.resolve('./sidebars.js'),
editUrl: 'https://github.com/DHTMLX/docs-richtext/edit/master/',
routeBasePath: '/'
},
theme: {
customCss: require.resolve('./src/css/custom.css')
},
sitemap: {
changefreq: 'daily',
priority: 0.5
}
})
]
],
plugins:[
'docusaurus-plugin-sass',
[
path.resolve(__dirname, './plugins/dhx-md-data-transformer-plugin'),
{
onBraceNotationMatch,
onAtNotationMatch,
onAtNotationFunctionMatch,
onEmptyLinkMatch,
onAfterDataTransformation
}
]
],
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
algolia: {
// This is a read-only, search-only key served directly by the front-end, managed by Algolia via their
// free DocSearch program. The key is not sensitive. See https://docsearch.algolia.com/ for more details.
appId: 'PJG180YLDH',
apiKey: '83de34cb4df8e71e814b989e48259185',
indexName: 'richtext',
contextualSearch: true,
},
navbar: {
title: 'JavaScript RichText Documentation',
logo: {
alt: 'DHTMLX RichText Documentation',
src: 'img/dhtmlx_logo.svg',
href: 'https://docs.dhtmlx.com/'
},
items: [
{
label: 'Examples',
href: 'https://snippet.dhtmlx.com/t55alxiy?tag=richtext',
position: 'right'
},
{
label: 'Forum',
href: 'https://forum.dhtmlx.com/c/richtext/',
position: 'right'
},
{
label: 'Support',
href: 'https://dhtmlx.com/docs/technical-support.shtml',
position: 'right'
},
{
label: 'Download',
href: 'https://dhtmlx.com/docs/products/dhtmlxRichText/download.shtml',
position: 'right'
}
]
},
footer: {
"style": "dark",
"links": [
{
"title": "Development center",
"items": [
{
label: 'Download RichText',
href: 'https://dhtmlx.com/docs/products/dhtmlxRichText/download.shtml',
position: 'right'
},
{
label: 'Examples',
href: 'https://snippet.dhtmlx.com/t55alxiy?tag=richtext',
position: 'right'
},
{
label: 'Blog',
href: 'https://dhtmlx.com/blog/tag/richtext/'
},
{
label: 'Forum',
href: 'https://forum.dhtmlx.com/c/richtext/',
position: 'right'
}
]
},
{
"title": "Community",
"items": [
{
label: 'GitHub',
href: 'https://github.com/DHTMLX'
},
{
label: 'Youtube',
href: 'https://www.youtube.com/user/dhtmlx'
},
{
label: 'Facebook',
href: 'https://www.facebook.com/dhtmlx'
},
{
label: 'Twitter',
href: 'https://twitter.com/dhtmlx'
},
{
label: 'Linkedin',
href: 'https://www.linkedin.com/groups/3345009/'
}
]
},
{
"title": "Company",
"items": [
{
label: 'About us',
href: 'https://dhtmlx.com/docs/company.shtml'
},
{
label: 'Contact us',
href: 'https://dhtmlx.com/docs/contact.shtml'
},
{
label: 'Licensing',
href: 'https://dhtmlx.com/docs/products/dhtmlxRichText/#editions-licenses'
}
]
}
]
}
})
};
module.exports = config;