garden/scripts/prebuild-fetch.sh
Vigilio Desto 5703e606d0
garden: port content, rebuild public/, add new scripts and features
- Ported Ludo profile from vault to garden
- Added auto-rebuild watcher scripts
- Updated static data snapshots
- Added garden-features.js and api-garden.json
- Added GARDEN-CONTENT-GAPS.md for tracking
- Rebuilt Hugo public/ output
2026-06-08 02:11:24 +02:00

46 lines
No EOL
1.2 KiB
Bash
Executable file

#!/bin/bash
# prebuild-fetch.sh — Fetch Estate API data at build time and save as static JSON
#
# Called before `hugo` to populate static/data/ with API snapshots.
# The estate.js client reads from /data/*.json as the primary source.
#
# Usage: bash scripts/prebuild-fetch.sh
set -euo pipefail
DIR="$(cd "$(dirname "$0")/.." && pwd)"
DATA_DIR="${DIR}/static/data"
API_HOST="${API_HOST:-http://127.0.0.1:8000}"
API_KEY="trentuna-estate-key-2026"
mkdir -p "$DATA_DIR"
ENDPOINTS=(
"summary"
"health"
"disk"
"events?limit=10"
"repos"
"providers"
"builds"
"trends?limit=5"
"state"
"api/garden"
)
echo "→ Fetching Estate API data for garden build…"
for ep in "${ENDPOINTS[@]}"; do
filename="$(echo "$ep" | sed 's/[?&=/]/-/g' | sed 's/--*/-/g' | sed 's/^-//')"
url="${API_HOST}/${ep}"
if json=$(curl -sf -H "X-API-Key: ${API_KEY}" "$url" 2>/dev/null); then
echo "$json" > "${DATA_DIR}/${filename}.json"
echo "${ep}${filename}.json ($(echo "$json" | wc -c) bytes)"
else
echo "${ep} — API unreachable"
echo '{"error":true,"message":"API unavailable at build time"}' > "${DATA_DIR}/${filename}.json"
fi
done
echo "→ Done. ${#ENDPOINTS[@]} endpoints cached."