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 @@ - - -{{ .Title }} -{{ if not (in site.BaseURL ".onion") -}} -{{ $icon_svg := resources.Get "/favicon.svg" | resources.Fingerprint "md5" }} -{{- printf `` $icon_svg.RelPermalink | safeHTML }} -{{- end }} -{{ $icon_192 := resources.Get "/apple-touch-icon.png" | resources.Fingerprint "md5" }} -{{- printf `` $icon_192.RelPermalink | safeHTML -}} -{{ $favicon := resources.Get "/favicon.png" -}} -{{ $favicon_base64 := $favicon.Content | base64Encode }} -{{ printf `` $favicon_base64 | safeHTML }} - - - + + {{- $resources := slice -}} {{- $resources = $resources | append (resources.Get "/css/main.css") -}} @@ -27,7 +14,17 @@ {{ $resources = $resources | append (resources.Get "css/print.css" | resources.ExecuteAsTemplate "print.css" .) -}} {{- $css := $resources | resources.Concat "css/style.css" | minify -}} -{{ hugo.Generator }} + +{{ .Title }} +{{ if not (in site.BaseURL ".onion") -}} +{{ $icon_svg := resources.Get "/favicon.svg" | resources.Fingerprint "md5" }} +{{- printf `` $icon_svg.RelPermalink | safeHTML }} +{{- end }} +{{ $icon_192 := resources.Get "/apple-touch-icon.png" | resources.Fingerprint "md5" }} +{{- printf `` $icon_192.RelPermalink | safeHTML -}} + + +
diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 02bd554..afd10c1 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -1,7 +1,18 @@ {{- $canonicalRelPermalink := .RelPermalink | replaceRE "^/~seirdy/" "/" }} - + + + + {{- $resources := slice -}} + {{- $resources = $resources | append (resources.Get "/css/main.css") -}} + {{ $dark := .Site.Params.dark | default "auto" -}} + {{- if not (eq $dark "off") -}} + {{ $resources = $resources | append (resources.Get "css/dark.css" | resources.ExecuteAsTemplate "dark.css" .) -}} + {{- end -}} + {{ $resources = $resources | append (resources.Get "css/print.css" | resources.ExecuteAsTemplate "print.css" .) -}} + {{- $css := $resources | resources.Concat "css/style.css" | minify -}} + {{ if or (eq site.BaseURL site.Params.CanonicalBaseURL) (in site.BaseURL "wgq3bd2kqoybhstp77i3wrzbfnsyd27wt34psaja4grqiezqircorkyd.onion") -}} {{ end -}} @@ -46,16 +57,6 @@ - - {{- $resources := slice -}} - {{- $resources = $resources | append (resources.Get "/css/main.css") -}} - {{ $dark := .Site.Params.dark | default "auto" -}} - {{- if not (eq $dark "off") -}} - {{ $resources = $resources | append (resources.Get "css/dark.css" | resources.ExecuteAsTemplate "dark.css" .) -}} - {{- end -}} - {{ $resources = $resources | append (resources.Get "css/print.css" | resources.ExecuteAsTemplate "print.css" .) -}} - {{- $css := $resources | resources.Concat "css/style.css" | minify -}} - {{- if not (or (ne "page" .Kind) (eq $canonicalRelPermalink "/bookmarks/") (eq $canonicalRelPermalink "/posts/")) }} diff --git a/layouts/partials/processed-content.html b/layouts/partials/processed-content.html index 82d0097..d3985ce 100644 --- a/layouts/partials/processed-content.html +++ b/layouts/partials/processed-content.html @@ -50,4 +50,9 @@ {{- $endNotesNotFocusable := `
  • ` -}} {{- $endNotesFocusable := `
  • ` -}} + + +{{- $extraLanguageFigure := `` -}} +{{- $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. -->
    -{{ .Inner | markdownify -}} +{{ .Inner | .Page.RenderString -}}
    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*)?\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