Plugins
Extend Docgo with config hooks, MDX transforms, and page-generation hooks.
Docgo plugins are plain objects in docgo.config.mjs.
export default defineConfig({
plugins: [
{
name: 'my-plugin',
},
],
});Plugins can implement several hooks.
extendConfig
extendConfig receives the resolved config and can return a modified config.
export default defineConfig({
plugins: [
{
name: 'site-defaults',
extendConfig(config) {
return {
...config,
baseUrl: '/docs/',
seo: {
...config.seo,
jsonLd: true,
},
};
},
},
],
});The hook may be async.
extendConfig: async config => {
return { ...config, title: 'Loaded from API' };
};transformMdx
transformMdx runs before Markdown preprocessing and MDX evaluation.
export default defineConfig({
plugins: [
{
name: 'replace-vars',
transformMdx(source, context) {
return source.replaceAll('__VERSION__', context.route);
},
},
],
});The context includes:
| Field | Description |
|---|---|
filePath | Absolute source file path. |
route | Generated route for the page. |
srcDir | Absolute docs source root. |
Use this for small source transforms, tokens, generated notices, or content normalization.
remarkPlugins and rehypePlugins
Use these hooks to add unified plugins to the Markdown/HTML pipeline.
export default defineConfig({
plugins: [
{
name: 'markdown-extensions',
remarkPlugins: [myRemarkPlugin],
rehypePlugins: context => [[myRehypePlugin, { route: context.route }]],
},
],
});Docgo's built-in Markdown plugins still run first.
viteConfig
viteConfig receives Docgo's internal Vite config and may return a partial
config to merge.
export default defineConfig({
plugins: [
{
name: 'vite-aliases',
viteConfig(config) {
return {
resolve: {
alias: {
'@components': '/absolute/path/to/components',
},
},
};
},
},
],
});onPageGenerated
onPageGenerated runs after a page's HTML and markdown mirror are written.
export default defineConfig({
plugins: [
{
name: 'log-pages',
onPageGenerated(page) {
console.log(page.route, page.outputPath);
},
},
],
});The page object contains:
| Field | Description |
|---|---|
route | Public route. |
outputPath | Written HTML file path. |
sourcePath | Source markdown/MDX file path. |
title | Final page title. |
locale | Resolved locale. |
version | Resolved version. |
Hook order
- Config is loaded.
extendConfighooks run in plugin order.- Each page runs
transformMdxhooks in plugin order. - The page is rendered and written.
onPageGeneratedhooks run in plugin order.
Keep plugins focused
Plugins run during builds and development. Keep them deterministic and avoid slow network calls unless the result is cached or required for every page.
