docusaurus-plugin-glossary 1.1.0 → 1.1.2

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/index.js CHANGED
@@ -81,7 +81,7 @@ function glossaryPlugin(context, options = {}) {
81
81
  },
82
82
 
83
83
  async contentLoaded({ content, actions }) {
84
- const { createData, addRoute } = actions;
84
+ const { createData, addRoute, setGlobalData } = actions;
85
85
 
86
86
  // Create data file that can be imported by components
87
87
  const glossaryDataPath = await createData('glossary-data.json', JSON.stringify(content));
@@ -104,6 +104,12 @@ function glossaryPlugin(context, options = {}) {
104
104
  glossaryData: glossaryDataPath,
105
105
  },
106
106
  });
107
+
108
+ // Expose global data for runtime lookups (used by GlossaryTerm)
109
+ setGlobalData({
110
+ terms: content.terms || [],
111
+ routePath,
112
+ });
107
113
  },
108
114
 
109
115
  getThemePath() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-glossary",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A Docusaurus plugin for creating and managing glossary terms with auto-generated pages and inline tooltips",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -15,6 +15,9 @@
15
15
  "test": "jest",
16
16
  "test:watch": "jest --watch",
17
17
  "test:coverage": "jest --coverage",
18
+ "example:start": "npm --prefix examples/docusaurus-v3 run start",
19
+ "example:build": "npm --prefix examples/docusaurus-v3 run build",
20
+ "example:serve": "npm --prefix examples/docusaurus-v3 run serve",
18
21
  "prepublishOnly": "npm test",
19
22
  "version": "npm version",
20
23
  "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,md}\"",
@@ -1,4 +1,5 @@
1
- import React, { useState } from 'react';
1
+ import React, { useMemo, useState } from 'react';
2
+ import {usePluginData} from '@docusaurus/useGlobalData';
2
3
  import styles from './styles.module.css';
3
4
 
4
5
  /**
@@ -20,13 +21,31 @@ import styles from './styles.module.css';
20
21
  export default function GlossaryTerm({ term, definition, routePath = '/glossary', children }) {
21
22
  const [showTooltip, setShowTooltip] = useState(false);
22
23
 
24
+ // Pull definition/route from plugin global data if not provided
25
+ const pluginData = usePluginData('docusaurus-plugin-glossary');
26
+ const effectiveDefinition = useMemo(() => {
27
+ if (definition && typeof definition === 'string' && definition.length > 0) {
28
+ return definition;
29
+ }
30
+ const terms = (pluginData && pluginData.terms) || [];
31
+ const found = terms.find(
32
+ (t) => typeof t.term === 'string' && t.term.toLowerCase() === String(term).toLowerCase()
33
+ );
34
+ return found && found.definition ? found.definition : undefined;
35
+ }, [definition, pluginData, term]);
36
+
37
+ const effectiveRoutePath = useMemo(() => {
38
+ if (routePath && typeof routePath === 'string' && routePath.length > 0) return routePath;
39
+ return (pluginData && pluginData.routePath) || '/glossary';
40
+ }, [pluginData, routePath]);
41
+
23
42
  const displayText = children || term;
24
43
  const termId = term.toLowerCase().replace(/\s+/g, '-');
25
44
 
26
45
  return (
27
46
  <span className={styles.glossaryTermWrapper}>
28
47
  <a
29
- href={`${routePath}#${termId}`}
48
+ href={`${effectiveRoutePath}#${termId}`}
30
49
  className={styles.glossaryTerm}
31
50
  onMouseEnter={() => setShowTooltip(true)}
32
51
  onMouseLeave={() => setShowTooltip(false)}
@@ -36,13 +55,13 @@ export default function GlossaryTerm({ term, definition, routePath = '/glossary'
36
55
  >
37
56
  {displayText}
38
57
  </a>
39
- {definition && (
58
+ {effectiveDefinition && (
40
59
  <span
41
60
  id={`tooltip-${termId}`}
42
61
  className={`${styles.tooltip} ${showTooltip ? styles.tooltipVisible : ''}`}
43
62
  role="tooltip"
44
63
  >
45
- <strong>{term}:</strong> {definition}
64
+ <strong>{term}:</strong> {effectiveDefinition}
46
65
  </span>
47
66
  )}
48
67
  </span>