From 381ac1fc3d98ecd0b6f5215c54f907eac6d2b873 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Wed, 12 Feb 2020 09:26:16 -0300 Subject: html tidy wip --- scripts/tidy-content.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 scripts/tidy-content.sh (limited to 'scripts') diff --git a/scripts/tidy-content.sh b/scripts/tidy-content.sh new file mode 100755 index 0000000..53533a1 --- /dev/null +++ b/scripts/tidy-content.sh @@ -0,0 +1,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 < + + 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 {}" -- cgit v1.2.3 From 8796f1ac4cba340633c67eb16e1a20b69c11e929 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Fri, 14 Feb 2020 22:59:08 -0300 Subject: Fix call of tidy: run in quiet mode --- scripts/tidy-content.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/tidy-content.sh b/scripts/tidy-content.sh index 53533a1..e9bc577 100755 --- a/scripts/tidy-content.sh +++ b/scripts/tidy-content.sh @@ -27,10 +27,9 @@ INPUT_DIR="${1:-}" 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." + echo "${FILE}" >&2 + if ! tidy --quiet yes -utf8 -indent -modify "${FILE}"; then + echo "Error in formatting '${FILE}'. See errors.txt for more detail." >&2 exit 1 fi } -- cgit v1.2.3 From c293692321f83ca11542eb3a4f795e8f140246dd Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Fri, 14 Feb 2020 23:01:07 -0300 Subject: Remove old error tidy message --- scripts/tidy-content.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/tidy-content.sh b/scripts/tidy-content.sh index e9bc577..2ccb925 100755 --- a/scripts/tidy-content.sh +++ b/scripts/tidy-content.sh @@ -29,7 +29,7 @@ format() { FILE="${1}" echo "${FILE}" >&2 if ! tidy --quiet yes -utf8 -indent -modify "${FILE}"; then - echo "Error in formatting '${FILE}'. See errors.txt for more detail." >&2 + echo "Error in formatting '${FILE}'." >&2 exit 1 fi } -- cgit v1.2.3 From 43a9e4eb977477275086b65bc5337f520499e08e Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Fri, 14 Feb 2020 23:06:27 -0300 Subject: Improve error message of tidy-content.sh --- default.nix | 6 +++++- scripts/tidy-content.sh | 8 ++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/default.nix b/default.nix index 537c2ae..2f10691 100644 --- a/default.nix +++ b/default.nix @@ -37,7 +37,11 @@ in rec { buildPhase = '' patchShebangs . jekyll build -d $out - ./scripts/tidy-content.sh $out + ./scripts/tidy-content.sh $out || { + echo 'Error in formatting HTML. Reproduce with: ' + echo ' jekyll build && ./scripts/tidy-content.sh _site/' + exit 1 + } ''; }); }; diff --git a/scripts/tidy-content.sh b/scripts/tidy-content.sh index 2ccb925..6dc13c6 100755 --- a/scripts/tidy-content.sh +++ b/scripts/tidy-content.sh @@ -26,12 +26,8 @@ INPUT_DIR="${1:-}" } format() { - FILE="${1}" - echo "${FILE}" >&2 - if ! tidy --quiet yes -utf8 -indent -modify "${FILE}"; then - echo "Error in formatting '${FILE}'." >&2 - exit 1 - fi + echo "${1}" >&2 + tidy --quiet yes -utf8 -indent -modify "${1}" } export -f format -- cgit v1.2.3