#!/bin/bash # ============================================================================ # convert_help_page.sh - Regenerates the in-app help page content # ---------------------------------------------------------------------------- # Converts documentatie/Manual-Utilizare-DigiServer.md into the HTML fragment # that the Flask app serves at /help, and refreshes the screenshot copies. # # Run this whenever the manual is edited, then rebuild the image: # ./documentatie/convert_help_page.sh # cd .. && docker compose up -d --build # ============================================================================ set -euo pipefail PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" SRC_MD="$PROJECT_DIR/documentatie/Manual-Utilizare-DigiServer.md" SRC_IMG_DIR="$PROJECT_DIR/documentatie/screenshots" DEST_DIR="$PROJECT_DIR/app/static/help" DEST_IMG_DIR="$DEST_DIR/screenshots" DEST_HTML="$DEST_DIR/_manual_body.html" echo "============================================================" echo " Regenerare pagina Ajutor (/help)" echo "============================================================" echo # --------------------------------------------------------------------------- # Checks # --------------------------------------------------------------------------- if ! command -v pandoc &> /dev/null; then echo "✗ Pandoc nu este instalat." echo " Instalati cu: sudo apt-get install -y pandoc" exit 1 fi if [ ! -f "$SRC_MD" ]; then echo "✗ Nu am gasit manualul: $SRC_MD" exit 1 fi mkdir -p "$DEST_IMG_DIR" # --------------------------------------------------------------------------- # 1. Convert Markdown -> HTML fragment # --------------------------------------------------------------------------- echo "[1/3] Conversie Markdown -> HTML..." pandoc "$SRC_MD" \ -t html5 \ --no-highlight \ --wrap=none \ -o "$DEST_HTML" echo " ✓ $(basename "$DEST_HTML")" # --------------------------------------------------------------------------- # 2. Copy screenshots and rewrite their paths for Flask's static route # --------------------------------------------------------------------------- echo echo "[2/3] Copiere capturi de ecran si rescriere cai..." cp "$SRC_IMG_DIR"/*.png "$DEST_IMG_DIR"/ 2>/dev/null || { echo " ⚠ Nicio captura gasita in $SRC_IMG_DIR" } COUNT=$(ls -1 "$DEST_IMG_DIR"/*.png 2>/dev/null | wc -l) echo " ✓ $COUNT capturi copiate" # Markdown references images as "screenshots/x.png"; the app serves them from # /static/help/screenshots/, so the prefix has to be made explicit. sed -i 's|src="screenshots/|src="/static/help/screenshots/|g' "$DEST_HTML" REFS=$(grep -c '/static/help/screenshots/' "$DEST_HTML" || true) echo " ✓ $REFS referinte de imagini rescrise" # --------------------------------------------------------------------------- # 3. Sanity check: every referenced image must exist # --------------------------------------------------------------------------- echo echo "[3/3] Verificare consistenta..." MISSING=0 while IFS= read -r ref; do [ -z "$ref" ] && continue if [ ! -f "$DEST_IMG_DIR/$(basename "$ref")" ]; then echo " ✗ lipsa: $ref" MISSING=$((MISSING + 1)) fi done < <(grep -oE '/static/help/screenshots/[^"]+' "$DEST_HTML" | sort -u || true) if [ "$MISSING" -eq 0 ]; then echo " ✓ toate imaginile referite exista" else echo " ⚠ $MISSING imagini lipsa" fi echo echo "============================================================" echo " Gata. Rebuild imaginea pentru a aplica modificarile:" echo " cd $PROJECT_DIR && docker compose up -d --build" echo "============================================================"