1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-12-24 01:42:10 +00:00

Internal: improve scripts

- I forgot to compress xhtml files. fix that.

- Stylistic change: remove unnecessary brace expansions
- Don't repeatedly append to a file; run commands in a different scope
  and write all at once.

Move Nu HTML validator filtering into a shell script:
- Return a bad exit code if validation errors are found after filtering
- Remove null-ish values from the JSON output; the final output *should*
  be an empty string, since nothing should be reported.
This commit is contained in:
Rohan Kumar 2022-06-02 17:18:13 -07:00
parent b02a619260
commit cb26956bca
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479
5 changed files with 33 additions and 16 deletions

View file

@ -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

View file

@ -15,4 +15,4 @@
)
) | not
)
)
) | del(..|select(. == [])) | del(..|select(. == {})) | select(. != null)

View file

@ -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"

13
scripts/filter-vnu.sh Normal file
View file

@ -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

View file

@ -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 '<pre(?: tabindex="0")?>\n\t*<code ' '<pre tabindex="0"><code ' \
| sd '(?:\n)?</code>\n(?:[\t\s]*)?</pre>' '</code></pre>' >>"$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 '<pre(?: tabindex="0")?>\n\t*<code ' '<pre tabindex="0"><code ' \
| sd '(?:\n)?</code>\n(?:[\t\s]*)?</pre>' '</code></pre>'
} >>"$xhtml_file"
# the "sed 5d" deletes the now-redundant meta charset; it's the first
# thing in the <head>.
# 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 <head>
sed -i 5d "$xhtml_file" # busybox sed supports "-i"