From 429dcda2cd5e0e0be15bf7f08b2ca42e5deae48f Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Sat, 25 Nov 2023 19:05:53 -0800 Subject: [PATCH] Minify feeds with xmllint This works particularly well on my Atom feeds with embedded XHTML. --- layouts/_default/_markup/render-link.atom.xml | 18 +++++++++--------- layouts/_default/_markup/render-link.rss.xml | 18 +++++++++--------- scripts/xhtmlize.sh | 1 + 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/layouts/_default/_markup/render-link.atom.xml b/layouts/_default/_markup/render-link.atom.xml index ce4dadc..a2033b4 100644 --- a/layouts/_default/_markup/render-link.atom.xml +++ b/layouts/_default/_markup/render-link.atom.xml @@ -1,12 +1,12 @@ {{- $parsedDest := urls.Parse (.Destination | absURL) -}} -{{- if (strings.HasPrefix .Destination "#") -}} - {{ .Text | safeHTML }} -{{- else if not (strings.HasPrefix .Destination $parsedDest.Scheme) -}} - {{- $baseURL := trim .Page.Site.BaseURL "/" -}} - {{- $fragment := "" -}} - {{- with $parsedDest.Fragment -}}{{- $fragment = printf "#%s" . -}}{{- end -}} - {{- $href := printf "%s%s%s" $baseURL $parsedDest.Path $fragment | absURL -}} - {{ .Text | safeHTML }} +{{- if (strings.HasPrefix .Destination "#") -}} +{{ .Text | safeHTML }} +{{- else if not (strings.HasPrefix .Destination $parsedDest.Scheme) -}} +{{- $baseURL := trim .Page.Site.BaseURL "/" -}} +{{- $fragment := "" -}} +{{- with $parsedDest.Fragment -}}{{- $fragment = printf "#%s" . -}}{{- end -}} +{{- $href := printf "%s%s%s" $baseURL $parsedDest.Path $fragment | absURL -}} +{{ .Text | safeHTML }} {{- else -}} - {{ .Text | safeHTML }} +{{ .Text | safeHTML }} {{- end -}} diff --git a/layouts/_default/_markup/render-link.rss.xml b/layouts/_default/_markup/render-link.rss.xml index e81c9ea..246f6ae 100644 --- a/layouts/_default/_markup/render-link.rss.xml +++ b/layouts/_default/_markup/render-link.rss.xml @@ -1,12 +1,12 @@ {{- $parsedDest := urls.Parse (.Destination | absURL) -}} -{{- if (strings.HasPrefix .Destination "#") -}} - {{ .Text | safeHTML }} -{{- else if not (strings.HasPrefix .Destination $parsedDest.Scheme) -}} - {{- $baseURL := trim .Page.Site.BaseURL "/" -}} - {{- $fragment := "" -}} - {{- with $parsedDest.Fragment -}}{{- $fragment = printf "#%s" . -}}{{- end -}} - {{- $href := printf "%s%s%s" $baseURL $parsedDest.Path $fragment | absURL -}} - {{ .Text | safeHTML }} +{{- if (strings.HasPrefix .Destination "#") -}} +{{ .Text | safeHTML }} +{{- else if not (strings.HasPrefix .Destination $parsedDest.Scheme) -}} +{{- $baseURL := trim .Page.Site.BaseURL "/" -}} +{{- $fragment := "" -}} +{{- with $parsedDest.Fragment -}}{{- $fragment = printf "#%s" . -}}{{- end -}} +{{- $href := printf "%s%s%s" $baseURL $parsedDest.Path $fragment | absURL -}} +{{ .Text | safeHTML }} {{- else -}} - {{ .Text | safeHTML }} +{{ .Text | safeHTML }} {{- end -}} diff --git a/scripts/xhtmlize.sh b/scripts/xhtmlize.sh index 796fd37..c18d856 100644 --- a/scripts/xhtmlize.sh +++ b/scripts/xhtmlize.sh @@ -20,4 +20,5 @@ trap cleanup EXIT export XMLLINT_INDENT=' ' export OUTPUT_DIR="$output_dir" find "$output_dir" -type f -name '*.html' -exec sh "$script_dir/xhtmlize-single-file.sh" {} \; +find "$output_dir" -type f -name '*.xml' -exec xmllint --noblanks --encode UTF-8 --noent {} --output {} \; # done