Skip to content

Configuration

The Astro D2 integration can be configured inside the astro.config.mjs configuration file of your project:

astro.config.mjs
import { defineConfig } from 'astro/config'
import astroD2 from 'astro-d2'
export default defineConfig({
integrations: [
astroD2({
// Configuration options go here.
}),
],
})

The Astro D2 integration accepts the following configuration options:

Type: AstroD2ThemeConfig

The themes to use for the generated diagrams.

Type: string
Default: 'd2'

The name of the output directory containing the generated diagrams relative to the public/ directory.

Type: boolean
Default: false

Whether the Astro D2 integration should skip the generation of diagrams.

This is useful to disable generating diagrams when deploying on platforms that do not have D2 installed or cannot be easily installed. This will require you to build and commit diagrams before deploying your site.

Read more about deploying your site in the “Deployment” guide.

Type: 'dagre' | 'elk' | 'tala'
Default: 'dagre'

Defines the layout engine to use to generate the diagrams. See the D2 documentation for more information about the available layout engines.

Type: boolean
Default: false

Whether to render the diagrams as if they were sketched by hand.

Type: number
Default: 100

The padding (in pixels) around the rendered diagrams.

Type: AstroD2FontsConfig

The fonts to use for the generated diagrams.

Type: boolean
Default: false

Whether to add an appendix to the diagrams with tooltips or links.

Type: boolean
Default: false

Defines if the SVG diagrams should be inlined in the HTML output.

By default, the diagrams are rendered using the <img> tag.

Type: AstroD2ExperimentalConfig

The experimental features to enable for the generated diagrams.

The theme configuration is an object used to configure the themes used for the generated diagrams. It accepts the following options:

Type: string
Default: '0'

The default theme to use for the diagrams.

See the D2 documentation for more information about the available themes.

Type: string | false
Default: '200'

The dark theme to use for the diagrams when the user’s system preference is set to dark mode. To disable the dark theme, set this option to false.

See the D2 documentation for more information about the available themes.

The fonts configuration is an object used to configure the fonts used for the generated diagrams. It accepts the following options:

Type: string

The relative path from the project’s root to the .ttf font file to use for the regular font.

Type: string

The relative path from the project’s root to the .ttf font file to use for the italic font.

Type: string

The relative path from the project’s root to the .ttf font file to use for the bold font.

Type: string

The relative path from the project’s root to the .ttf font file to use for the semibold font.

Experimental flags allow you to participate in feature development by reporting issues and providing feedback on features that are still in development. These features are not guaranteed to be stable and may change or be removed in any future release.

The experimental configuration is an object used to configure the experimental features to enable for the generated diagrams. It accepts the following options:

Type: boolean
Default: false

Whether to use D2.js to generate the diagrams instead of the D2 binary.

By default, the integration requires the D2 binary to be installed on the system to generate diagrams. Enabling this option allows generating diagrams using D2.js, a JavaScript wrapper around D2 to run it through WebAssembly.