commit b7b8f7fb2a21edff11a27c9752013a312f35714e
parent b0cb964d419f9e147b0759f43bec4c71cb37393a
Author: Henry Unite <unitehenry@gmail.com>
Date: Sat, 28 Nov 2026 19:37:12 +0000
feat(stagit): add static git page generator
Generate source browser pages from the project details in build/index.html and deploy them with the site.
Diffstat:
7 files changed, 445 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
@@ -73,7 +73,15 @@ jobs:
- name: Install gcc
run: |
sudo apt-get update
- sudo apt-get install -y build-essential gcc g++
+ sudo apt-get install -y build-essential gcc g++ libgit2-dev pkg-config
+
+ - name: Install stagit
+ run: |
+ curl -sL https://deb.debian.org/debian/pool/main/s/stagit/stagit_1.3.orig.tar.gz | tar xz
+ make -C stagit-1.3 \
+ LIBGIT_INC="$(pkg-config --cflags libgit2)" \
+ LIBGIT_LIB="$(pkg-config --libs libgit2)"
+ sudo make -C stagit-1.3 install
- name: Install htmlq
run: |
@@ -85,11 +93,14 @@ jobs:
uses: pandoc/actions/setup@v1
- name: Make scripts executable
- run: chmod +x scripts/generate scripts/rss
+ run: chmod +x scripts/generate scripts/rss scripts/stagit
- name: Generate site
run: ./scripts/generate
+ - name: Generate stagit pages
+ run: ./scripts/stagit
+
- name: Generate rss feed
run: ./scripts/rss > build/blog/rss.xml
diff --git a/.gitignore b/.gitignore
@@ -1,4 +1,5 @@
site
build
static/fonts
+/.cache
*.sw*
diff --git a/README.md b/README.md
@@ -8,6 +8,25 @@ A custom static site generator written in C.
scripts/generate
```
+### Static Git Pages
+
+Generate static [`stagit`](https://codemadness.org/git/stagit/file/README.html)
+pages for the projects listed in `content/index.md`:
+
+```bash
+scripts/generate
+scripts/stagit
+```
+
+`stagit` reads the generated `build/index.html` with `htmlq`, so the site must
+be generated first. Projects without a GitHub link are skipped. The pages are
+written to `build/git`. Repositories are mirrored under `.cache/stagit/repos`,
+so later runs only fetch new commits.
+
+Generated pages are styled with `static/git/style.css` and deployed by the
+build workflow. The git pages require `stagit`,
+[`libgit2`](https://libgit2.org), and [`htmlq`](https://github.com/mgdm/htmlq).
+
### Dependencies
The following dependencies are required to run this program:
diff --git a/scripts/stagit b/scripts/stagit
@@ -0,0 +1,174 @@
+#!/usr/bin/env bash
+
+# Generate static stagit pages for the projects listed in content/index.md.
+#
+# The project metadata is read from the generated build/index.html with htmlq,
+# so run scripts/generate first. Projects without a GitHub link are skipped.
+#
+# Repositories are mirrored into .cache/stagit/repos so subsequent runs only
+# fetch new commits. The generated site is written to build/git and can be
+# served by any static file server.
+#
+# Environment variables:
+# STAGIT_HTML generated site HTML (default: build/index.html)
+# STAGIT_CACHE repository cache directory (default: .cache/stagit)
+# STAGIT_OUTPUT output directory (default: build/git)
+# STAGIT_BASE_URL public URL of the output (default: https://unitehenry.com/git)
+# STAGIT_BIN path to stagit (default: stagit)
+# STAGIT_INDEX_BIN path to stagit-index (default: stagit-index)
+
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+INDEX="${STAGIT_HTML:-$ROOT/build/index.html}"
+
+CACHE_DIR="${STAGIT_CACHE:-$ROOT/.cache/stagit}"
+REPO_DIR="$CACHE_DIR/repos"
+OUT_DIR="${STAGIT_OUTPUT:-$ROOT/build/git}"
+ASSET_DIR="$ROOT/static/git"
+BASE_URL="${STAGIT_BASE_URL:-https://unitehenry.com/git}"
+
+STAGIT_BIN="${STAGIT_BIN:-stagit}"
+STAGIT_INDEX_BIN="${STAGIT_INDEX_BIN:-stagit-index}"
+
+if ! command -v "$STAGIT_BIN" >/dev/null 2>&1; then
+ echo "error: $STAGIT_BIN not found" >&2
+ echo "install stagit or set STAGIT_BIN" >&2
+ exit 1
+fi
+
+if ! command -v "$STAGIT_INDEX_BIN" >/dev/null 2>&1; then
+ echo "error: $STAGIT_INDEX_BIN not found" >&2
+ echo "install stagit or set STAGIT_INDEX_BIN" >&2
+ exit 1
+fi
+
+if ! command -v htmlq >/dev/null 2>&1; then
+ echo "error: htmlq not found (required to parse $INDEX)" >&2
+ exit 1
+fi
+
+if [ ! -f "$INDEX" ]; then
+ echo "error: $INDEX not found (run scripts/generate first)" >&2
+ exit 1
+fi
+
+for asset in style.css logo.png favicon.png; do
+ if [ ! -f "$ASSET_DIR/$asset" ]; then
+ echo "error: $ASSET_DIR/$asset not found" >&2
+ exit 1
+ fi
+done
+
+STAGIT_BIN="$(command -v "$STAGIT_BIN")"
+STAGIT_INDEX_BIN="$(command -v "$STAGIT_INDEX_BIN")"
+
+# Read project details from the generated index. Only details with both a local
+# git link and a GitHub link are considered.
+parse_projects() {
+ htmlq -f "$INDEX" -r '#blog ~ details' 'details' |
+ awk '
+ /<details>/ {
+ inblock = 1
+ block = $0 "\n"
+ next
+ }
+
+ inblock {
+ block = block $0 "\n"
+ }
+
+ inblock && /<\/details>/ {
+ if (block ~ /href="\/git\//) printf "%s%c", block, 0
+ inblock = 0
+ block = ""
+ }
+ ' |
+ while IFS= read -r -d '' block; do
+ git_href="$(printf '%s\n' "$block" | htmlq -a href 'summary a[href^="/git/"]' | sed -n '1p')"
+ gh_href="$(printf '%s\n' "$block" | htmlq -a href 'summary a[href^="https://github.com/"]' | sed -n '1p')"
+
+ [ -n "$git_href" ] && [ -n "$gh_href" ] || continue
+
+ name="$(printf '%s\n' "$git_href" | sed -E 's|^/git/([^/]+)/.*|\1|')"
+ owner="$(printf '%s\n' "$gh_href" | sed -E 's|^https://github\.com/([^/]+)/.*|\1|')"
+ description="$(printf '%s\n' "$block" | htmlq -t 'p' | tr '\t\r\n' ' ' | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//')"
+
+ printf '%s\t%s\t%s\t%s\n' "$name" "$description" "$owner" "$gh_href"
+ done
+}
+
+mkdir -p "$REPO_DIR" "$OUT_DIR"
+
+repo_dirs=()
+
+if ! project_rows="$(parse_projects)"; then
+ exit 1
+fi
+
+while IFS=$'\t' read -r name description owner url; do
+ [ -n "$name" ] || continue
+
+ if [ -z "$url" ]; then
+ printf 'Skipping %s (no repository URL)\n' "$name" >&2
+ continue
+ fi
+
+ if [[ ! "$name" =~ ^[A-Za-z0-9._-]+$ ]]; then
+ echo "error: invalid repository name: $name" >&2
+ exit 1
+ fi
+
+ if [ -z "$description" ]; then
+ description="$name"
+ fi
+
+ repo_dir="$REPO_DIR/$name.git"
+
+ if [ -d "$repo_dir" ]; then
+ printf 'Updating %s...\n' "$name"
+ git --git-dir="$repo_dir" remote update --prune
+ else
+ printf 'Cloning %s...\n' "$name"
+ git clone --quiet --mirror "$url" "$repo_dir"
+ fi
+
+ printf '%s\n' "$description" >"$repo_dir/description"
+ printf '%s\n' "$owner" >"$repo_dir/owner"
+ printf '%s\n' "$url" >"$repo_dir/url"
+
+ repo_dirs+=("$repo_dir")
+done <<<"$project_rows"
+
+if [ "${#repo_dirs[@]}" -eq 0 ]; then
+ echo "error: no repositories found in $INDEX" >&2
+ exit 1
+fi
+
+mkdir -p "$OUT_DIR"
+
+for repo_dir in "${repo_dirs[@]}"; do
+ name="$(basename "$repo_dir" .git)"
+
+ printf 'Generating %s...\n' "$name"
+
+ rm -rf "$OUT_DIR/$name"
+ mkdir -p "$OUT_DIR/$name"
+
+ (
+ cd "$OUT_DIR/$name"
+ "$STAGIT_BIN" -u "$BASE_URL/$name/" "$repo_dir"
+
+ # Assets are copied rather than symlinked so the build artifact works on
+ # hosts that do not preserve symlinks.
+ cp "$ASSET_DIR/style.css" "$ASSET_DIR/logo.png" "$ASSET_DIR/favicon.png" .
+ )
+done
+
+printf 'Generating index...\n'
+
+"$STAGIT_INDEX_BIN" "${repo_dirs[@]}" >"$OUT_DIR/index.html"
+
+cp "$ASSET_DIR/style.css" "$ASSET_DIR/logo.png" "$ASSET_DIR/favicon.png" "$OUT_DIR"
+
+printf 'Generated %s\n' "$OUT_DIR"
diff --git a/static/git/favicon.png b/static/git/favicon.png
Binary files differ.
diff --git a/static/git/logo.png b/static/git/logo.png
Binary files differ.
diff --git a/static/git/style.css b/static/git/style.css
@@ -0,0 +1,238 @@
+:root {
+ font-family:
+ Departure Mono,
+ monospace;
+ font-synthesis: none;
+ text-rendering: optimizeLegibility;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ color-scheme: light dark;
+
+ --amber: #ffa133;
+ --pumpkin: #e47b1a;
+ --periwinkle: #8f99fb;
+ --enamel: #eeeeee;
+ --ash: #8e8e8e;
+ --mud: #8a8a6f;
+ --clay: #6c6c58;
+ --smoke: #666666;
+ --dark: #444444;
+ --carbon: #222222;
+
+ --link: blue;
+ --border: var(--smoke);
+ --accent: var(--amber);
+ --fg: var(--dark);
+ --bg: var(--enamel);
+ --muted: var(--clay);
+ --hover: #e4e4e4;
+ --add: #d9f2d0;
+ --del: #f6d5d8;
+}
+
+@media (prefers-color-scheme: dark) {
+ :root {
+ --border: var(--mud);
+ --link: var(--periwinkle);
+ --fg: var(--enamel);
+ --bg: var(--carbon);
+ --muted: #bccabb;
+ --hover: #2c2c2c;
+ --add: #173d1c;
+ --del: #4a1f24;
+ }
+}
+
+@font-face {
+ font-family: DepartureMono;
+ src:
+ url("/fonts/DepartureMono-1.500/DepartureMono-Regular.woff2")
+ format("woff2"),
+ url("/fonts/DepartureMono-1.500/DepartureMono-Regular.woff") format("woff"),
+ url("/fonts/DepartureMono-1.500/DepartureMono-Regular.otf")
+ format("opentype");
+}
+
+* {
+ box-sizing: border-box;
+}
+
+body {
+ max-width: 960px;
+ margin: 0 auto;
+ padding: 2rem;
+ color: var(--fg);
+ background-color: var(--bg);
+ font-size: 0.9rem;
+ line-height: 1.5;
+}
+
+a {
+ color: var(--link);
+ text-decoration: none;
+}
+
+a:hover {
+ text-decoration: underline;
+}
+
+h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+ font-size: 1em;
+ margin: 1rem 0 0.5rem;
+}
+
+h1 {
+ color: var(--accent);
+}
+
+img,
+h1,
+h2 {
+ vertical-align: middle;
+}
+
+img {
+ border: 0;
+}
+
+hr {
+ border: 0;
+ border-top: 1px dashed var(--border);
+ height: 1px;
+ margin: 1rem 0;
+}
+
+table {
+ border-collapse: collapse;
+ width: 100%;
+}
+
+table thead td {
+ font-weight: bold;
+ border-bottom: 1px solid var(--border);
+}
+
+table td {
+ padding: 0.15rem 0.4rem;
+ vertical-align: top;
+}
+
+#branches tr:hover td,
+#tags tr:hover td,
+#index tr:hover td,
+#log tr:hover td,
+#files tr:hover td {
+ background-color: var(--hover);
+}
+
+#content table td {
+ white-space: nowrap;
+}
+
+#index tr td:nth-child(2),
+#tags tr td:nth-child(3),
+#branches tr td:nth-child(3),
+#log tr td:nth-child(2) {
+ white-space: normal;
+}
+
+td.num {
+ text-align: right;
+}
+
+.desc {
+ color: var(--muted);
+}
+
+.url a {
+ overflow-wrap: anywhere;
+}
+
+#content pre {
+ margin: 0;
+ overflow-x: auto;
+}
+
+#blob a {
+ color: var(--muted);
+}
+
+#blob a.line {
+ display: inline-block;
+ min-width: 4ch;
+ margin-right: 1ch;
+ text-align: right;
+ user-select: none;
+}
+
+#blob a:target,
+#blob a.line:hover {
+ color: var(--accent);
+}
+
+a.d,
+a.h,
+a.i,
+a.line {
+ text-decoration: none;
+}
+
+a.i {
+ background-color: var(--add);
+}
+
+a.d {
+ background-color: var(--del);
+}
+
+a.h {
+ color: var(--accent);
+}
+
+.A,
+.M,
+.D,
+.R,
+.C,
+.T,
+.U,
+.X {
+ font-weight: bold;
+}
+
+.A,
+.i {
+ color: #1d7a32;
+}
+
+.D,
+.d {
+ color: #b4232f;
+}
+
+@media (prefers-color-scheme: dark) {
+ .A,
+ .i {
+ color: #7ddb91;
+ }
+
+ .D,
+ .d {
+ color: #ff8a95;
+ }
+}
+
+@media screen and (max-width: 800px) {
+ body {
+ padding: 1rem;
+ }
+
+ #content {
+ overflow-x: auto;
+ }
+}