aboutsummaryrefslogtreecommitdiff
path: root/spelling/check-spelling.sh
blob: 4f7549c9b946dc26e706c8768ebfd4d4455a112c (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
set -Eeuo pipefail

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

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

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

cat spelling/*.txt > dicts.txt
check() {
  html="$1"
  echo "$1"
  hunspell -l -p dicts.txt -d fr_FR -d en_US -i utf-8 "$html" | tee -a spelling.txt
}
export -f check
find "${HTML_DIR}" -type f -name '*.html' -print0 | xargs -0 -I{} bash -c "check {}" \;

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