#!/usr/bin/env sh
# Build docs/help.pdf from docs/help.md.
# Requires: pandoc, chromium (headless print-to-PDF).
set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
# HTML next to docs/help.md so relative image paths (e.g. images/help/*.svg) resolve.
HTML="$ROOT/docs/.help-print.html"
trap 'rm -f "$HTML"' EXIT

pandoc "$ROOT/docs/help.md" -s \
  --css="$ROOT/scripts/help-pdf.css" \
  --metadata title="LED controller — user guide" \
  -o "$HTML"

chromium --headless --no-sandbox --disable-gpu \
  --print-to-pdf="$ROOT/docs/help.pdf" \
  "file://${HTML}"

echo "Wrote $ROOT/docs/help.pdf ($(wc -c < "$ROOT/docs/help.pdf") bytes)"
