diff --git a/Makefile b/Makefile index 3fc5f2c..b9f961d 100644 --- a/Makefile +++ b/Makefile @@ -40,9 +40,9 @@ lint-css: $(CSS_DIR)/*.css pnpm -s dlx stylelint --config linter-configs/stylelintrc.json --di --rd --rdd $(CSS_DIR)/*.css @#csslint --quiet $(CSS_DIR) -.PHONY: lint-html -lint-html: - $(VNU) --stdout --format json --skip-non-html --also-check-svg $(OUTPUT_DIR) | jq --from-file linter-configs/vnu_filter.jq +.PHONY: validate-markup +validate-markup: + $(VNU) --stdout --format json --skip-non-html --also-check-svg $(OUTPUT_DIR) | sh scripts/filter-vnu.sh .PHONY: hint hint: hugo .hintrc-local @@ -50,7 +50,7 @@ hint: hugo .hintrc-local rm .hintrc-local .PHONY: lint-local -lint-local: lint-css lint-html +lint-local: lint-css validate-markup # dev server, includes future and draft posts .PHONY: serve diff --git a/linter-configs/vnu_filter.jq b/linter-configs/vnu_filter.jq index 8bb1301..fdaa783 100644 --- a/linter-configs/vnu_filter.jq +++ b/linter-configs/vnu_filter.jq @@ -15,4 +15,4 @@ ) ) | not ) -) +) | del(..|select(. == [])) | del(..|select(. == {})) | select(. != null) diff --git a/scripts/compress.sh b/scripts/compress.sh index 316cf43..c7f03c4 100644 --- a/scripts/compress.sh +++ b/scripts/compress.sh @@ -10,7 +10,7 @@ set -e -u output_dir="$1" format="$2" -alias find_compressible='find "$output_dir" -type f \( -name "*.html" -o -name "*.xml" -o -name "*.webmanifest" -o -name "*.*.svg" \)' +alias find_compressible='find "$output_dir" -type f \( -name "*.html" -o -name "*.xhtml" -o -name "*.xml" -o -name "*.webmanifest" -o -name "*.*.svg" \)' if [ "$format" = "gzip" ]; then compress_level="$3" diff --git a/scripts/filter-vnu.sh b/scripts/filter-vnu.sh new file mode 100644 index 0000000..cf62bea --- /dev/null +++ b/scripts/filter-vnu.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# filters the Nu HTML Validator's JSON output. Operates on stdin. +set -e -u + +root_dir="$(dirname "$0")/.." +vnu_output="$(jq --from-file "$root_dir/linter-configs/vnu_filter.jq")" +if [ "$vnu_output" = '' ]; then + echo "All markup is valid" +else + echo "Markup errors found!" 1>&2 + echo "$vnu_output" + exit 1 +fi diff --git a/scripts/xhtmlize-single-file.sh b/scripts/xhtmlize-single-file.sh index 2026db1..f324d44 100644 --- a/scripts/xhtmlize-single-file.sh +++ b/scripts/xhtmlize-single-file.sh @@ -15,7 +15,7 @@ set -e -u export html_file="$1" -export tmp_file="${html_file}.tmp" +export tmp_file="$html_file.tmp" export xhtml_file=${html_file%*.html}.xhtml cleanup() { @@ -25,13 +25,17 @@ trap cleanup EXIT trap cleanup EXIT sed 7d "$html_file" | xmllint --format --encode UTF-8 --noent - -o "$tmp_file" -head -n7 "$tmp_file" >> "$xhtml_file" -cat tmp.css >>"$xhtml_file" -tail -n +8 "$tmp_file" \ - | sd '\n\t*\n(?:[\t\s]*)?' '' >>"$xhtml_file" -tail -n +2 "$xhtml_file" > "$html_file" -sed -i 5d "$xhtml_file" # busybox sed supports "-i" +{ + head -n7 "$tmp_file" + cat tmp.css + tail -n +8 "$tmp_file" \ + | sd '\n\t*\n(?:[\t\s]*)?' '' +} >>"$xhtml_file" -# the "sed 5d" deletes the now-redundant meta charset; it's the first -# thing in the . + # replace the html file with the formatted xhtml5 file, excluding the xml declaration +tail -n +2 "$xhtml_file" > "$html_file" + +# remove the redundant charset declaration from the xhtml file. It's the +# first thing in the +sed -i 5d "$xhtml_file" # busybox sed supports "-i"