Engine + Framework

D2 with Hugo

Integration guide for teams shipping diagram rendering in Hugo.

D2 usage guidance

Best for

  • General diagram rendering
  • Programmatic documentation pipelines
  • Automated visual generation

Syntax tip

Keep D2 source deterministic and reusable across environments.

Quick start

Use a Hugo shortcode with resources.GetRemote to render D2 diagrams at build time.

Recommended flow

  1. Store your D2 source in code or markdown.
  2. Send source to a server-side endpoint backed by ChartQuery.
  3. Render returned SVG/PNG in Hugo pages and docs.

Typical Hugo integration path: /layouts/shortcodes/diagram.html

D2 integration details

FieldValue
EngineD2
FrameworkHugo

Hugo implementation checklist

  • Use shortcode for diagram blocks
  • Call remote renderer at build time
  • Add security allowlist for outbound requests

D2 source example

// D2 source
// Add your diagram content here

D2 in Hugo: quick comparison

Why teams usually prefer the ChartQuery API pattern over direct client-side rendering for D2 in Hugo.

Feature
Hugo native setup
ChartQuery API setup
Server-side rendering without browser dependencies
Unified output (SVG/PNG) for docs, dashboards, and emails
Consistent rendering across environments
Works with CI/CD pipelines
Fits backend-first architectures
Single rendering workflow across multiple frameworks

Ship D2 in Hugo faster

Use ChartQuery to standardize diagram rendering across your stack with one API, one workflow, and predictable output quality.

Get started with ChartQuery

Start generating charts today

No API key required to get started. Generate charts, diagrams, and more with a single HTTP request.

Get StartedView Pricing