Building quanhua.me: Static-First Reader with LaTeX and Mermaid
Why I built a minimal Astro + Cloudflare personal site with build-time KaTeX, conditional Mermaid, and zero unnecessary client JS.
I wanted a fast personal home on quanhua.me that feels like a clean technical reader—supporting LaTeX math, Mermaid diagrams, and interactive MDX islands without shipping an editor or a heavy theme.
Build-Time LaTeX (0 KB Client JS)
Inline math like and scaled dot-product attention render directly to HTML and CSS at build time via remark-math and rehype-katex:
Even currency values like $2.48 for year one and $19.98 for renewal stay plain text when escaped cleanly.
Conditional Mermaid Diagrams
Pages without diagrams ship 0 KB of Mermaid JavaScript. On pages that contain a diagram, Mermaid is dynamically imported and re-rendered automatically on light/dark theme switches:
flowchart LR
MD[Markdown / MDX] --> Astro[Astro Build]
Astro --> HTML[Static HTML + KaTeX + Shiki]
Astro --> API["/api/* Cloudflare Worker"]
HTML --> Edge[Cloudflare Edge]
API --> EdgeDual-Theme Code Blocks
Code blocks are highlighted at build time with Shiki using CSS variables:
export function kvCacheBytes(
layers: number,
heads: number,
headDim: number,
seqLen: number,
bytesPerParam = 2,
): number {
return 2 * layers * heads * headDim * seqLen * bytesPerParam;
}
Interactive MDX Islands
Stateful demos hydrate lazily only when scrolled into view (client:visible), leaving non-interactive posts at zero React JS:
Interactive Island · React