diff --git a/.build.yml b/.build.yml index 718df0e..7426726 100644 --- a/.build.yml +++ b/.build.yml @@ -7,7 +7,7 @@ packages: - rsync - git # for Hugo's gitInfo - bmake - - moreutils + - libxml2-utils # for xmllint sources: - https://git.sr.ht/~seirdy/seirdy.one secrets: diff --git a/layouts/_default/404.html b/layouts/_default/404.html index 4ce0ef8..effdbf5 100644 --- a/layouts/_default/404.html +++ b/layouts/_default/404.html @@ -2,21 +2,8 @@
- - -` -}}
+{{- $replacedLanguageFigure := `` -}}
+
{{- .Content | replaceRE $referencesWithoutHeading $referencesWithHeading | replaceRE $badNoteRef $goodNoteRef | replaceRE $endnotesClosingDiv $endnotesClosingSection | replaceRE $tocHeadingOutside $tocHeadingInside | replaceRE $footnoteBacklinksBad $footnoteBacklinksGood | replaceRE $repeatedFootnoteBacklinksBad $repeatedFootnoteBacklinksGood | replaceRE $endNotesNotFocusable $endNotesFocusable | replaceRE `\’` `’` | replaceRE `\ ` `\ ` | replaceRE `\“` `“` | replaceRE `\”` `”` | replaceRE `\…` `—` | replaceRE `\—` `—` | replaceRE `\` `\` | replaceRE `‘` `‘`| safeHTML -}}
diff --git a/layouts/shortcodes/codefigure.html b/layouts/shortcodes/codefigure.html
index 6692ce6..e64f768 100644
--- a/layouts/shortcodes/codefigure.html
+++ b/layouts/shortcodes/codefigure.html
@@ -8,5 +8,5 @@
just use the beginning for the label and the full thing for the aria description.
-->
diff --git a/scripts/xhtmlize-single-file.sh b/scripts/xhtmlize-single-file.sh
new file mode 100644
index 0000000..e22c845
--- /dev/null
+++ b/scripts/xhtmlize-single-file.sh
@@ -0,0 +1,37 @@
+#!/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 which we remove
+# with "sd". I chose sd since it handles newlines well.
+
+set -e -u
+
+export html_file="$1"
+export tmp_file="${html_file}.tmp"
+export xhtml_file=${html_file%*.html}.xhtml
+
+cleanup() {
+ rm -f "$tmp_file"
+}
+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.css >>"$xhtml_file"
+tail -n +8 "$tmp_file" \
+ | sd '\n\t*\n\t*
' '
' >>"$xhtml_file"
+tail -n +2 "$xhtml_file" > "$html_file"
+sed -i 5d "$xhtml_file" # busybox sed supports "-i"
+
+# the "sed 5d" deletes the now-redundant meta charset; it's the first
+# thing in the .
diff --git a/scripts/xhtmlize.sh b/scripts/xhtmlize.sh
index 920e05b..03d12ad 100644
--- a/scripts/xhtmlize.sh
+++ b/scripts/xhtmlize.sh
@@ -1,11 +1,19 @@
#!/bin/sh
# takes an arg for the output dir.
-# copies every .html file to an equivalent .xhtml file, but replaces
-# the meta charset with an XML declaration for compatibility with some
-# XML tooling.
-# this means that every index.html file has an equivalent index.xhtml file.
-# content negotiation allows an agent to pick html or xhtml.
+# Runs xhtmlize-single-file.sh on every single html file in the output dir.
-find "$1" -type f -name '*.html' \
- -exec sh -c 'echo "" >"${0%*.html}.xhtml" && xmlfmt -i " " -f "$0" | busybox sed -e :a -e "/./,\$!d;/^\n*\$/{\$d;N;};/\n\$/ba" | sd -f m "\n(?:\t*)?" "" | sd -f m "\n\t*>\"${0%*.html}.xhtml\"" "sponge \"$0\""' {} \;
+set -e -u
+
+output_dir="$1"
+script_dir="$(dirname "$0")"
+
+printf '\t\t\n' "$(htmlq -t style <"$output_dir/index.html")" >tmp.css
+cleanup() {
+ rm -f "tmp.css"
+}
+trap cleanup EXIT
+
+export XMLLINT_INDENT=' '
+find "$output_dir" -type f -name '*.html' \
+ -exec sh "$script_dir/xhtmlize-single-file.sh" {} \;
# done