1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-11-23 21:02:09 +00:00

use html-tidy to format my pages

This commit is contained in:
Rohan Kumar 2023-11-13 17:33:18 -08:00
parent 9e54f9321f
commit 72aa3606c5
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479
2 changed files with 9 additions and 4 deletions

View file

@ -4,3 +4,5 @@ char-encoding: utf8
input-encoding: utf8 input-encoding: utf8
output-xhtml: yes output-xhtml: yes
quiet: yes quiet: yes
indent: no
tidy-mark: no

View file

@ -24,11 +24,15 @@ cleanup() {
} }
trap cleanup EXIT trap cleanup EXIT
run_tidy () {
tidy -asxhtml -config linter-configs/tidy.conf 2>/dev/null || true
}
# delete the stylesheet from the html file; we'll re-insert it later. # delete the stylesheet from the html file; we'll re-insert it later.
# Also remove two indentation levels # Also remove two indentation levels
sed 7d "$html_file" | xmllint --format --encode UTF-8 --noent - | tail -n +2 | sd '^\t(?:\t)?' '' >"$tmp_file" sed 7d "$html_file" | xmllint --format --encode UTF-8 --noent - | tail -n +2 | sd '^\t(?:\t)?' '' | run_tidy >"$tmp_file"
{ {
head -n7 "$tmp_file" | sd -s '/>' ' />' head -n7 "$tmp_file"
cat "$OUTPUT_DIR/tmp.css" cat "$OUTPUT_DIR/tmp.css"
# shellcheck disable=SC2016 # these are regex statements, not shell expressions # shellcheck disable=SC2016 # these are regex statements, not shell expressions
tail -n +8 "$tmp_file" \ tail -n +8 "$tmp_file" \
@ -38,6 +42,5 @@ sed 7d "$html_file" | xmllint --format --encode UTF-8 --noent - | tail -n +2 | s
| sd -s ' ' ' ' \ | sd -s ' ' ' ' \
| sd -f m 'class="u-photo photo"[^<]*<' 'class="u-photo photo"/> <' \ | sd -f m 'class="u-photo photo"[^<]*<' 'class="u-photo photo"/> <' \
| sd '([a-z])<(data|time)' '$1 <$2' \ | sd '([a-z])<(data|time)' '$1 <$2' \
| sd '</span>(<a[^>]*rel="(?:nofollow ugc|ugc nofollow)"(?:[^>]*)?>liked</a>)' '</span> $1' \ | sd '</span>(<a[^>]*rel="(?:nofollow ugc|ugc nofollow)"(?:[^>]*)?>liked</a>)' '</span> $1'
| sd '([^ ])/>' '$1 />'
} >"$html_file" } >"$html_file"