#!/bin/sh set -eu # Top-level build script — builds all ZDDC HTML tools, the zddc-server # binaries, and the bootstrap stubs published under website/bootstrap/. SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) echo "=== Building ZDDC tools ===" sh "$SCRIPT_DIR/transmittal/build.sh" "${1:-}" "${2:-}" sh "$SCRIPT_DIR/archive/build.sh" "${1:-}" "${2:-}" sh "$SCRIPT_DIR/classifier/build.sh" "${1:-}" "${2:-}" sh "$SCRIPT_DIR/mdedit/build.sh" "${1:-}" "${2:-}" sh "$SCRIPT_DIR/landing/build.sh" "${1:-}" "${2:-}" echo "" echo "=== Assembling zddc/dist/web/ ===" # Only landing and archive ship inside the server bundle: they call the # server's JSON API (GET / for the project list, directory listings for the # archive) and are useless without it. transmittal, classifier, and mdedit # are pure client-side tools that work from file:// or any static host; # they are released to website/ for download but not bundled with the server. mkdir -p "$SCRIPT_DIR/zddc/dist/web" cp "$SCRIPT_DIR/landing/dist/index.html" "$SCRIPT_DIR/zddc/dist/web/index.html" cp "$SCRIPT_DIR/archive/dist/archive.html" "$SCRIPT_DIR/zddc/dist/web/archive.html" echo "Wrote zddc/dist/web/index.html" echo "Wrote zddc/dist/web/archive.html" # Cross-compiled zddc-server binaries — only relevant if you're shipping # standalone Linux/macOS/Windows binaries to users. Skipped silently when # Go isn't on PATH. (zddc/release.sh handles the publish flow that # uploads these to Codeberg release assets.) echo "" echo "=== Building zddc-server binaries ===" if command -v go >/dev/null 2>&1; then cd "$SCRIPT_DIR/zddc" mkdir -p dist for target in linux/amd64 darwin/amd64 darwin/arm64 windows/amd64; do os="${target%/*}"; arch="${target#*/}" out="zddc-server-${os}-${arch}" case "$os" in windows) out="${out}.exe" ;; esac echo " building $out" CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" \ go build -trimpath -ldflags="-s -w" -o "dist/$out" ./cmd/zddc-server done cd "$SCRIPT_DIR" else echo "go not found — skipping cross-compiled binary build." echo " (Install Go 1.24+ to build standalone binaries.)" fi # ─── Bootstrap stubs ───────────────────────────────────────────────────────── # Generated from bootstrap/level{1,2}.html.tmpl on every build and published # as standalone files under website/bootstrap/. The website's "Install on # your server" section prints copy-pasteable shell snippets that curl these # files into the operator's deployment directory. # # bootstrap/level1/.html — same-origin stubs for # /.html (4 tools; # landing only lives at root) # bootstrap/track-/.html — level-2 stubs that fetch the # named channel from upstream # (5 tools × 3 channels = 15) WEBSITE_DIR="$SCRIPT_DIR/website" RELEASES_DIR="$WEBSITE_DIR/releases" BOOTSTRAP_DIR="$SCRIPT_DIR/bootstrap" mkdir -p "$WEBSITE_DIR" # tool|filename|title TOOL_TABLE='archive|archive.html|Archive transmittal|transmittal.html|Transmittal classifier|classifier.html|Classifier mdedit|mdedit.html|Markdown Editor landing|index.html|ZDDC' # Substitute {{TOOL}}, {{TOOL_TITLE}}, {{CHANNEL}}, {{FAVICON}} in a template. # The favicon is a base64-encoded data URI built once from shared/favicon.svg. _favicon_data_uri="" if [ -f "$SCRIPT_DIR/shared/favicon.svg" ]; then _favicon_data_uri="data:image/svg+xml;base64,$(base64 -w 0 "$SCRIPT_DIR/shared/favicon.svg")" fi render_stub() { sed \ -e "s|{{TOOL_TITLE}}|$3|g" \ -e "s|{{TOOL}}|$2|g" \ -e "s|{{CHANNEL}}|${4:-}|g" \ -e "s|{{FAVICON}}|$_favicon_data_uri|g" \ "$1" > "$5" } build_bootstrap_stubs() { _stubs="$WEBSITE_DIR/bootstrap" rm -rf "$_stubs" mkdir -p "$_stubs/level1" # Level-1 stubs (same-origin, channel-agnostic). Drop into a project # subdirectory so /.html fetches ../.html. # Landing has no level-1 stub — landing only lives at deployment root. while IFS='|' read -r _tool _file _title; do render_stub "$BOOTSTRAP_DIR/level1.html.tmpl" "$_tool" "$_title" "" \ "$_stubs/level1/$_file" done </releases/ # — no Codeberg API call, no manifest, no proxy magic. Page is static # and current as of the last `sh build.sh` run. # # zddc-server's section links to its Codeberg release pages directly # (different distribution model — per-platform binaries). build_releases_index() { _out="$RELEASES_DIR/index.html" mkdir -p "$RELEASES_DIR" { cat <<'HEAD' Releases — ZDDC

Releases

All published versions and channel builds of every ZDDC tool. Stable releases are immutable; alpha and beta channels are rebuilt without notice.

HEAD # Render one section per HTML tool, scanning website/releases/ for # _v*.html real files (per-version archives) and resolving the # current channel symlinks. for _tool_entry in 'archive|Archive' \ 'transmittal|Transmittal' \ 'classifier|Classifier' \ 'mdedit|Markdown Editor' \ 'landing|Landing (project picker)'; do _tool="${_tool_entry%%|*}" _title="${_tool_entry#*|}" # All per-version real files for this tool, semver-descending. # Use find to filter out symlinks; grep + sort -Vr for ordering. _versioned=$(find "$RELEASES_DIR" -maxdepth 1 -type f -name "${_tool}_v*.html" 2>/dev/null \ | sed "s|^${RELEASES_DIR}/||" \ | sort -Vr) if [ -z "$_versioned" ]; then continue fi printf '
\n' printf '

%s

\n' "$_title" # Channel chips — only render if the symlink exists. printf '
\n' for _ch in stable beta alpha; do _link="${_tool}_${_ch}.html" if [ -e "$RELEASES_DIR/$_link" ]; then printf ' %s\n' "$_ch" "$_link" "$_ch" fi done printf '
\n' # Pin-to-version row: every per-version real file, descending. printf '
Pin to version:\n' printf '%s\n' "$_versioned" | while read -r _f; do [ -n "$_f" ] || continue # Display as v stripped of _v prefix and .html suffix. _v="${_f#${_tool}_v}" _v="${_v%.html}" printf ' v%s\n' "$_f" "$_v" done printf '
\n' printf '
\n' done # zddc-server section — links to Codeberg release pages directly, # since binaries don't live under website/releases/. printf '
\n' printf '

zddc-server (Go file server)

\n' printf '

Binaries are published as Codeberg release assets. Pick a platform from the release page; or build from source via the helm charts under helm/.

\n' printf '

Browse zddc-server releases on Codeberg →

\n' printf '
\n' cat <<'TAIL'

Append ?v=stable, ?v=beta, ?v=alpha, ?v=0.0 (latest 0.0.x), or ?v=0.0.1 (exact) to any deployment URL to switch versions for a single request — see the home page.

TAIL } > "$_out" echo "Wrote $_out" } echo "" echo "=== Building bootstrap stubs and releases/index.html ===" build_bootstrap_stubs build_releases_index echo "" echo "=== All tools built successfully ===" echo "" echo "Server deployment package: zddc/dist/" echo " Binaries: zddc-server-{linux,darwin,windows}-*" echo " Web files: web/ (copy contents to ZDDC_ROOT)" echo "" echo "Bootstrap stubs: website/bootstrap/" echo " level1/.html — same-origin stubs for project subdirs" echo " track-{alpha,beta,stable}/ — level-2 stubs for each channel" echo "" echo "The home page's 'Install on your server' section prints copy-pasteable" echo "shell snippets that curl these files into the operator's deployment dir."