docusaurus-plugin-glossary 3.1.0 → 3.2.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.
Files changed (50) hide show
  1. package/dist/chunk-4CUFUKUA.js +109 -0
  2. package/dist/chunk-4CUFUKUA.js.map +1 -0
  3. package/dist/chunk-PEB4Y6RI.js +311 -0
  4. package/dist/chunk-PEB4Y6RI.js.map +1 -0
  5. package/dist/chunk-SNP37IVL.js +212 -0
  6. package/dist/chunk-SNP37IVL.js.map +1 -0
  7. package/dist/client/index.cjs +55 -0
  8. package/dist/client/index.cjs.map +1 -0
  9. package/dist/client/index.js +10 -21
  10. package/dist/client/index.js.map +1 -0
  11. package/dist/components/GlossaryPage.cjs +130 -0
  12. package/dist/components/GlossaryPage.cjs.map +1 -0
  13. package/dist/components/GlossaryPage.js +74 -113
  14. package/dist/components/GlossaryPage.js.map +1 -0
  15. package/dist/index.cjs +659 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.cts +173 -0
  18. package/dist/index.d.ts +82 -11
  19. package/dist/index.js +23 -173
  20. package/dist/index.js.map +1 -0
  21. package/dist/preset.cjs +710 -0
  22. package/dist/preset.cjs.map +1 -0
  23. package/dist/preset.d.cts +98 -0
  24. package/dist/preset.d.ts +8 -7
  25. package/dist/preset.js +79 -143
  26. package/dist/preset.js.map +1 -0
  27. package/dist/remark/glossary-terms.cjs +345 -0
  28. package/dist/remark/glossary-terms.cjs.map +1 -0
  29. package/dist/remark/glossary-terms.js +9 -440
  30. package/dist/remark/glossary-terms.js.map +1 -0
  31. package/dist/theme/GlossaryTerm/index.cjs +138 -0
  32. package/dist/theme/GlossaryTerm/index.cjs.map +1 -0
  33. package/dist/theme/GlossaryTerm/index.js +56 -90
  34. package/dist/theme/GlossaryTerm/index.js.map +1 -0
  35. package/dist/validation.cjs +238 -0
  36. package/dist/validation.cjs.map +1 -0
  37. package/dist/validation.d.cts +2 -0
  38. package/dist/validation.d.ts +2 -44
  39. package/dist/validation.js +11 -256
  40. package/dist/validation.js.map +1 -0
  41. package/package.json +25 -30
  42. package/dist/components/GlossaryPage.test.js +0 -205
  43. package/dist/index.d.ts.map +0 -1
  44. package/dist/preset.d.ts.map +0 -1
  45. package/dist/remark/glossary-terms.d.ts +0 -28
  46. package/dist/remark/glossary-terms.d.ts.map +0 -1
  47. package/dist/theme/GlossaryTerm/index.test.js +0 -143
  48. package/dist/validation.d.ts.map +0 -1
  49. /package/dist/{components/GlossaryPage.module.css → GlossaryPage.module-M4DEUP4X.module.css} +0 -0
  50. /package/dist/{theme/GlossaryTerm/styles.module.css → styles.module-N7ME3MWS.module.css} +0 -0
@@ -0,0 +1,710 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/preset.ts
31
+ var preset_exports = {};
32
+ __export(preset_exports, {
33
+ default: () => preset
34
+ });
35
+ module.exports = __toCommonJS(preset_exports);
36
+
37
+ // src/index.ts
38
+ var import_path2 = __toESM(require("path"), 1);
39
+ var import_url = require("url");
40
+ var import_fs_extra = __toESM(require("fs-extra"), 1);
41
+ var import_validate_peer_dependencies = __toESM(require("validate-peer-dependencies"), 1);
42
+
43
+ // src/remark/glossary-terms.js
44
+ var import_unist_util_visit = require("unist-util-visit");
45
+ var import_path = __toESM(require("path"), 1);
46
+ var import_fs = __toESM(require("fs"), 1);
47
+ function validateGlossaryTerms(data, _filePath) {
48
+ const errors = [];
49
+ const validTerms = [];
50
+ if (data === null || data === void 0) {
51
+ errors.push(`Glossary data is null or undefined`);
52
+ return { terms: [], errors };
53
+ }
54
+ if (typeof data !== "object") {
55
+ errors.push(`Glossary data must be an object, got ${typeof data}`);
56
+ return { terms: [], errors };
57
+ }
58
+ if (!("terms" in data)) {
59
+ errors.push(`Glossary data must contain a "terms" array`);
60
+ return { terms: [], errors };
61
+ }
62
+ if (!Array.isArray(data.terms)) {
63
+ errors.push(`Field "terms" must be an array, got ${typeof data.terms}`);
64
+ return { terms: [], errors };
65
+ }
66
+ data.terms.forEach((term, index) => {
67
+ if (term === null || term === void 0 || typeof term !== "object") {
68
+ errors.push(`terms[${index}]: Term must be an object`);
69
+ return;
70
+ }
71
+ if (typeof term.term !== "string" || term.term.trim() === "") {
72
+ errors.push(`terms[${index}]: Missing or invalid "term" field`);
73
+ return;
74
+ }
75
+ if (typeof term.definition !== "string") {
76
+ errors.push(`terms[${index}]: Missing or invalid "definition" field`);
77
+ return;
78
+ }
79
+ validTerms.push(term);
80
+ });
81
+ return { terms: validTerms, errors };
82
+ }
83
+ var glossaryCache = /* @__PURE__ */ new Map();
84
+ var CACHE_TTL = 5e3;
85
+ function remarkGlossaryTerms({
86
+ terms = [],
87
+ glossaryPath = null,
88
+ routePath = "/glossary",
89
+ siteDir = null
90
+ } = {}) {
91
+ let glossaryTerms = terms;
92
+ if (!glossaryTerms.length && glossaryPath && siteDir) {
93
+ try {
94
+ const glossaryFilePath = import_path.default.resolve(siteDir, glossaryPath);
95
+ const now = Date.now();
96
+ const cached = glossaryCache.get(glossaryFilePath);
97
+ if (cached && now - cached.loadedAt < CACHE_TTL) {
98
+ glossaryTerms = cached.terms;
99
+ } else {
100
+ if (import_fs.default.existsSync(glossaryFilePath)) {
101
+ const fileContent = import_fs.default.readFileSync(glossaryFilePath, "utf8");
102
+ let glossaryData;
103
+ try {
104
+ glossaryData = JSON.parse(fileContent);
105
+ } catch (parseError) {
106
+ console.error(
107
+ `[glossary-plugin] Failed to parse glossary JSON at ${glossaryPath}:`,
108
+ parseError.message
109
+ );
110
+ glossaryCache.set(glossaryFilePath, {
111
+ terms: [],
112
+ loadedAt: now
113
+ });
114
+ return (tree) => tree;
115
+ }
116
+ const { terms: validTerms, errors } = validateGlossaryTerms(glossaryData, glossaryPath);
117
+ if (errors.length > 0) {
118
+ console.warn(`[glossary-plugin] Glossary validation errors in ${glossaryPath}:`);
119
+ errors.forEach((err) => console.warn(` - ${err}`));
120
+ if (validTerms.length > 0) {
121
+ console.warn(`[glossary-plugin] Proceeding with ${validTerms.length} valid term(s).`);
122
+ }
123
+ }
124
+ glossaryTerms = validTerms;
125
+ glossaryCache.set(glossaryFilePath, {
126
+ terms: glossaryTerms,
127
+ loadedAt: now
128
+ });
129
+ if (!cached && process.env.NODE_ENV !== "production") {
130
+ console.log(
131
+ `[glossary-plugin] Loaded ${glossaryTerms.length} terms from ${glossaryPath}`
132
+ );
133
+ }
134
+ } else {
135
+ glossaryCache.set(glossaryFilePath, {
136
+ terms: [],
137
+ loadedAt: now
138
+ });
139
+ if (process.env.NODE_ENV !== "production") {
140
+ console.warn(`[glossary-plugin] Glossary file not found: ${glossaryPath}`);
141
+ }
142
+ }
143
+ }
144
+ } catch (error) {
145
+ console.warn(
146
+ `[glossary-plugin] Failed to load glossary from ${glossaryPath}:`,
147
+ error.message
148
+ );
149
+ if (glossaryPath && siteDir) {
150
+ const glossaryFilePath = import_path.default.resolve(siteDir, glossaryPath);
151
+ glossaryCache.set(glossaryFilePath, {
152
+ terms: [],
153
+ loadedAt: Date.now()
154
+ });
155
+ }
156
+ }
157
+ }
158
+ const termMap = /* @__PURE__ */ new Map();
159
+ glossaryTerms.forEach((termObj) => {
160
+ if (termObj.term && termObj.autoLink !== false) {
161
+ termMap.set(termObj.term.toLowerCase(), termObj);
162
+ }
163
+ });
164
+ const sortedTerms = Array.from(termMap.entries()).sort((a, b) => b[0].length - a[0].length);
165
+ if (sortedTerms.length === 0) {
166
+ return (tree) => tree;
167
+ }
168
+ function replaceTermsInText(text) {
169
+ if (!text || !sortedTerms.length) {
170
+ return [{ type: "text", value: text }];
171
+ }
172
+ const result = [];
173
+ let lastIndex = 0;
174
+ const textLower = text.toLowerCase();
175
+ const matches = [];
176
+ for (const [lowerTerm, termObj] of sortedTerms) {
177
+ const term = termObj.term;
178
+ let searchIndex = 0;
179
+ while (searchIndex < textLower.length) {
180
+ const index = textLower.indexOf(lowerTerm, searchIndex);
181
+ if (index === -1) break;
182
+ const beforeChar = index > 0 ? textLower[index - 1] : " ";
183
+ const afterIndex = index + lowerTerm.length;
184
+ const afterChar = afterIndex < textLower.length ? textLower[afterIndex] : " ";
185
+ let matchLength = term.length;
186
+ let isWordBoundary = !/\w/.test(beforeChar) && !/\w/.test(afterChar);
187
+ if (!isWordBoundary && afterChar === "s") {
188
+ const nextChar = afterIndex + 1 < textLower.length ? textLower[afterIndex + 1] : " ";
189
+ if (!/\w/.test(nextChar)) {
190
+ isWordBoundary = true;
191
+ matchLength = term.length + 1;
192
+ }
193
+ }
194
+ if (!isWordBoundary && afterChar === "e" && afterIndex + 1 < textLower.length && textLower[afterIndex + 1] === "s") {
195
+ const nextChar = afterIndex + 2 < textLower.length ? textLower[afterIndex + 2] : " ";
196
+ if (!/\w/.test(nextChar)) {
197
+ isWordBoundary = true;
198
+ matchLength = term.length + 2;
199
+ }
200
+ }
201
+ if (isWordBoundary) {
202
+ matches.push({
203
+ index,
204
+ length: matchLength,
205
+ term,
206
+ termObj,
207
+ // Store original case from the text
208
+ originalText: text.substring(index, index + matchLength)
209
+ });
210
+ }
211
+ searchIndex = index + 1;
212
+ }
213
+ }
214
+ matches.sort((a, b) => a.index - b.index);
215
+ const nonOverlappingMatches = [];
216
+ let lastMatchEnd = 0;
217
+ for (const match of matches) {
218
+ if (match.index >= lastMatchEnd) {
219
+ nonOverlappingMatches.push(match);
220
+ lastMatchEnd = match.index + match.length;
221
+ }
222
+ }
223
+ for (const match of nonOverlappingMatches) {
224
+ if (match.index > lastIndex) {
225
+ result.push({
226
+ type: "text",
227
+ value: text.substring(lastIndex, match.index)
228
+ });
229
+ }
230
+ result.push({
231
+ type: "mdxJsxFlowElement",
232
+ name: "GlossaryTerm",
233
+ attributes: [
234
+ {
235
+ type: "mdxJsxAttribute",
236
+ name: "term",
237
+ value: match.termObj.term
238
+ },
239
+ {
240
+ type: "mdxJsxAttribute",
241
+ name: "definition",
242
+ value: match.termObj.definition || ""
243
+ },
244
+ {
245
+ type: "mdxJsxAttribute",
246
+ name: "routePath",
247
+ value: routePath
248
+ }
249
+ ],
250
+ children: [
251
+ {
252
+ type: "text",
253
+ value: match.originalText
254
+ }
255
+ ]
256
+ });
257
+ lastIndex = match.index + match.length;
258
+ }
259
+ if (lastIndex < text.length) {
260
+ result.push({
261
+ type: "text",
262
+ value: text.substring(lastIndex)
263
+ });
264
+ }
265
+ return result.length > 0 ? result : [{ type: "text", value: text }];
266
+ }
267
+ const transformer = (tree) => {
268
+ let usedGlossaryTerm = false;
269
+ (0, import_unist_util_visit.visit)(tree, "text", (node, index, parent) => {
270
+ if (parent.type === "code" || parent.type === "inlineCode" || parent.type === "link" || parent.type === "mdxJsxFlowElement" || parent.type === "mdxJsxTextElement") {
271
+ return;
272
+ }
273
+ const replacements = replaceTermsInText(node.value);
274
+ if (replacements.length > 1 || replacements.length === 1 && replacements[0].type !== "text") {
275
+ const newNodes = replacements.map((replacement) => {
276
+ if (replacement.type === "mdxJsxFlowElement") {
277
+ if (parent.type === "paragraph") {
278
+ usedGlossaryTerm = true;
279
+ return {
280
+ type: "mdxJsxTextElement",
281
+ name: replacement.name,
282
+ attributes: replacement.attributes,
283
+ children: replacement.children
284
+ };
285
+ }
286
+ usedGlossaryTerm = true;
287
+ }
288
+ return replacement;
289
+ });
290
+ parent.children.splice(index, 1, ...newNodes);
291
+ return index + newNodes.length - 1;
292
+ }
293
+ });
294
+ if (usedGlossaryTerm) {
295
+ const importNode = {
296
+ type: "mdxjsEsm",
297
+ value: 'import GlossaryTerm from "@theme/GlossaryTerm";',
298
+ data: {
299
+ estree: {
300
+ type: "Program",
301
+ sourceType: "module",
302
+ body: [
303
+ {
304
+ type: "ImportDeclaration",
305
+ specifiers: [
306
+ {
307
+ type: "ImportDefaultSpecifier",
308
+ local: { type: "Identifier", name: "GlossaryTerm" }
309
+ }
310
+ ],
311
+ source: {
312
+ type: "Literal",
313
+ value: "@theme/GlossaryTerm",
314
+ raw: '"@theme/GlossaryTerm"'
315
+ }
316
+ }
317
+ ]
318
+ }
319
+ }
320
+ };
321
+ const hasImport = Array.isArray(tree.children) && tree.children.some(
322
+ (n) => n.type === "mdxjsEsm" && (n.value?.includes("@theme/GlossaryTerm") || n.data?.estree?.body?.some((s) => s.source?.value === "@theme/GlossaryTerm"))
323
+ );
324
+ if (!hasImport) {
325
+ if (!Array.isArray(tree.children)) tree.children = [];
326
+ let insertIndex = 0;
327
+ for (let i = 0; i < tree.children.length; i++) {
328
+ const node = tree.children[i];
329
+ if (node.type === "yaml" || node.type === "toml") {
330
+ insertIndex = i + 1;
331
+ } else {
332
+ break;
333
+ }
334
+ }
335
+ tree.children.splice(insertIndex, 0, importNode);
336
+ }
337
+ }
338
+ };
339
+ return transformer;
340
+ }
341
+
342
+ // src/validation.ts
343
+ function validateTerm(term, index) {
344
+ const errors = [];
345
+ const prefix = `terms[${index}]`;
346
+ if (term === null || term === void 0) {
347
+ errors.push({
348
+ field: prefix,
349
+ message: "Term cannot be null or undefined",
350
+ value: term
351
+ });
352
+ return errors;
353
+ }
354
+ if (typeof term !== "object") {
355
+ errors.push({
356
+ field: prefix,
357
+ message: `Term must be an object, got ${typeof term}`,
358
+ value: term
359
+ });
360
+ return errors;
361
+ }
362
+ const termObj = term;
363
+ if (!("term" in termObj)) {
364
+ errors.push({
365
+ field: `${prefix}.term`,
366
+ message: 'Missing required field "term"'
367
+ });
368
+ } else if (typeof termObj.term !== "string") {
369
+ errors.push({
370
+ field: `${prefix}.term`,
371
+ message: `Field "term" must be a string, got ${typeof termObj.term}`,
372
+ value: termObj.term
373
+ });
374
+ } else if (termObj.term.trim() === "") {
375
+ errors.push({
376
+ field: `${prefix}.term`,
377
+ message: 'Field "term" cannot be empty',
378
+ value: termObj.term
379
+ });
380
+ }
381
+ if (!("definition" in termObj)) {
382
+ errors.push({
383
+ field: `${prefix}.definition`,
384
+ message: 'Missing required field "definition"'
385
+ });
386
+ } else if (typeof termObj.definition !== "string") {
387
+ errors.push({
388
+ field: `${prefix}.definition`,
389
+ message: `Field "definition" must be a string, got ${typeof termObj.definition}`,
390
+ value: termObj.definition
391
+ });
392
+ }
393
+ if ("abbreviation" in termObj && termObj.abbreviation !== void 0) {
394
+ if (typeof termObj.abbreviation !== "string") {
395
+ errors.push({
396
+ field: `${prefix}.abbreviation`,
397
+ message: `Field "abbreviation" must be a string, got ${typeof termObj.abbreviation}`,
398
+ value: termObj.abbreviation
399
+ });
400
+ }
401
+ }
402
+ if ("relatedTerms" in termObj && termObj.relatedTerms !== void 0) {
403
+ if (!Array.isArray(termObj.relatedTerms)) {
404
+ errors.push({
405
+ field: `${prefix}.relatedTerms`,
406
+ message: `Field "relatedTerms" must be an array, got ${typeof termObj.relatedTerms}`,
407
+ value: termObj.relatedTerms
408
+ });
409
+ } else {
410
+ termObj.relatedTerms.forEach((relatedTerm, relatedIndex) => {
411
+ if (typeof relatedTerm !== "string") {
412
+ errors.push({
413
+ field: `${prefix}.relatedTerms[${relatedIndex}]`,
414
+ message: `Related term must be a string, got ${typeof relatedTerm}`,
415
+ value: relatedTerm
416
+ });
417
+ }
418
+ });
419
+ }
420
+ }
421
+ if ("id" in termObj && termObj.id !== void 0) {
422
+ if (typeof termObj.id !== "string") {
423
+ errors.push({
424
+ field: `${prefix}.id`,
425
+ message: `Field "id" must be a string, got ${typeof termObj.id}`,
426
+ value: termObj.id
427
+ });
428
+ }
429
+ }
430
+ if ("autoLink" in termObj && termObj.autoLink !== void 0) {
431
+ if (typeof termObj.autoLink !== "boolean") {
432
+ errors.push({
433
+ field: `${prefix}.autoLink`,
434
+ message: `Field "autoLink" must be a boolean, got ${typeof termObj.autoLink}`,
435
+ value: termObj.autoLink
436
+ });
437
+ }
438
+ }
439
+ return errors;
440
+ }
441
+ function validateGlossaryData(data, options = {}) {
442
+ const { throwOnError = true } = options;
443
+ const errors = [];
444
+ if (data === null || data === void 0) {
445
+ errors.push({
446
+ field: "root",
447
+ message: "Glossary data cannot be null or undefined",
448
+ value: data
449
+ });
450
+ if (throwOnError && errors.length > 0) {
451
+ throw new GlossaryValidationError(errors);
452
+ }
453
+ return { valid: false, errors, data: { terms: [] } };
454
+ }
455
+ if (typeof data !== "object") {
456
+ errors.push({
457
+ field: "root",
458
+ message: `Glossary data must be an object, got ${typeof data}`,
459
+ value: data
460
+ });
461
+ if (throwOnError && errors.length > 0) {
462
+ throw new GlossaryValidationError(errors);
463
+ }
464
+ return { valid: false, errors, data: { terms: [] } };
465
+ }
466
+ const glossaryData = data;
467
+ if (!("terms" in glossaryData)) {
468
+ errors.push({
469
+ field: "terms",
470
+ message: 'Glossary data must contain a "terms" array'
471
+ });
472
+ if (throwOnError && errors.length > 0) {
473
+ throw new GlossaryValidationError(errors);
474
+ }
475
+ return { valid: false, errors, data: { terms: [] } };
476
+ }
477
+ if (!Array.isArray(glossaryData.terms)) {
478
+ errors.push({
479
+ field: "terms",
480
+ message: `Field "terms" must be an array, got ${typeof glossaryData.terms}`,
481
+ value: glossaryData.terms
482
+ });
483
+ if (throwOnError && errors.length > 0) {
484
+ throw new GlossaryValidationError(errors);
485
+ }
486
+ return { valid: false, errors, data: { terms: [] } };
487
+ }
488
+ const validTerms = [];
489
+ glossaryData.terms.forEach((term, index) => {
490
+ const termErrors = validateTerm(term, index);
491
+ if (termErrors.length > 0) {
492
+ errors.push(...termErrors);
493
+ } else {
494
+ validTerms.push(term);
495
+ }
496
+ });
497
+ const termNames = /* @__PURE__ */ new Map();
498
+ validTerms.forEach((term, index) => {
499
+ const lowerName = term.term.toLowerCase();
500
+ if (termNames.has(lowerName)) {
501
+ errors.push({
502
+ field: `terms[${index}].term`,
503
+ message: `Duplicate term "${term.term}" (first occurrence at index ${termNames.get(lowerName)})`,
504
+ value: term.term
505
+ });
506
+ } else {
507
+ termNames.set(lowerName, index);
508
+ }
509
+ });
510
+ if (throwOnError && errors.length > 0) {
511
+ throw new GlossaryValidationError(errors);
512
+ }
513
+ return {
514
+ valid: errors.length === 0,
515
+ errors,
516
+ data: { terms: validTerms }
517
+ };
518
+ }
519
+ var GlossaryValidationError = class _GlossaryValidationError extends Error {
520
+ constructor(errors) {
521
+ const message = formatValidationErrors(errors);
522
+ super(message);
523
+ this.name = "GlossaryValidationError";
524
+ this.errors = errors;
525
+ if (Error.captureStackTrace) {
526
+ Error.captureStackTrace(this, _GlossaryValidationError);
527
+ }
528
+ }
529
+ };
530
+ function formatValidationErrors(errors) {
531
+ if (errors.length === 0) {
532
+ return "No validation errors";
533
+ }
534
+ const header = `Glossary validation failed with ${errors.length} error${errors.length > 1 ? "s" : ""}:`;
535
+ const errorList = errors.map((err, index) => {
536
+ let msg = ` ${index + 1}. [${err.field}] ${err.message}`;
537
+ if (err.value !== void 0) {
538
+ const valueStr = typeof err.value === "object" ? JSON.stringify(err.value) : String(err.value);
539
+ const truncated = valueStr.length > 50 ? valueStr.substring(0, 50) + "..." : valueStr;
540
+ msg += ` (got: ${truncated})`;
541
+ }
542
+ return msg;
543
+ }).join("\n");
544
+ return `${header}
545
+ ${errorList}`;
546
+ }
547
+
548
+ // src/index.ts
549
+ var import_meta = {};
550
+ var currentFilePath = (0, import_url.fileURLToPath)(import_meta.url);
551
+ var currentDir = import_path2.default.dirname(currentFilePath);
552
+ (0, import_validate_peer_dependencies.default)(currentDir);
553
+ function glossaryPlugin(context, options = {}) {
554
+ const { glossaryPath = "glossary/glossary.json", routePath = "/glossary" } = options;
555
+ return {
556
+ name: "docusaurus-plugin-glossary",
557
+ getClientModules() {
558
+ return [import_path2.default.resolve(currentDir, "./client/index.js")];
559
+ },
560
+ async loadContent() {
561
+ const glossaryFilePath = import_path2.default.resolve(context.siteDir, glossaryPath);
562
+ if (await import_fs_extra.default.pathExists(glossaryFilePath)) {
563
+ try {
564
+ const rawData = await import_fs_extra.default.readJson(glossaryFilePath);
565
+ const validationResult = validateGlossaryData(rawData, { throwOnError: false });
566
+ if (!validationResult.valid) {
567
+ console.warn(
568
+ `[glossary-plugin] Glossary file has validation errors at ${glossaryFilePath}:`
569
+ );
570
+ validationResult.errors.forEach((err) => {
571
+ console.warn(` - [${err.field}] ${err.message}`);
572
+ });
573
+ console.warn("[glossary-plugin] Proceeding with valid terms only.");
574
+ }
575
+ return validationResult.data;
576
+ } catch (error) {
577
+ if (error instanceof GlossaryValidationError) {
578
+ throw error;
579
+ }
580
+ throw new Error(
581
+ `Failed to parse glossary file at ${glossaryFilePath}: ${error instanceof Error ? error.message : String(error)}`
582
+ );
583
+ }
584
+ }
585
+ console.warn(`Glossary file not found at ${glossaryFilePath}. Using empty glossary.`);
586
+ return { terms: [] };
587
+ },
588
+ async contentLoaded({ content, actions }) {
589
+ const { createData, addRoute, setGlobalData } = actions;
590
+ const glossaryContent = content;
591
+ const glossaryDataPath = await createData(
592
+ "glossary-data.json",
593
+ JSON.stringify(glossaryContent)
594
+ );
595
+ await createData(
596
+ "remark-glossary-data.json",
597
+ JSON.stringify({
598
+ terms: glossaryContent.terms || [],
599
+ routePath
600
+ })
601
+ );
602
+ addRoute({
603
+ path: routePath,
604
+ component: import_path2.default.join(currentDir, "components/GlossaryPage.js"),
605
+ exact: true,
606
+ modules: {
607
+ glossaryData: glossaryDataPath
608
+ }
609
+ });
610
+ setGlobalData({
611
+ terms: glossaryContent.terms || [],
612
+ routePath
613
+ });
614
+ },
615
+ getThemePath() {
616
+ return import_path2.default.resolve(currentDir, "./theme");
617
+ },
618
+ getPathsToWatch() {
619
+ return [import_path2.default.resolve(context.siteDir, glossaryPath)];
620
+ },
621
+ async postBuild() {
622
+ console.log("Glossary plugin: Build completed");
623
+ }
624
+ };
625
+ }
626
+ function getRemarkPlugin(pluginOptions, context) {
627
+ const { glossaryPath = "glossary/glossary.json", routePath = "/glossary" } = pluginOptions;
628
+ const siteDir = context?.siteDir;
629
+ return [
630
+ remarkGlossaryTerms,
631
+ {
632
+ glossaryPath,
633
+ routePath,
634
+ siteDir
635
+ }
636
+ ];
637
+ }
638
+
639
+ // src/preset.ts
640
+ function preset(context, options = {}) {
641
+ const { glossary = {}, id: _id, ...restOptions } = options;
642
+ const { docs, pages, theme, gtag, googleAnalytics, googleTagManager, debug } = restOptions;
643
+ const blog = restOptions.blog;
644
+ const sitemap = restOptions.sitemap;
645
+ const classicOptions = {};
646
+ if (docs !== void 0) classicOptions.docs = docs;
647
+ if (blog !== void 0) classicOptions.blog = blog;
648
+ if (pages !== void 0) classicOptions.pages = pages;
649
+ if (theme !== void 0) classicOptions.theme = theme;
650
+ if (gtag !== void 0) classicOptions.gtag = gtag;
651
+ if (googleAnalytics !== void 0) classicOptions.googleAnalytics = googleAnalytics;
652
+ if (googleTagManager !== void 0) classicOptions.googleTagManager = googleTagManager;
653
+ if (sitemap !== void 0) classicOptions.sitemap = sitemap;
654
+ if (debug !== void 0) classicOptions.debug = debug;
655
+ const { glossaryPath = "glossary/glossary.json", routePath = "/glossary" } = glossary;
656
+ const remarkPlugin = getRemarkPlugin({ glossaryPath, routePath }, { siteDir: context.siteDir });
657
+ const docsConfig = classicOptions.docs || {};
658
+ const docsRemarkPlugins = docsConfig.remarkPlugins || [];
659
+ const extendedDocsConfig = {
660
+ ...docsConfig,
661
+ remarkPlugins: [...docsRemarkPlugins, remarkPlugin]
662
+ };
663
+ const pagesConfig = classicOptions.pages || {};
664
+ const pagesRemarkPlugins = pagesConfig.remarkPlugins || [];
665
+ const extendedPagesConfig = {
666
+ ...pagesConfig,
667
+ remarkPlugins: [...pagesRemarkPlugins, remarkPlugin]
668
+ };
669
+ let extendedBlogConfig = blog;
670
+ if (typeof blog === "object" && blog !== null) {
671
+ const blogRemarkPlugins = blog.remarkPlugins || [];
672
+ extendedBlogConfig = {
673
+ ...blog,
674
+ remarkPlugins: [...blogRemarkPlugins, remarkPlugin]
675
+ };
676
+ }
677
+ const finalClassicOptions = {};
678
+ if (extendedDocsConfig !== void 0) finalClassicOptions.docs = extendedDocsConfig;
679
+ if (extendedBlogConfig !== void 0) finalClassicOptions.blog = extendedBlogConfig;
680
+ if (extendedPagesConfig !== void 0) finalClassicOptions.pages = extendedPagesConfig;
681
+ if (theme !== void 0) finalClassicOptions.theme = theme;
682
+ if (gtag !== void 0) finalClassicOptions.gtag = gtag;
683
+ if (googleAnalytics !== void 0) finalClassicOptions.googleAnalytics = googleAnalytics;
684
+ if (googleTagManager !== void 0) finalClassicOptions.googleTagManager = googleTagManager;
685
+ if (sitemap !== void 0) finalClassicOptions.sitemap = sitemap;
686
+ if (debug !== void 0) finalClassicOptions.debug = debug;
687
+ const plugins = [
688
+ // Add the glossary plugin first
689
+ function glossaryPluginWrapper(ctx) {
690
+ return glossaryPlugin(ctx, glossary);
691
+ }
692
+ ];
693
+ if (extendedDocsConfig) plugins.push(["@docusaurus/plugin-content-docs", extendedDocsConfig]);
694
+ if (typeof extendedBlogConfig === "object" && extendedBlogConfig !== null)
695
+ plugins.push(["@docusaurus/plugin-content-blog", extendedBlogConfig]);
696
+ if (extendedPagesConfig) plugins.push(["@docusaurus/plugin-content-pages", extendedPagesConfig]);
697
+ if (gtag) plugins.push(["@docusaurus/plugin-google-gtag", gtag]);
698
+ if (googleAnalytics) plugins.push(["@docusaurus/plugin-google-analytics", googleAnalytics]);
699
+ if (googleTagManager) plugins.push(["@docusaurus/plugin-google-tag-manager", googleTagManager]);
700
+ if (sitemap !== false) plugins.push(["@docusaurus/plugin-sitemap", sitemap || {}]);
701
+ if (debug) plugins.push(["@docusaurus/plugin-debug", {}]);
702
+ return {
703
+ themes: [
704
+ // Pass theme options (including customCss) to theme-classic
705
+ ["@docusaurus/theme-classic", theme || {}]
706
+ ],
707
+ plugins
708
+ };
709
+ }
710
+ //# sourceMappingURL=preset.cjs.map