Skip to content

Commit bf1d664

Browse files
authored
feat: integrate D2 diagram support and update styles
- Added D2 installation script to package.json. - Replaced mermaid diagrams with D2 diagrams in blog posts. - Updated styles for D2 diagrams and removed old mermaid styles. - Created TypeScript definitions for rehype-d2. - Adjusted blog content to reflect changes in diagram syntax.
1 parent db295ea commit bf1d664

17 files changed

Lines changed: 226 additions & 422 deletions

.devcontainer/devcontainer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"BUN_INSTALL": "/home/node/.bun",
66
"PATH": "/home/node/.bun/bin:${containerEnv:PATH}"
77
},
8-
"postCreateCommand": "bash -lc 'set -e; export BUN_INSTALL=\"$HOME/.bun\"; curl -fsSL https://bun.sh/install | bash; \"$BUN_INSTALL/bin/bun\" --version; \"$BUN_INSTALL/bin/bun\" install; grep -q \"BUN_INSTALL=\\\"$HOME/.bun\\\"\" ~/.bashrc || printf \"\\nexport BUN_INSTALL=\\\"$HOME/.bun\\\"\\nexport PATH=\\\"$BUN_INSTALL/bin:$PATH\\\"\\n\" >> ~/.bashrc; grep -q \"BUN_INSTALL=\\\"$HOME/.bun\\\"\" ~/.zshrc || printf \"\\nexport BUN_INSTALL=\\\"$HOME/.bun\\\"\\nexport PATH=\\\"$BUN_INSTALL/bin:$PATH\\\"\\n\" >> ~/.zshrc'",
8+
"postCreateCommand": "bash -lc 'set -e; export BUN_INSTALL=\"$HOME/.bun\"; curl -fsSL https://bun.sh/install | bash; \"$BUN_INSTALL/bin/bun\" --version; \"$BUN_INSTALL/bin/bun\" install; curl -fsSL https://d2lang.com/install.sh | sh -s --; d2 --version; grep -q \"BUN_INSTALL=\\\"$HOME/.bun\\\"\" ~/.bashrc || printf \"\\nexport BUN_INSTALL=\\\"$HOME/.bun\\\"\\nexport PATH=\\\"$BUN_INSTALL/bin:$PATH\\\"\\n\" >> ~/.bashrc; grep -q \"BUN_INSTALL=\\\"$HOME/.bun\\\"\" ~/.zshrc || printf \"\\nexport BUN_INSTALL=\\\"$HOME/.bun\\\"\\nexport PATH=\\\"$BUN_INSTALL/bin:$PATH\\\"\\n\" >> ~/.zshrc'",
9+
"features": {
10+
"ghcr.io/devcontainer-community/devcontainer-features/astral.sh-uv:1": {}
11+
},
912
"customizations": {
1013
"vscode": {
1114
"extensions": ["astro-build.astro-vscode", "biomejs.biome"]

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
with:
1818
bun-version: latest
1919

20+
- name: Install D2 CLI
21+
run: curl -fsSL https://d2lang.com/install.sh | sh -s --
22+
2023
- name: Install dependencies
2124
run: bun install
2225

.github/workflows/pages-build-deployment.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
- name: Checkout your repository using git
2222
uses: actions/checkout@v5
2323

24+
- name: Install D2 CLI
25+
run: curl -fsSL https://d2lang.com/install.sh | sh -s --
26+
2427
- name: Install, build, and upload your site
2528
uses: withastro/action@v5
2629

.vscode/mcp.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,22 @@
4343
"command": "bunx",
4444
"args": ["-y", "@modelcontextprotocol/server-memory"]
4545
},
46-
// "github": {
47-
// "type": "stdio",
48-
// "command": "bunx",
49-
// "args": ["-y", "@modelcontextprotocol/server-github"],
50-
// "env": {
51-
// "GITHUB_PERSONAL_ACCESS_TOKEN": "YOUR_TOKEN_HERE"
52-
// }
53-
// },
46+
"github": {
47+
"type": "http",
48+
"url": "https://api.githubcopilot.com/mcp/"
49+
},
5450
"playwright": {
5551
"type": "stdio",
5652
"command": "bunx",
5753
"args": ["@playwright/mcp@latest"]
54+
},
55+
"fetch": {
56+
"command": "uvx",
57+
"args": ["mcp-server-fetch"]
58+
},
59+
"time": {
60+
"command": "uvx",
61+
"args": ["mcp-server-time"]
5862
}
5963
}
6064
}

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@
55
## Requirements
66

77
- Bun
8+
- D2 CLI (for diagram rendering)
89

910
## Setup
1011

1112
```bash
13+
# Install D2 CLI (required for diagram rendering)
14+
bun run setup:d2
15+
16+
# Install dependencies
1217
bun install
1318
```
1419

1520
## Scripts
1621

1722
```bash
18-
bun run dev
19-
bun run build
20-
bun run preview
21-
bun run lint
22-
bun run format
23+
bun run dev # Start development server
24+
bun run build # Build for production
25+
bun run preview # Preview production build
26+
bun run lint # Lint codebase
27+
bun run format # Format codebase
28+
bun run setup:d2 # Install D2 diagram CLI
2329
```

astro.config.ts

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,27 @@ import solid from "@astrojs/solid-js";
55
import tailwindcss from "@tailwindcss/vite";
66
import AstroPWA from "@vite-pwa/astro";
77
import { defineConfig } from "astro/config";
8-
import rehypeMermaid from "rehype-mermaid";
8+
import rehypeD2 from "rehype-d2";
99
import rehypeCopyCodeButton from "./src/lib/rehypeCopyCodeButton";
1010

11-
type HastNode = {
12-
type?: string;
13-
tagName?: string;
14-
properties?: Record<string, unknown>;
15-
children?: HastNode[];
16-
};
17-
18-
const rehypeMermaidAriaLabel = () => {
19-
return (tree: HastNode) => {
20-
const visit = (node: HastNode) => {
21-
if (
22-
node.type === "element" &&
23-
node.tagName === "svg" &&
24-
typeof node.properties?.id === "string" &&
25-
node.properties.id.startsWith("mermaid-")
26-
) {
27-
if (!node.properties) {
28-
node.properties = {};
29-
}
30-
31-
const properties = node.properties;
32-
if (typeof properties["aria-label"] !== "string") {
33-
properties["aria-label"] = "Mermaid diagram";
34-
}
35-
}
36-
37-
node.children?.forEach(visit);
38-
};
39-
40-
visit(tree);
41-
};
42-
};
43-
4411
// https://astro.build/config
4512
export default defineConfig({
4613
site: "https://avaabrazzaq.com", // Used to generate canonical URLs and sitemap entries.
4714
trailingSlash: "always", // Consistent URL format - all URLs end with /
4815
markdown: {
4916
syntaxHighlight: {
5017
type: "shiki",
51-
excludeLangs: ["math", "mermaid"],
18+
excludeLangs: ["math", "d2"],
5219
},
5320
rehypePlugins: [
5421
[
55-
rehypeMermaid,
22+
rehypeD2,
5623
{
57-
strategy: "inline-svg",
58-
dark: true,
24+
theme: 0,
25+
darkTheme: 200,
26+
sketch: false,
5927
},
6028
],
61-
rehypeMermaidAriaLabel,
6229
rehypeCopyCodeButton,
6330
],
6431
},
@@ -70,13 +37,13 @@ export default defineConfig({
7037
mdx({
7138
rehypePlugins: [
7239
[
73-
rehypeMermaid,
40+
rehypeD2,
7441
{
75-
strategy: "inline-svg",
76-
dark: true,
42+
theme: 0,
43+
darkTheme: 200,
44+
sketch: false,
7745
},
7846
],
79-
rehypeMermaidAriaLabel,
8047
rehypeCopyCodeButton,
8148
],
8249
}),

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.4.8/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.4.10/schema.json",
33
"formatter": {
44
"enabled": true,
55
"indentStyle": "space",

0 commit comments

Comments
 (0)