A template for building "X by Example" websites — hands-on introductions to a programming language through annotated example programs, in the style of gobyexample.com.
Built with Astro and Tailwind CSS v4.
- Two-column examples: explanation on the left, code on the right, aligned segment by segment (stacks on mobile)
- Markdown-driven: examples are plain
.mdfiles in a content collection - Categories: optionally group examples on the index page
- Dark/light mode: nightfox palettes (dawnfox/terafox) for both the site
and syntax highlighting, persisted to
localStorage - Batteries included: Shiki syntax highlighting, Fontsource fonts (Karla + JetBrains Mono) via Astro's font provider, Lucide icons, ESLint + Prettier
npm install
npm run dev- Site config — edit
src/consts.ts(SITE_TITLE,SITE_DESCRIPTION,SITE_AUTHOR,GITHUB_URL). - Content — replace the files in
src/content/examples/with your own (see below). - Theme — swap the palettes in
src/plugins/shiki-themes.mjsand the CSS variables insrc/styles/global.css. - Favicon — replace
public/favicon.svg. - Deployment — set
site(andbaseif needed) inastro.config.mjs.
Each example is a Markdown file in src/content/examples/:
---
title: Hello World
order: 1
category: Basics # optional
---
Explanatory text goes here. The code block that follows a block of text is
rendered beside it in the right column.
`js
console.log("hello world");
`
More text, then more code — each pair becomes a row.Frontmatter fields:
| Field | Required | Purpose |
|---|---|---|
title |
yes | Page title and index link text |
order |
yes | Sort order (also drives prev/next navigation) |
category |
no | Group heading on the index page; omit for no group |
Use the language's code fence (```rust, ```python, …) for
correct syntax highlighting.
| Command | Action |
|---|---|
npm run dev |
Start dev server at localhost:4321 |
npm run build |
Build production site to ./dist/ |
npm run preview |
Preview the production build locally |
npm run lint |
Lint with ESLint (lint:fix to autofix) |
npm run format |
Format with Prettier (format:check to CI) |
See CONTRIBUTING.md.
CC0 1.0 Universal — public domain dedication. Use it however you want, no attribution required.