Skip to content

Commit aabc0d3

Browse files
authored
Add D2 diagram support to documentation
(#241) Integrates D2 diagramming tool into the website build pipeline, enabling architecture diagrams directly in MDX files. ## Changes - **Added** **`astro-d2`** **integration** with pgflow brand colors for light/dark themes - **Created** **`.github/actions/setup-d2`** - reusable action to install D2 CLI with retry logic - **Updated CI workflow** to install D2 before building website - **Added** **`public/d2/`** **to gitignore** - SVGs are generated at build time ## How it works Write D2 diagrams in MDX files using ````d2` code blocks: ``` direction: down worker: "Edge Worker" { shape: cloud } ``` At build time: 1. `astro-d2` renders diagrams to SVG in `public/d2/` 2. Code blocks are replaced with `<img>` tags 3. Static assets deploy to Cloudflare Pages ## Example See `/concepts/how-pgflow-works/` for live diagrams showing the three-layer architecture.
1 parent e368e08 commit aabc0d3

File tree

8 files changed

+1634
-1316
lines changed

8 files changed

+1634
-1316
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'Setup D2'
2+
description: 'Install D2 diagramming tool with retry logic'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Install D2
8+
shell: bash
9+
run: |
10+
for i in 1 2 3 4 5; do
11+
echo "Attempt $i to install D2..."
12+
if curl -fsSL https://d2lang.com/install.sh | sh -s --; then
13+
echo "D2 installed successfully"
14+
break
15+
else
16+
if [ $i -eq 5 ]; then
17+
echo "Failed to install D2 after 5 attempts"
18+
exit 1
19+
fi
20+
echo "Install failed, retrying in 5 seconds..."
21+
sleep 5
22+
fi
23+
done

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ jobs:
9494
- name: Quality gate (lint + typecheck + test)
9595
run: pnpm nx affected -t lint typecheck test --parallel --configuration=production --base="$NX_BASE" --head="$NX_HEAD"
9696

97-
- name: Build all affected projects
98-
run: pnpm nx affected -t build --configuration=production --parallel --base="$NX_BASE" --head="$NX_HEAD"
97+
- name: Build all affected packages (excludes website and demo - they build during deploy)
98+
run: pnpm nx affected -t build --configuration=production --parallel --exclude=website,demo --base="$NX_BASE" --head="$NX_HEAD"
9999

100100
- name: Verify exports for built packages
101101
run: pnpm nx affected -t verify-exports --base="$NX_BASE" --head="$NX_HEAD"
@@ -306,6 +306,8 @@ jobs:
306306
github-token: ${{ secrets.GITHUB_TOKEN }}
307307
atlas-cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
308308

309+
- uses: ./.github/actions/setup-d2
310+
309311
- name: Check if website is affected
310312
id: check-affected
311313
run: |

pkgs/website/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ pnpm-debug.log*
1919

2020
# macOS-specific files
2121
.DS_Store
22+
23+
# generated files
2224
public/edge-worker/
25+
public/d2/

pkgs/website/astro.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import robotsTxt from 'astro-robots-txt';
88
import starlightLlmsTxt from 'starlight-llms-txt';
99
import starlightContextualMenu from 'starlight-contextual-menu';
1010
import starlightImageZoom from 'starlight-image-zoom';
11+
import d2 from 'astro-d2';
1112
import { fileURLToPath } from 'url';
1213
import path from 'path';
1314

@@ -70,6 +71,7 @@ export default defineConfig({
7071
redirects,
7172

7273
integrations: [
74+
d2(),
7375
react({
7476
include: ['**/components/**/*.tsx'],
7577
exclude: ['**/pages/**/*'],
@@ -433,6 +435,7 @@ export default defineConfig({
433435
'/author',
434436
'/demos',
435437
'/demo-colors',
438+
'/d2-guide',
436439
'/news',
437440
'/news/**',
438441
'/edge-worker',

pkgs/website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@types/react-dom": "^19.1.7",
2323
"@vercel/analytics": "^1.5.0",
2424
"astro": "^5.7.14",
25+
"astro-d2": "^0.8.0",
2526
"astro-robots-txt": "^1.0.0",
2627
"react": "^19.1.1",
2728
"react-dom": "^19.1.1",
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
vars: {
2+
d2-config: {
3+
theme-id: 0
4+
dark-theme-overrides: {
5+
# Canvas background
6+
N7: "#121a19"
7+
8+
# Neutrals - desaturated grays for default nodes
9+
N1: "#e8eced"
10+
N2: "#c5cacc"
11+
N3: "#95a0a3"
12+
N4: "#4a5759"
13+
N5: "#2d3739"
14+
N6: "#1a2324"
15+
16+
# Borders - neutral grays
17+
B1: "#3a4547"
18+
B2: "#4a5759"
19+
B3: "#5a6769"
20+
B4: "#1a2324"
21+
B5: "#2d3739"
22+
B6: "#4a5759"
23+
24+
# Semantic colors - intentional states
25+
AA2: "#a87c45"
26+
AA4: "#a33636"
27+
AA5: "#4d3d2b"
28+
AB4: "#247056"
29+
AB5: "#34578f"
30+
}
31+
}
32+
}
33+
34+
# Semantic color classes for workflow states
35+
classes: {
36+
# Generic semantic classes (for general use)
37+
neutral: {
38+
style.fill: "#95a0a3"
39+
style.stroke: "#4a5759"
40+
}
41+
info: {
42+
style.fill: "#34578f"
43+
style.stroke: "#5c8dd6"
44+
}
45+
warning: {
46+
style.fill: "#a87c45"
47+
style.stroke: "#d9a66e"
48+
}
49+
error: {
50+
style.fill: "#a33636"
51+
style.stroke: "#e85c5c"
52+
}
53+
success: {
54+
style.fill: "#247056"
55+
style.stroke: "#33cc7f"
56+
}
57+
58+
# Run state classes (started, completed, failed)
59+
run_started: {
60+
style.fill: "#34578f"
61+
style.stroke: "#5c8dd6"
62+
}
63+
run_completed: {
64+
style.fill: "#247056"
65+
style.stroke: "#33cc7f"
66+
}
67+
run_failed: {
68+
style.fill: "#a33636"
69+
style.stroke: "#e85c5c"
70+
}
71+
72+
# Step state classes (created, started, completed, failed)
73+
step_created: {
74+
style.fill: "#95a0a3"
75+
style.stroke: "#4a5759"
76+
}
77+
step_started: {
78+
style.fill: "#34578f"
79+
style.stroke: "#5c8dd6"
80+
}
81+
step_completed: {
82+
style.fill: "#247056"
83+
style.stroke: "#33cc7f"
84+
}
85+
step_failed: {
86+
style.fill: "#a33636"
87+
style.stroke: "#e85c5c"
88+
}
89+
90+
# Task state classes (queued, completed, failed)
91+
task_queued: {
92+
style.fill: "#95a0a3"
93+
style.stroke: "#4a5759"
94+
}
95+
task_completed: {
96+
style.fill: "#247056"
97+
style.stroke: "#33cc7f"
98+
}
99+
task_failed: {
100+
style.fill: "#a33636"
101+
style.stroke: "#e85c5c"
102+
}
103+
}

0 commit comments

Comments
 (0)