aboutsummaryrefslogblamecommitdiff
path: root/scripts/tidy-content.sh
blob: 2ccb9259b7922124f3512db5a334635cc2d67a56 (plain) (tree)




























                                                                           

                                                             
                                             






                                                      
#!/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}"
  echo "${FILE}" >&2
  if ! tidy --quiet yes -utf8 -indent -modify "${FILE}"; then
    echo "Error in formatting '${FILE}'." >&2
    exit 1
  fi
}
export -f format

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