#!/usr/bin/env bash

# Run spelling check
bash ./scripts/check-spelling.sh _posts && bash ./scripts/check-spelling.sh _pages
SPELL_STATUS=$?

# Run markdown lint
bash ./scripts/markdown_lint.sh _posts --fix && bash ./scripts/markdown_lint.sh _pages --fix
LINT_STATUS=$?

# Check results
if [ $SPELL_STATUS -ne 0 ] || [ $LINT_STATUS -ne 0 ]; then
  echo "Pre-commit checks failed."
  [ $SPELL_STATUS -ne 0 ] && echo "❌ Spelling check failed"
  [ $LINT_STATUS -ne 0 ] && echo "❌ Markdown linting failed"
  exit 1
fi

# Regenerate word clouds, if needed
bash ./scripts/create_wordcloud_precommit.sh

# Stage the regenerated wordcloud files for commit
git add data/wc/wordcloud-*.json

echo "✅ All pre-commit checks passed."

exit 0
