DocgoDocgo
Latest
/Advanced

Plugins

Extend Docgo with config hooks, MDX transforms, and page-generation hooks.

Docgo plugins are plain objects in docgo.config.mjs.

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.

docgo.config.mjs
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.

docgo.config.mjs
export default defineConfig({
  plugins: [
    {
      name: 'replace-vars',
      transformMdx(source, context) {
        return source.replaceAll('__VERSION__', context.route);
      },
    },
  ],
});

The context includes:

FieldDescription
filePathAbsolute source file path.
routeGenerated route for the page.
srcDirAbsolute 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.

docgo.config.mjs
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.

docgo.config.mjs
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.

docgo.config.mjs
export default defineConfig({
  plugins: [
    {
      name: 'log-pages',
      onPageGenerated(page) {
        console.log(page.route, page.outputPath);
      },
    },
  ],
});

The page object contains:

FieldDescription
routePublic route.
outputPathWritten HTML file path.
sourcePathSource markdown/MDX file path.
titleFinal page title.
localeResolved locale.
versionResolved version.

Hook order

  1. Config is loaded.
  2. extendConfig hooks run in plugin order.
  3. Each page runs transformMdx hooks in plugin order.
  4. The page is rendered and written.
  5. onPageGenerated hooks 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.

Edit this page

Last updated: