aboutsummaryrefslogblamecommitdiff
path: root/spelling/check-spelling.sh
blob: 3ddfd2a509a2c5857e65ab58cc0940ccb1dbec0d (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                      
                                          
                                                                
                                                              



          







                                                                                                             








                                                              
#!/usr/bin/env bash
set -Eeuo pipefail

HTML_DIR="${1:-}"
[[ -z "${HTML_DIR}" ]] && {
  echo 'Undefined input HTML_DIR.' >&2
  exit 2
}

# Required by =sort= and =hunspell=
export LANG=C.UTF-8

for DICT in spelling/*.txt; do
  diff <(sort "$DICT" | uniq) "$DICT" || {
    echo "The $DICT dictionary is unsorted. To fix it, run:" >&2
    echo "  LANG=C.UTF-8 sort $DICT | uniq | sponge $DICT" >&2
    exit 1
  }
done

rm -f spelling.txt
shopt -s globstar
for f in "${HTML_DIR}"/**/*.html; do
  if ! grep -E '/pastebin(/|s.html)' <(echo "$f") > /dev/null; then
    l="$(head -n2 "$f" | tail -n1 | cut -d\" -f2)"
    hunspell -u3 -H -d "$l" -p <(cat spelling/international.txt "spelling/$l.txt") "$f" | tee -a spelling.txt
  fi
done

if [[ -s spelling.txt ]]; then
  printf "\nvvv Mispelled words detected by hunspell.\n\n" >&2
  sort < spelling.txt | uniq >&2
  printf "\n^^^\n" >&2
  exit 1
else
  echo "No words mispelled" >&2
fi