#!/usr/bin/env bash
# Finds blank (empty or whitespace-only) HTML files in books/core

DIR="$(dirname "$0")/books/core"
empty=()
whitespace_only=()

for f in "$DIR"/*.html; do
  if [ ! -s "$f" ]; then
    empty+=("$f")
  elif ! grep -qE '[^[:space:]]' "$f"; then
    whitespace_only+=("$f")
  fi
done

echo "=== Empty (0 bytes): ${#empty[@]} files ==="
for f in "${empty[@]}"; do printf '  %s\n' "$(basename "$f")"; done | sort -V

if [ ${#whitespace_only[@]} -gt 0 ]; then
  echo ""
  echo "=== Whitespace-only: ${#whitespace_only[@]} files ==="
  for f in "${whitespace_only[@]}"; do printf '  %s\n' "$(basename "$f")"; done | sort -V
fi

echo ""
echo "Total blank: $((${#empty[@]} + ${#whitespace_only[@]}))"
