aboutsummaryrefslogtreecommitdiff
path: root/scripts/assert-spelling.sh
blob: f4ab58ed76b4a664c8d50bd47e97b55b310f4bd4 (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
#!/bin/sh -eu

export LANG=C.UTF-8

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

OUT="$(mktemp)"
jekyll build --future --trace
# shellcheck disable=2044
for f in $(find _site -type f -name '*.html'); do
  if ! echo "$f" | grep -E '^_site/vendor/' > /dev/null; then
    l="$(head -n2 "$f" | tail -n1 | cut -d\" -f2)"
    CURR_DICT="$(mktemp)"
    cat scripts/spelling/international.txt "scripts/spelling/$l.txt" > "$CURR_DICT"
    hunspell -u3 -H -d "$l" -p "$CURR_DICT" "$f" | tee -a "$OUT"
  fi
done

if [ -s "$OUT" ]; then
  printf "\nvvv Mispelled words detected by hunspell.\n\n"
  cut -d\  -f2- < "$OUT" | sort | uniq
  printf "\n^^^\n" >&2
  exit 1
else
  echo "No spelling errors detected"
  exit 0
fi