1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-09-19 20:02:10 +00:00
seirdy.one/scripts/xhtmlize.sh

12 lines
717 B
Bash
Raw Normal View History

#!/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.
find "$1" -type f -name '*.html' \
2022-06-02 04:00:19 +00:00
-exec sh -c 'echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" >"${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 "<pre>\n\t*<code" "<pre><code" | sd -f m "\(\n\t*<abbr" "(<abbr" | pee "sed 5d >>\"${0%*.html}.xhtml\"" "sponge \"$0\""' {} \;
# done