aboutsummaryrefslogtreecommitdiff
path: root/scripts/tidy-content.sh
blob: 53533a1bb605ea285d6cc6ac754b5aea50ab7c3b (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
38
39
40
#!/usr/bin/env bash
set -Eeuo pipefail

end="\033[0m"
red="\033[0;31m"
red() { echo -e "${red}${1}${end}"; }

usage() {
  red "Missing argument <${1}>.\n"
  cat <<EOF
Usage:
    $0 <INPUT_DIR>

    Arguments:
        INPUT_DIR        Input directory with the static HTML to be tidy-ed

Examples:
    $0 _site/
EOF
}

INPUT_DIR="${1:-}"
[[ -z "${INPUT_DIR}" ]] && {
  usage 'INPUT_DIR'
  exit 2
}

format() {
  FILE="${1}"
  # mktemp
  if ! tidy -utf8 -indent -modify "${FILE}" 2>> tmp-error.txt; then
    cat <(echo "${FILE}") tmp-error.txt >> errors.txt
    echo "Error in formatting '${FILE}'. See errors.txt for more detail."
    exit 1
  fi
}
export -f format

find "${INPUT_DIR}" -type f -name '*.html' -print0 | \
  xargs -0 -I{} bash -c "format {}"