-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocusaurus.config.js
More file actions
457 lines (426 loc) · 13 KB
/
docusaurus.config.js
File metadata and controls
457 lines (426 loc) · 13 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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
const { themes } = require('prism-react-renderer');
const { default: remarkGfm } = require('remark-gfm');
const lightTheme = themes.github;
const darkTheme = themes.palenight;
const isProduction = process.env.GITHUB_REPOSITORY_OWNER === '4d';
const router = process.env.DOCUSAURUS_ROUTER
const isStatic = process.env.DOCUSAURUS_ROUTER === "hash"
const language = process.env.DOCUSAURUS_LANGUAGE ?? "en"
const LANGUAGE_TO_BUILD = process.env.LANGUAGE_TO_BUILD ?? "en"
const BASE_URL_LANGUAGE = LANGUAGE_TO_BUILD !== "en" ? `${LANGUAGE_TO_BUILD}/` : "";
console.log("Language ", BASE_URL_LANGUAGE)
const locales = isStatic ? [language] : ['en', 'fr', 'es', 'ja', 'pt']
const localeConfigs = isStatic ? {} : {
en: {
label: "English",
baseUrl: "/docs/",
},
fr: {
label: "Français",
baseUrl: "/docs/fr/",
},
es: {
label: "Español",
baseUrl: "/docs/es/",
},
ja: {
label: "日本語",
baseUrl: "/docs/ja/",
},
pt: {
label: "Português",
baseUrl: "/docs/pt/",
},
}
function getCliLocaleFromArgv() {
// supporte: "--locale fr" ou "--locale=fr"
const i = process.argv.indexOf('--locale');
if (i > -1 && process.argv[i + 1] && !process.argv[i + 1].startsWith('--')) {
return process.argv[i + 1];
}
const eq = process.argv.find((a) => a.startsWith('--locale='));
if (eq) return eq.split('=')[1];
return undefined;
}
// docusaurus.config.js
const fs = require('fs');
const path = require('path');
// 1) Collator FR (tri “dictionnaire” : accents pris en compte)
const collators = {};
function getCollator(locale) {
const loc = locale || 'en';
if (!collators[loc]) {
// Sensibilité 'accent' => 'é' > 'e' (contraire de 'base' qui les considère égaux)
collators[loc] = new Intl.Collator(loc, {
usage: 'sort',
sensitivity: 'accent',
ignorePunctuation: false,
numeric: true,
});
// Log de diag : vérifie la locale réellement résolue par ICU
const resolved = collators[loc].resolvedOptions().locale;
console.log(`[sidebar-sort] requested=${loc} resolved=${resolved}`);
}
return collators[loc];
}
// 2) Charge le catalogue i18n des sidebars pour la locale
function loadSidebarTranslations(locale) {
if (!locale || typeof locale !== 'string') return {};
const base = path.join(__dirname, 'i18n', locale, 'docusaurus-plugin-content-docs');
const candidates = [
path.join(base, 'current.json'),
path.join(base, 'current', 'current.json'),
path.join(base, 'default', 'current.json'),
path.join(__dirname, 'i18n', locale, 'code.json'),
];
for (const file of candidates) {
if (fs.existsSync(file)) {
try {
return JSON.parse(fs.readFileSync(file, 'utf8'));
} catch { /* ignore */ }
}
}
return {};
}
// 3) Déduit le nom de la sidebar (docs/mainSidebar/…)
// à partir des clés présentes dans le JSON de traduction.
function guessSidebarNameFromTranslations(translations) {
for (const k of Object.keys(translations || {})) {
const m = /^sidebar\.([^.]+)\.category\./.exec(k);
if (m) return m[1];
}
return 'docs';
}
// 4) Récupère la traduction d’un label de catégorie
function getTranslatedCategoryLabel(labelSource, sidebarName, translations) {
const src = String(labelSource || '').normalize('NFC').trim();
if (!src) return '';
const directKey = `sidebar.${sidebarName}.category.${src}`;
const direct = translations[directKey]?.message;
if (direct && direct.trim()) return direct;
// Tolérance : si le nom de sidebar diffère, on scanne
for (const [k, v] of Object.entries(translations)) {
const m = /^sidebar\.([^.]+)\.category\.(.+)$/.exec(k);
if (!m) continue;
const keyLabel = String(m[2] || '').normalize('NFC').trim();
if (keyLabel.localeCompare(src, undefined, {sensitivity: 'accent'}) === 0) {
const msg = v?.message;
if (msg && msg.trim()) return msg;
}
}
// Pas de traduction → fallback source
return src;
}
// 5) Clé de tri
function sortKey(item, helpers) {
const { translations, sidebarName } = helpers;
if (item.type === 'category') {
return getTranslatedCategoryLabel(item.label, sidebarName, translations);
}
return item.label || item.title || item.id || '';
}
// 6) Tri des catégories racine.
function sortRec(items, helpers) {
const collator = getCollator(helpers.locale);
const withChildrenSorted = items.map((it) => {
//if (it.type === 'category' && Array.isArray(it.items)) {
if (it.type === 'category' && Array.isArray(it.items)) {
const translated = getTranslatedCategoryLabel(
it.label,
helpers.sidebarName,
helpers.translations
);
return { ...it, label: translated, items: sortRec(it.items, helpers) };
}
return it;
});
return withChildrenSorted.sort((a, b) => collator.compare(sortKey(a, helpers), sortKey(b, helpers)));
}
module.exports = {
title: "4D Docs",
tagline: "Documentation for 4D developers",
baseUrl: isStatic ? "/" : "/docs/" + BASE_URL_LANGUAGE,
//url: "https://4d.github.io/",
url: "https://developer.4d.com/",
organizationName: "4D",
projectName: "docs",
favicon: "img/favicon/4d.gif",
trailingSlash: false,
onBrokenLinks: "ignore",
noIndex: isProduction ? false : true,
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
remarkPlugins: [remarkGfm],
// Docs folder path relative to website dir.
path: 'docs',
routeBasePath: '/',
//editUrl: 'https://github.com/4D/docs/edit/main/',
editUrl: function edit(info) {
// const lang = info.locale;
// const version = info.version;
// const permalink = info.permalink;
const title = `Comment on ${info.docPath} (${info.version})`;
const body = `Please enter your comment:`;
return `https://github.com/4d/docs/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`
},
sidebarPath: require.resolve('./sidebars.js'),
sidebarItemsGenerator: async function (args) {
const { defaultSidebarItemsGenerator, item, locale } = args;
// 1) Laisser Docusaurus générer l'arbre standard
const items = await defaultSidebarItemsGenerator(args);
// 2) Cibler uniquement l'autogenerated "language"
if (item?.type === 'autogenerated' && item.dirName === 'language-legacy') {
// 🔒 Locale robuste : jamais undefined
// ordre de priorité :
// - locale passée par Docusaurus
// - locale extraite du CLI (--locale fr)
// - locale de la version (si dispo)
// - fallback explicite 'fr-FR' si tu veux forcer FR
// - sinon 'en'
const detectedLocale =
locale ||
getCliLocaleFromArgv() ||
args.version?.versionMetadata?.locale ||
// 👉 si tu veux forcer le tri FR en dev et en build, dé-commente:
// 'fr-FR' ||
'en';
// Optionnel : log de diag
const collator = new Intl.Collator(detectedLocale, {
usage: 'sort',
sensitivity: 'accent',
ignorePunctuation: false,
numeric: true,
});
const resolved = collator.resolvedOptions().locale;
console.log(`[sidebar-sort] requested=${detectedLocale} resolved=${resolved}`);
// 3) Charger le catalogue i18n pour la locale détectée
const translations = loadSidebarTranslations(detectedLocale); // (ta fonction existante)
const sidebarName = guessSidebarNameFromTranslations(translations); // (ta fonction existante)
const helpers = { locale: detectedLocale, sidebarName, translations };
// 4) Appliquer le tri (catégories + docs internes)
return sortRec(items, helpers); // (ta fonction existante)
}
return items;
},
versions: {
'21-R2': {
label: '21 R2 BETA',
banner: 'none',
},
'21': {
label: '21',
banner: 'none',
},
'20': {
label: '20',
banner: 'none',
},
'19': {
label: '19',
banner: 'none',
},
'18': {
label: '18',
banner: 'none',
},
},
includeCurrentVersion: isProduction ? false : true, // false for prod only
},
blog: false,
theme: {
customCss: [require.resolve('./src/css/customTheme.css')],
},
},
],
],
future: {
experimental_faster: {
swcJsLoader: true,
swcJsMinimizer: true,
swcHtmlMinimizer: true,
lightningCssMinimizer: true,
rspackBundler: true,
mdxCrossCompilerCache: true,
},
experimental_router: router,
},
i18n: {
defaultLocale: language,
locales: locales,
localeConfigs: localeConfigs,
},
plugins: [
[
"@docusaurus/plugin-client-redirects",
{
"fromExtensions": ["html"],
createRedirects(existingPath) {
if (existingPath.includes('/docs')) {
// Redirect from /docs/en to /docs
return [
existingPath.replace('/docs', '/docs/en'),
];
}
return undefined; // Return a falsy value: no redirect created
},
},
],
],
themeConfig: {
algolia: {
apiKey: '5f22ebbb9382abafeadc3e86ca47d4af',
appId: 'OJ04C0M3CU',
indexName: '4d',
//contextualSearch: false
//added for command search
searchParameters: {
advancedSyntax: true,
queryType: 'prefixAll', // Priorise la chaine entiere
removeWordsIfNoResults: 'allOptional', // Recherche les elements individuels si aucun resultat
},
// end
},
docs: {
sidebar: {
hideable: true,
},
},
prism: {
theme: lightTheme,
darkTheme: darkTheme,
additionalLanguages: ['json'],
},
navbar: {
title: "4D Documentation",
hideOnScroll: true,
logo: {
alt: "4D Logo",
src: "img/logohome.png",
},
items: [{
type: 'docsVersionDropdown',
position: 'right',
}, {
type: 'localeDropdown',
position: 'right',
},
],
},
//"image": "../assets/en/logohome.png",
footer: {
style: 'dark',
links: [
{
title: 'Community',
items: [
{
label: '4D Blog',
to: 'https://blog.4d.com',
},
{
label: '4D Forum',
to: 'https://discuss.4d.com',
},
{
label: 'Facebook',
to: 'https://facebook.com/4Dsoftware',
},
{
label: 'X',
to: 'https://x.com/4Dsoftware',
},
{
label: 'Youtube',
to: 'https://youtube.com/user/4Dsoftware',
},
{
label: 'Github',
to: 'https://github.com/4D',
},
],
},
{
title: 'Support',
items: [
{
label: 'Documentation download',
to: 'https://github.com/4d/docs/releases/tag/latest',
},
{
label: 'Learn 4D',
to: 'https://learn.4d.com',
},
{
label: '4D Doc Center (legacy documentation web site) ',
to: 'https://doc.4d.com',
},
{
label: 'Knowledgebase',
to: 'https://kb.4d.com',
},
{
label: 'Downloads',
to: 'https://us.4d.com/product-download',
},
{
label: 'Resources',
to: 'https://us.4d.com/resources',
},
{
label: 'Get Support',
to: 'https://us.4d.com/4d-technical-support',
}
],
},
{
title: 'Company',
items: [
{
label: 'About 4D',
to: 'https://us.4d.com/about-us',
},
{
label: 'Contact us',
to: 'https://us.4d.com/contact-us',
},
{
label: '4D around the world',
to: 'https://us.4d.com/4d-around-the-world',
},
{
label: 'Careers',
to: 'https://us.4d.com/Careers',
},
],
},
],
"copyright": "© 2026 4D SAS - All rights reserved",
},
},
markdown: {
format: 'detect',
mermaid: true,
mdx1Compat: {
comments: true,
admonitions: true,
headingIds: true,
},
anchors: {
maintainCase: false,
},
hooks: {
onBrokenMarkdownLinks: 'warn',
onBrokenMarkdownImages: 'ignore', //tempo for test with subfolders
},
},
themes: ['@docusaurus/theme-mermaid'],
scripts: [
{
src: 'https://kit.fontawesome.com/daeacc3fc4.js',
crossorigin: 'anonymous',
},
],
}