FreeTRX/website/build-docs.sh
Marcus Kida 35ba6e9975 docs: add MkDocs Material documentation website
Renders the root markdown (manual, tools, changelog) into a static, searchable
HTML site with client-side (lunr.js) search and a dark/light theme. Built in
Docker via website/build-docs.sh (no host installs). Public URL is set at build
time with SITE_URL=... (default is a neutral placeholder; the site works at any
URL since site_url only affects the sitemap/canonical links). Generated output
(website/_build/) is gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-10 13:29:29 +02:00

49 lines
1.9 KiB
Bash

#!/usr/bin/env bash
#
# Build the FreeTRX documentation website (MkDocs Material) entirely in Docker.
# Source markdown lives in the repo root; this assembles it into _build/docs and
# renders a static, self-contained HTML site with client-side search into
# website/_build/site.
#
# Usage: ./website/build-docs.sh # build
# ./website/build-docs.sh serve # live-reload preview on http://localhost:8000
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd "$HERE/.." && pwd)"
SRC="$HERE/_build/docs"
IMAGE="squidfunk/mkdocs-material:9"
# ---- assemble the docs source tree from the root markdown -----------------
rm -rf "$HERE/_build"
mkdir -p "$SRC/images"
cp "$HERE/home.md" "$SRC/index.md"
cp "$ROOT/MANUAL.md" "$SRC/MANUAL.md"
cp "$ROOT/TOOLS.md" "$SRC/TOOLS.md"
cp "$ROOT/CHANGELOG.md" "$SRC/CHANGELOG.md"
cp "$ROOT"/docs/images/*.png "$SRC/images/" 2>/dev/null || true
# MANUAL.md links back to README.md (a repo file, not a site page) -> point it at
# the site home instead.
sed -i.bak 's#(README.md)#(index.md)#g' "$SRC/MANUAL.md" && rm -f "$SRC/MANUAL.md.bak"
# Optional public URL (sitemap / canonical only). Set SITE_URL to override the
# placeholder in mkdocs.yml — the site works at any URL regardless.
ENVARGS=()
if [[ -n "${SITE_URL:-}" ]]; then
echo "==> Site URL: $SITE_URL"
ENVARGS=(-e "SITE_URL=$SITE_URL")
fi
# ---- build (or serve) -----------------------------------------------------
if [[ "${1:-}" == "serve" ]]; then
echo "==> Serving docs on http://localhost:8000 (Ctrl-C to stop)"
docker run --rm -it -p 8000:8000 "${ENVARGS[@]+"${ENVARGS[@]}"}" -v "$HERE":/docs "$IMAGE" serve -a 0.0.0.0:8000
else
echo "==> Building docs site"
docker run --rm "${ENVARGS[@]+"${ENVARGS[@]}"}" -v "$HERE":/docs "$IMAGE" build
echo
echo "==> Done. Static site (upload the *contents* of this folder):"
echo " $HERE/_build/site"
fi