docusaurus-plugin-glossary 1.0.1 → 1.0.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/README.md CHANGED
@@ -13,177 +13,77 @@ A comprehensive Docusaurus plugin that provides glossary functionality with an a
13
13
  - **Abbreviation Support**: Display full form of abbreviated terms
14
14
  - **Customizable**: Configure glossary path and route
15
15
 
16
- ## Installation
17
-
18
- ### For Local Use (Same Repository)
16
+ ## Quick Start
19
17
 
20
- 1. Copy the plugin directory to your Docusaurus site:
21
-
22
- ```
23
- src/plugins/docusaurus-plugin-glossary/
18
+ 1. **Install the plugin:**
19
+ ```bash
20
+ npm install docusaurus-plugin-glossary
24
21
  ```
25
22
 
26
- 2. Add the plugin to your `docusaurus.config.js`:
23
+ 2. **Add to your `docusaurus.config.js`:**
27
24
  ```javascript
28
- const glossaryPlugin = require.resolve('./src/plugins/docusaurus-plugin-glossary');
29
-
30
25
  module.exports = {
31
26
  // ... other config
32
27
  plugins: [
33
28
  [
34
- glossaryPlugin,
29
+ 'docusaurus-plugin-glossary',
35
30
  {
36
- glossaryPath: 'glossary/glossary.json', // optional, default: 'glossary/glossary.json'
37
- routePath: '/glossary', // optional, default: '/glossary'
38
- autoLinkTerms: true, // optional, default: true - automatically link terms in markdown
31
+ glossaryPath: 'glossary/glossary.json', // Path to your glossary file
32
+ routePath: '/glossary', // URL path for glossary page
33
+ autoLinkTerms: true, // Automatically link terms (default: true)
39
34
  },
40
35
  ],
41
36
  ],
42
37
  // ... other config
43
38
  };
44
39
  ```
40
+
41
+ **That's it!** The remark plugin is automatically configured - no manual `markdown.remarkPlugins` setup needed.
45
42
 
46
- 3. **Enable automatic term detection** by adding the remark plugin to your markdown configuration:
47
- ```javascript
48
- const glossaryPlugin = require('./src/plugins/docusaurus-plugin-glossary');
49
-
50
- module.exports = {
51
- // ... other config
52
- markdown: {
53
- remarkPlugins: [
54
- [
55
- glossaryPlugin.remarkPlugin,
56
- {
57
- glossaryPath: 'glossary/glossary.json',
58
- routePath: '/glossary',
59
- siteDir: process.cwd(), // or your site directory
60
- },
61
- ],
62
- ],
63
- },
64
- // ... other config
65
- };
66
- ```
67
-
68
- ### For Separate Package (To Publish)
69
-
70
- To publish this as a separate npm package:
71
-
72
- 1. Create a new directory for the package:
73
-
74
- ```bash
75
- mkdir docusaurus-plugin-glossary
76
- cd docusaurus-plugin-glossary
77
- ```
78
-
79
- 2. Copy the plugin files:
80
-
81
- ```
82
- docusaurus-plugin-glossary/
83
- ├── index.js
84
- ├── components/
85
- │ ├── GlossaryPage.js
86
- │ └── GlossaryPage.module.css
87
- ├── remark/
88
- │ └── glossary-terms.js
89
- ├── theme/
90
- │ └── GlossaryTerm/
91
- │ ├── index.js
92
- │ └── styles.module.css
93
- ├── package.json
94
- └── README.md
95
- ```
96
-
97
- 3. Create a `package.json`:
98
-
43
+ 3. **Create your glossary file at `glossary/glossary.json`:**
99
44
  ```json
100
45
  {
101
- "name": "docusaurus-plugin-glossary",
102
- "version": "1.0.0",
103
- "description": "A Docusaurus plugin for creating and managing glossary terms",
104
- "main": "index.js",
105
- "files": [
106
- "index.js",
107
- "components/",
108
- "theme/",
109
- "remark/",
110
- "README.md",
111
- "LICENSE"
112
- ],
113
- "keywords": ["docusaurus", "glossary", "plugin", "documentation"],
114
- "peerDependencies": {
115
- "@docusaurus/core": "^3.0.0",
116
- "react": "^18.0.0",
117
- "react-dom": "^18.0.0"
118
- },
119
- "dependencies": {
120
- "fs-extra": "^11.0.0",
121
- "unist-util-visit": "^5.0.0"
122
- },
123
- "engines": {
124
- "node": ">=16.14"
125
- }
46
+ "description": "A collection of technical terms and their definitions",
47
+ "terms": [
48
+ {
49
+ "term": "API",
50
+ "abbreviation": "Application Programming Interface",
51
+ "definition": "A set of rules and protocols that allows different software applications to communicate with each other.",
52
+ "relatedTerms": ["REST", "GraphQL"]
53
+ },
54
+ {
55
+ "term": "REST",
56
+ "abbreviation": "Representational State Transfer",
57
+ "definition": "An architectural style for designing networked applications.",
58
+ "relatedTerms": ["API", "HTTP"]
59
+ }
60
+ ]
126
61
  }
127
62
  ```
128
63
 
129
- 4. Publish to npm:
130
-
64
+ 4. **Start your dev server:**
131
65
  ```bash
132
- npm publish
66
+ npm run start
133
67
  ```
134
68
 
135
- 5. Install in your Docusaurus site:
69
+ 5. **That's it!**
70
+ - Visit `/glossary` to see your glossary page
71
+ - Write markdown normally - terms will automatically be linked with tooltips
72
+ - Use `<GlossaryTerm>` component in MDX for manual control
136
73
 
137
- ```bash
138
- npm install docusaurus-plugin-glossary
139
- ```
74
+ ## Installation
140
75
 
141
- 6. Add to your `docusaurus.config.js`:
142
- ```javascript
143
- const glossaryPlugin = require('docusaurus-plugin-glossary');
144
-
145
- module.exports = {
146
- // ... other config
147
- plugins: [
148
- [
149
- 'docusaurus-plugin-glossary',
150
- {
151
- glossaryPath: 'glossary/glossary.json',
152
- routePath: '/glossary',
153
- },
154
- ],
155
- ],
156
- // ... other config
157
- };
158
- ```
76
+ ### Install from npm (Recommended)
159
77
 
160
- 7. **Enable automatic term detection** by adding the remark plugin to your markdown configuration:
161
- ```javascript
162
- const glossaryPlugin = require('docusaurus-plugin-glossary');
163
-
164
- module.exports = {
165
- // ... other config
166
- markdown: {
167
- remarkPlugins: [
168
- [
169
- glossaryPlugin.remarkPlugin,
170
- {
171
- glossaryPath: 'glossary/glossary.json',
172
- routePath: '/glossary',
173
- siteDir: process.cwd(), // or your site directory
174
- },
175
- ],
176
- ],
177
- },
178
- // ... other config
179
- };
180
- ```
78
+ ```bash
79
+ npm install docusaurus-plugin-glossary
80
+ ```
181
81
 
182
- ## Usage
82
+ ## Usage Guide
183
83
 
184
- ### 1. Create a Glossary Data File
84
+ ### Step 1: Create Your Glossary File
185
85
 
186
- Create a JSON file at `glossary/glossary.json` (or your configured path):
86
+ Create a JSON file at `glossary/glossary.json` (or your configured path) in your Docusaurus site root:
187
87
 
188
88
  ```json
189
89
  {
@@ -205,19 +105,74 @@ Create a JSON file at `glossary/glossary.json` (or your configured path):
205
105
  }
206
106
  ```
207
107
 
208
- ### 2. Glossary Data Structure
108
+ **Required fields:**
109
+ - `term` (string): The glossary term name
110
+ - `definition` (string): The term's definition
111
+
112
+ **Optional fields:**
113
+ - `abbreviation` (string): The full form if the term is an abbreviation
114
+ - `relatedTerms` (string[]): Array of related term names that link to other glossary entries
115
+ - `id` (string): Custom ID for linking (auto-generated from term name if not provided)
116
+
117
+ ### Step 2: Configure the Plugin
118
+
119
+ Add the plugin to your `docusaurus.config.js`:
209
120
 
210
- Each term object can include:
121
+ ```javascript
122
+ module.exports = {
123
+ plugins: [
124
+ [
125
+ 'docusaurus-plugin-glossary',
126
+ {
127
+ glossaryPath: 'glossary/glossary.json', // Path to your glossary file
128
+ routePath: '/glossary', // URL path for the glossary page
129
+ autoLinkTerms: true, // Automatically detect and link terms (default: true)
130
+ },
131
+ ],
132
+ ],
133
+ };
134
+ ```
135
+
136
+ **Automatic Configuration:** The remark plugin is automatically configured when `autoLinkTerms` is `true` (the default). You don't need to manually configure `markdown.remarkPlugins`!
137
+
138
+ **Advanced: Manual Remark Plugin Configuration**
139
+
140
+ If you need more control or want to disable automatic detection, you can manually configure the remark plugin:
141
+
142
+ ```javascript
143
+ const glossaryPlugin = require('docusaurus-plugin-glossary');
144
+
145
+ module.exports = {
146
+ plugins: [
147
+ [
148
+ 'docusaurus-plugin-glossary',
149
+ {
150
+ glossaryPath: 'glossary/glossary.json',
151
+ routePath: '/glossary',
152
+ autoLinkTerms: false, // Disable automatic configuration
153
+ },
154
+ ],
155
+ ],
156
+ markdown: {
157
+ remarkPlugins: [
158
+ [
159
+ glossaryPlugin.remarkPlugin,
160
+ {
161
+ glossaryPath: 'glossary/glossary.json',
162
+ routePath: '/glossary',
163
+ siteDir: process.cwd(),
164
+ },
165
+ ],
166
+ ],
167
+ },
168
+ };
169
+ ```
211
170
 
212
- - `term` (required): The glossary term
213
- - `definition` (required): The term's definition
214
- - `abbreviation` (optional): The full form if the term is an abbreviation
215
- - `relatedTerms` (optional): Array of related term names
216
- - `id` (optional): Custom ID for linking (auto-generated from term if not provided)
171
+ ### Step 3: Use Glossary Terms in Your Content
217
172
 
218
- ### 3. Automatic Term Detection
173
+ #### Option A: Automatic Detection (Recommended)
219
174
 
220
- When the remark plugin is configured (see Installation), glossary terms are automatically detected and linked in all markdown files. Simply write your content normally:
175
+ With the remark plugin configured, glossary terms are **automatically detected and linked** in all your markdown files. Simply write your content normally:
221
176
 
222
177
  ```markdown
223
178
  Our API uses REST principles to provide a simple interface.
@@ -225,45 +180,66 @@ Our API uses REST principles to provide a simple interface.
225
180
  This project supports webhooks for real-time notifications.
226
181
  ```
227
182
 
228
- Terms like "API", "REST", and "webhooks" will automatically be detected if they're defined in your glossary and will appear with:
229
- - Dotted underline styling
230
- - Tooltip showing definition on hover
231
- - Link to full glossary page entry
183
+ Terms like "API", "REST", and "webhooks" will automatically be:
184
+ - Detected if they're defined in your glossary
185
+ - Styled with a dotted underline
186
+ - Display a tooltip with the definition on hover
187
+ - Link to the full glossary page entry
232
188
 
233
- **Note**: Automatic detection works for whole words only and respects word boundaries. Terms inside code blocks, links, or existing MDX components are not processed.
189
+ **Limitations:**
190
+ - Only whole words are matched (respects word boundaries)
191
+ - Terms inside code blocks, links, or existing MDX components are **not** processed
192
+ - Matching is case-insensitive
234
193
 
235
- ### 4. Using the GlossaryTerm Component Manually
194
+ #### Option B: Manual Component Usage
236
195
 
237
- For more control or when automatic detection isn't sufficient, you can manually import and use the `GlossaryTerm` component in your MDX files:
196
+ For more control or when automatic detection isn't sufficient, use the `GlossaryTerm` component in MDX files:
238
197
 
239
198
  ```jsx
240
199
  import GlossaryTerm from '@theme/GlossaryTerm';
241
200
 
242
- This website uses an <GlossaryTerm term="API" definition="Application Programming Interface">API</GlossaryTerm> to fetch data.
201
+ This website uses an <GlossaryTerm term="API">API</GlossaryTerm> to fetch data.
243
202
 
244
- // Or with default display (term name):
245
- We use <GlossaryTerm term="REST" definition="Representational State Transfer" /> for our web services.
246
- ```
203
+ // Or with explicit definition (overrides glossary entry):
204
+ We use <GlossaryTerm term="REST" definition="Representational State Transfer" /> for our services.
247
205
 
248
- The component features:
206
+ // Or with children content:
207
+ Our <GlossaryTerm term="API" definition="Application Programming Interface">RESTful API</GlossaryTerm> is available.
208
+ ```
249
209
 
250
- - Dotted underline styling
251
- - Tooltip showing definition on hover
252
- - Link to full glossary page entry
253
- - Accessible with keyboard navigation
210
+ **Component props:**
211
+ - `term` (required): The term name (used to look up definition from glossary)
212
+ - `definition` (optional): Override the definition from the glossary file
213
+ - `children` (optional): Custom text to display (defaults to term name)
254
214
 
255
- ### 5. Accessing the Glossary Page
215
+ ### Step 4: Access the Glossary Page
256
216
 
257
217
  The glossary page is automatically available at `/glossary` (or your configured `routePath`).
258
218
 
259
- Features:
260
-
219
+ **Features:**
261
220
  - Alphabetical grouping with letter navigation
262
- - Real-time search
263
- - Related terms linking
221
+ - Real-time search across terms and definitions
222
+ - Clickable related terms
264
223
  - Responsive design
265
224
  - Dark mode support
266
225
 
226
+ **Add to navigation:**
227
+
228
+ To add the glossary to your navbar, update your `docusaurus.config.js`:
229
+
230
+ ```javascript
231
+ module.exports = {
232
+ themeConfig: {
233
+ navbar: {
234
+ items: [
235
+ {to: '/glossary', label: 'Glossary', position: 'left'},
236
+ // ... other items
237
+ ],
238
+ },
239
+ },
240
+ };
241
+ ```
242
+
267
243
  ## Configuration Options
268
244
 
269
245
  | Option | Type | Default | Description |
@@ -316,12 +292,26 @@ themeConfig: {
316
292
 
317
293
  ## Examples
318
294
 
319
- ### Example 1: Technical Documentation
295
+ See the [Usage Guide](#usage-guide) section above for complete examples. Here are additional examples:
296
+
297
+ ### Complete Glossary Example
320
298
 
321
299
  ```json
322
300
  {
323
301
  "description": "Technical terms used in our documentation",
324
302
  "terms": [
303
+ {
304
+ "term": "API",
305
+ "abbreviation": "Application Programming Interface",
306
+ "definition": "A set of rules and protocols that allows different software applications to communicate with each other.",
307
+ "relatedTerms": ["REST", "GraphQL", "Webhook"]
308
+ },
309
+ {
310
+ "term": "REST",
311
+ "abbreviation": "Representational State Transfer",
312
+ "definition": "An architectural style for designing networked applications.",
313
+ "relatedTerms": ["API", "HTTP"]
314
+ },
325
315
  {
326
316
  "term": "Webhook",
327
317
  "definition": "An HTTP callback that occurs when something happens; a simple event-notification via HTTP POST.",
@@ -331,9 +321,7 @@ themeConfig: {
331
321
  }
332
322
  ```
333
323
 
334
- ### Example 2: Automatic Term Detection
335
-
336
- With the remark plugin configured, you can simply write markdown normally:
324
+ ### Writing Content with Automatic Detection
337
325
 
338
326
  ```markdown
339
327
  ---
@@ -348,7 +336,7 @@ Webhooks are supported for real-time event notifications.
348
336
 
349
337
  The terms "API", "RESTful", and "Webhooks" will automatically be detected and linked if they're defined in your glossary.
350
338
 
351
- ### Example 3: Using in MDX Manually
339
+ ### Using the Component in MDX
352
340
 
353
341
  ```mdx
354
342
  ---
@@ -359,8 +347,8 @@ import GlossaryTerm from '@theme/GlossaryTerm';
359
347
 
360
348
  # Getting Started with Our API
361
349
 
362
- Our <GlossaryTerm term="API" definition="Application Programming Interface" />
363
- uses <GlossaryTerm term="REST" definition="Representational State Transfer">RESTful</GlossaryTerm>
350
+ Our <GlossaryTerm term="API" />
351
+ uses <GlossaryTerm term="REST">RESTful</GlossaryTerm>
364
352
  principles to provide a simple and consistent interface.
365
353
  ```
366
354
 
@@ -421,11 +409,13 @@ The remark plugin (`remark/glossary-terms.js`) automatically detects glossary te
421
409
 
422
410
  ### Automatic term detection not working
423
411
 
424
- - Ensure the remark plugin is configured in `markdown.remarkPlugins` in `docusaurus.config.js`
425
- - Check that `glossaryPath` and `siteDir` are correctly configured in the remark plugin options
426
- - Verify your glossary file exists and contains terms
412
+ - Ensure `autoLinkTerms` is `true` (the default) in your plugin configuration
413
+ - The remark plugin is automatically configured, so you don't need to manually add it to `markdown.remarkPlugins`
414
+ - Verify your glossary file exists at the configured `glossaryPath` and contains terms
415
+ - Check that terms in your content match the terms in your glossary (matching is case-insensitive but respects word boundaries)
427
416
  - Try clearing cache with `npm run clear` and restarting the dev server
428
417
  - Note that terms inside code blocks, links, or MDX components are not processed
418
+ - If you've manually configured the remark plugin, ensure `siteDir` points to the correct Docusaurus site directory
429
419
 
430
420
  ### Styles not applying
431
421
 
package/index.js CHANGED
@@ -30,6 +30,41 @@ function glossaryPlugin(context, options = {}) {
30
30
  return {
31
31
  name: 'docusaurus-plugin-glossary',
32
32
 
33
+ configureMarkdown(markdownConfig) {
34
+ // Automatically configure the remark plugin if autoLinkTerms is enabled
35
+ if (autoLinkTerms) {
36
+ if (!markdownConfig.remarkPlugins) {
37
+ markdownConfig.remarkPlugins = [];
38
+ }
39
+
40
+ const remarkPlugin = require('./remark/glossary-terms');
41
+
42
+ // Check if the remark plugin is already configured
43
+ const isAlreadyConfigured = markdownConfig.remarkPlugins.some(
44
+ (plugin) => {
45
+ if (Array.isArray(plugin) && plugin[0]) {
46
+ // Check if it's our remark plugin by comparing the function reference
47
+ return plugin[0] === remarkPlugin;
48
+ }
49
+ // Also check if it's directly the remark plugin function
50
+ return plugin === remarkPlugin;
51
+ }
52
+ );
53
+
54
+ // Only add if not already configured
55
+ if (!isAlreadyConfigured) {
56
+ markdownConfig.remarkPlugins.push([
57
+ remarkPlugin,
58
+ {
59
+ glossaryPath,
60
+ routePath,
61
+ siteDir: context.siteDir,
62
+ }
63
+ ]);
64
+ }
65
+ }
66
+ },
67
+
33
68
  async loadContent() {
34
69
  // Load glossary terms from JSON file
35
70
  const glossaryFilePath = path.resolve(context.siteDir, glossaryPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-glossary",
3
- "version": "1.0.1",
3
+ "version": "1.0.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": [
@@ -33,10 +33,11 @@
33
33
  white-space: normal;
34
34
  max-width: 300px;
35
35
  min-width: 200px;
36
- z-index: 1000;
36
+ z-index: 9999;
37
37
  opacity: 0;
38
38
  pointer-events: none;
39
39
  transition: opacity 0.2s;
40
+ visibility: hidden;
40
41
  }
41
42
 
42
43
  .tooltip::after {
@@ -63,6 +64,7 @@
63
64
  .tooltipVisible {
64
65
  opacity: 1;
65
66
  pointer-events: auto;
67
+ visibility: visible;
66
68
  }
67
69
 
68
70
  .tooltip strong {