|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Regenerate HTML outputs from stored JSON logs. |
| 4 | +# Processes each ./log/*.json through main.process() and writes ./html/<name>.html. |
| 5 | + |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 9 | +REPO_ROOT="${SCRIPT_DIR}" |
| 10 | +LOG_DIR="${REPO_ROOT}/log" |
| 11 | +HTML_DIR="${REPO_ROOT}/html" |
| 12 | + |
| 13 | +if [[ ! -d "${LOG_DIR}" ]]; then |
| 14 | + echo "Log directory not found: ${LOG_DIR}" >&2 |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +mkdir -p "${HTML_DIR}" |
| 19 | + |
| 20 | +if ! find "${LOG_DIR}" -maxdepth 1 -type f -name '*.json' -print -quit | grep -q .; then |
| 21 | + echo "No JSON log files found in ${LOG_DIR}; nothing to regenerate." >&2 |
| 22 | + exit 0 |
| 23 | +fi |
| 24 | + |
| 25 | +echo "Removing previous HTML outputs in ${HTML_DIR}" |
| 26 | +find "${HTML_DIR}" -maxdepth 1 -type f -name '*.html' -exec rm -f {} + |
| 27 | + |
| 28 | +( |
| 29 | + cd "${REPO_ROOT}" |
| 30 | + python3 - "${LOG_DIR}" "${HTML_DIR}" <<'PY' |
| 31 | +import json |
| 32 | +import traceback |
| 33 | +import sys |
| 34 | +from pathlib import Path |
| 35 | +
|
| 36 | +from main import process |
| 37 | +
|
| 38 | +log_dir = Path(sys.argv[1]) |
| 39 | +html_dir = Path(sys.argv[2]) |
| 40 | +
|
| 41 | +for idx, json_path in enumerate(log_dir.glob("*.json"), start=1): |
| 42 | + output_name = json_path.stem + ".html" |
| 43 | + print(f"[{idx}] Generating {output_name} from {json_path.name}", flush=True) |
| 44 | + try: |
| 45 | + with json_path.open("r", encoding="utf-8") as fh: |
| 46 | + data = json.load(fh) |
| 47 | + result = process(data, filename=output_name) |
| 48 | + output_file = html_dir / output_name |
| 49 | +
|
| 50 | + if isinstance(result, str) and result.endswith(output_name) and output_file.exists(): |
| 51 | + continue |
| 52 | + if output_file.exists(): |
| 53 | + continue |
| 54 | + print(f"Skipping {json_path.name}; process() returned: {result}", file=sys.stderr, flush=True) |
| 55 | + except Exception as exc: |
| 56 | + print(f"Skipping {json_path.name}; error encountered: {exc}", file=sys.stderr, flush=True) |
| 57 | + traceback.print_exc() |
| 58 | +
|
| 59 | +print(f"HTML regeneration complete. Files saved to {html_dir}") |
| 60 | +PY |
| 61 | +) |
0 commit comments