-
Notifications
You must be signed in to change notification settings - Fork 2
Docusaurus Plugins
This document explains how plugins are configured and managed in the SignalWire documentation platform.
Our documentation uses three types of plugins with different configuration locations:
-
Docusaurus Plugins - Configured in the
plugins
field ofdocusaurus.config.js
- technical reference: https://docusaurus.io/docs/api/docusaurus-config#plugins -
Remark Plugins - Configured in the
presets
field ofdocusaurus.config.js
- technical reference: https://docusaurus.io/docs/markdown-features/plugins#installing-plugins -
Rehype Plugins - Configured in the
presets
field ofdocusaurus.config.js
- technical reference: https://docusaurus.io/docs/markdown-features/plugins#installing-plugins
Docusaurus plugins are configured through:
-
config/pluginsConfig/index.ts
- Main plugin registration -
plugins
field indocusaurus.config.js
// docusaurus.config.js
const config = {
plugins: require("./config/pluginsConfig"), // plugins of the site
};
New Docusaurus plugins are added by:
- Creating a plugin configuration file in
/config/pluginsConfig/
- Importing and adding the plugin to the plugins array in
config/pluginsConfig/index.ts
// config/pluginsConfig/index.ts
import { PluginConfig } from '@docusaurus/types';
import { openapiPlugin } from './docusaurus-plugin-openapi-docs';
import { sassPlugin } from './sass';
import { markdownPrinterPlugin } from './markdown-printer';
import { showcasePlugin } from './guide-showcase';
const plugins: PluginConfig[] = [
openapiPlugin,
sassPlugin,
markdownPrinterPlugin,
showcasePlugin,
];
Location: /config/pluginsConfig/docusaurus-plugin-openapi-docs
- Handles OpenAPI documentation rendering
- Integrates with the
docusaurus-theme-openapi-docs
theme - Used for API reference documentation
Location: /config/pluginsConfig/sass
- Enables SASS/SCSS stylesheet processing
- Allows for more maintainable styling using SASS features
Location: /config/pluginsConfig/markdown-printer
- Custom plugin for enhanced markdown processing
- Located in
/plugins/markdown-printer
Location: /config/pluginsConfig/guide-showcase
- Handles the showcase features of the documentation
- Located in
/plugins/docusaurus-plugin-showcase
Remark plugins are markdown processors configured in the presets
field of docusaurus.config.js
:
// docusaurus.config.js
const config = {
presets: require("./config/presets.js"), // Contains remark plugin configuration
};
Located in /plugins/
, we have several custom remark plugins:
Location: /plugins/remark-plugin-a11y-checker
- Checks markdown content for accessibility issues
- Ensures documentation meets accessibility standards
- Reports issues during build process
Location: /plugins/remark-plugin-api-table
- Enhances API documentation tables
- Provides consistent formatting for API endpoints
- Supports additional metadata for API documentation
Location: /plugins/remark-plugin-image-to-figure
- Converts markdown images to HTML figure elements
- Allows for better image captions and accessibility
- Enhances image presentation in documentation
Location: /plugins/remark-plugin-vfile-reporter
- Provides detailed reporting of markdown processing
- Helps identify issues in markdown files
- Useful for debugging and quality assurance
Location: /plugins/remark-plugin-yaml-and-json
- Handles YAML and JSON processing in markdown
- Enables structured data in documentation
- Supports metadata processing
Rehype plugins process HTML after markdown conversion. Like remark plugins, they are configured in the presets
field of docusaurus.config.js
:
// config/presets.js
module.exports = [
[
'classic',
{
docs: {
rehypePlugins: [
// rehype plugins would go here
],
},
},
],
];
Note: We currently do not use any rehype plugins in our documentation system. This section is provided for future reference if rehype plugins are added.
To add a new rehype plugin:
- Install the plugin package:
npm install rehype-plugin-name
- Add the plugin to the presets configuration:
// config/presets.js
module.exports = [
[
'classic',
{
docs: {
rehypePlugins: [
[require('rehype-plugin-name'), {
// plugin options
}],
],
},
},
],
];
When creating TypeScript-based plugins, they need to be built before Docusaurus can use them. This is configured in package.json
:
- Add a build script for your plugin:
{
"scripts": {
"build:new-plugin": "cd plugins/new-plugin && npm run build && cd ../../"
}
}
- Add the plugin to the
build:plugins
script chain:
{
"scripts": {
"build:plugins": "npm run build:remark-plugin-yaml-and-json && npm run build:docusaurus-plugin-showcase && npm run build:new-plugin"
}
}
Current plugin build configuration example:
{
"scripts": {
"build:docusaurus-plugin-showcase": "cd plugins/docusaurus-plugin-showcase && npm run build && cd ../../",
"build:remark-plugin-yaml-and-json": "cd plugins/remark-plugin-yaml-and-json && npm run build && cd ../../",
"build:remark-plugin-a11y-checker": "cd plugins/remark-plugin-a11y-checker && npm run build && cd ../../",
"build:remark-plugin-vfile-reporter": "cd plugins/remark-plugin-vfile-reporter && npm run build && cd ../../",
"build:remark-plugin-image-to-figure": "cd plugins/remark-plugin-image-to-figure && npm run build && cd ../../",
"build:remark-plugin-api-table": "cd plugins/remark-plugin-api-table && npm run build && cd ../../",
"build:plugins": "npm run build:remark-plugin-yaml-and-json && npm run build:docusaurus-plugin-showcase && npm run build:remark-plugin-a11y-checker && npm run build:remark-plugin-vfile-reporter && npm run build:remark-plugin-image-to-figure && npm run build:remark-plugin-api-table"
}
}
For plugins that use external dependencies:
- Add the plugin as a local dependency in the root
package.json
:
{
"dependencies": {
"docusaurus-plugin-showcase": "./plugins/docusaurus-plugin-showcase",
"docusaurus-plugin-markdown-printer": "./plugins/markdown-printer"
}
}
- Create a separate
package.json
in your plugin directory with its specific dependencies:
{
"name": "your-plugin",
"version": "1.0.0",
"dependencies": {
"specific-dependency": "^1.0.0"
}
}
The build process follows this order:
-
npm run build:plugins
runs first to compile all TypeScript plugins - Docusaurus build process runs after plugins are built
- Plugin dependencies are resolved through the root
package.json
Example of the complete build chain:
{
"scripts": {
"build": "npm run build:plugins && npm run build:root",
"start": "npm run build:plugins && docusaurus start"
}
}
- Keep plugin-specific dependencies in the plugin's own
package.json
- Add TypeScript plugins to the
build:plugins
script - Ensure plugin build scripts return to the root directory using
cd ../../
- Test plugin builds individually before adding to the main build chain
- Use consistent naming conventions for build scripts
The documentation processing pipeline follows this order:
-
Remark Processing (via presets)
- Processes markdown through configured remark plugins
- Transforms content according to plugin rules
-
Rehype Processing (via presets)
- Processes HTML output from remark
- Currently not in use, but available for future HTML transformations
-
Docusaurus Plugin Processing (via plugins)
- Handles additional functionality and features
- Manages site-wide plugin operations
- Keep Docusaurus plugin configurations in
/config/pluginsConfig/
- Configure remark and rehype plugins in the
/config/presets.js
configuration - Document plugin options and dependencies
- Test plugins in development before deploying
- Maintain consistent file naming conventions
If a plugin isn't working:
- For Docusaurus plugins:
- Check the plugin configuration in
/config/pluginsConfig/
- Verify the plugin is properly imported in
index.ts
- Check the plugin configuration in
- For remark/rehype plugins:
- Check the
/config/presets.js
configuration - Verify the plugin is properly included in the appropriate plugins array
- Check the
- Review the Docusaurus build logs for errors