2022-06-02 05:11:40 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# copies an .html file to an equivalent .xhtml file, but replaces
|
|
|
|
# the meta charset with an XML declaration for compatibility with some
|
|
|
|
# XML tooling.
|
|
|
|
# Expects polygot XHTML(5) markup.
|
|
|
|
# Formats both the .html and .xhtml file.
|
|
|
|
# this means that every index.html file has an equivalent index.xhtml file.
|
|
|
|
# content negotiation allows an agent to pick html or xhtml.
|
|
|
|
|
|
|
|
# use xmllint to do the formatting.
|
|
|
|
# xmllint ruins inline CSS so delete the inline CSS and re-insert it.
|
|
|
|
# xmllint also adds extra whitespace around <pre><code> which we remove
|
2023-11-15 05:39:53 +00:00
|
|
|
# with sed.
|
2022-06-05 05:36:55 +00:00
|
|
|
# It also decreases indents by one level
|
2022-06-02 05:11:40 +00:00
|
|
|
|
2023-11-25 21:40:52 +00:00
|
|
|
#shellcheck disable=SC3040 # This only sets pipefail if it's available and otherwise does nothing
|
|
|
|
set -o pipefail 2>/dev/null || true
|
2022-06-02 05:11:40 +00:00
|
|
|
set -e -u
|
|
|
|
|
2022-06-13 15:27:09 +00:00
|
|
|
html_file="$1"
|
2023-11-15 05:39:53 +00:00
|
|
|
tmp_file="$(mktemp)"
|
2022-06-02 05:11:40 +00:00
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
rm -f "$tmp_file"
|
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2023-11-26 22:37:07 +00:00
|
|
|
# run_tidy() {
|
|
|
|
# tidy -asxhtml -config linter-configs/tidy.conf 2>/dev/null || true
|
|
|
|
# }
|
|
|
|
|
|
|
|
run_xmllint() {
|
|
|
|
xmllint --format --encode UTF-8 --noent - || {
|
|
|
|
echo "$html_file"
|
|
|
|
exit 1
|
|
|
|
}
|
2023-11-14 01:33:18 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 15:27:09 +00:00
|
|
|
# delete the stylesheet from the html file; we'll re-insert it later.
|
2023-11-26 22:37:07 +00:00
|
|
|
sed 7d "$html_file" | run_xmllint | tail -n +2 >"$tmp_file"
|
2022-06-03 00:18:13 +00:00
|
|
|
{
|
2023-11-14 01:33:18 +00:00
|
|
|
head -n7 "$tmp_file"
|
2023-11-15 10:26:52 +00:00
|
|
|
cat "${OUTPUT_DIR:?}/tmp.css"
|
2022-06-07 16:39:32 +00:00
|
|
|
# shellcheck disable=SC2016 # these are regex statements, not shell expressions
|
2023-11-15 10:26:52 +00:00
|
|
|
#shellcheck source=/home/rkumar/Executables/ghq/git.sr.ht/~seirdy/seirdy.one/scripts/xhtmlize.sh
|
2023-11-15 05:39:53 +00:00
|
|
|
sed \
|
2023-11-24 03:06:46 +00:00
|
|
|
-e '1,7d' \
|
2023-11-27 07:59:31 +00:00
|
|
|
-e 's|</span><span itemprop="familyName"|</span>\ <span itemprop="familyName"|' \
|
2023-11-24 03:06:46 +00:00
|
|
|
-e 's|class="u-photo photo"[^<]*<|class="u-photo photo"/> <|' \
|
|
|
|
-E \
|
|
|
|
-e 's|([a-z])<data|\1 <data|' \
|
|
|
|
-e 's#</span>(<a[^>]*rel="(nofollow ugc|ugc nofollow)"([^>]*)?>liked</a>)#</span> \1#' \
|
|
|
|
-e 's#^[\t\s]*<(code|/pre)#<\1#' \
|
2023-11-26 02:40:29 +00:00
|
|
|
"$tmp_file"
|
2022-08-11 04:30:22 +00:00
|
|
|
} >"$html_file"
|