mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-11-23 21:02:09 +00:00
Minify feeds with xmllint
This works particularly well on my Atom feeds with embedded XHTML.
This commit is contained in:
parent
9ae88a5bef
commit
429dcda2cd
3 changed files with 19 additions and 18 deletions
|
@ -1,12 +1,12 @@
|
||||||
{{- $parsedDest := urls.Parse (.Destination | absURL) -}}
|
{{- $parsedDest := urls.Parse (.Destination | absURL) -}}
|
||||||
{{- if (strings.HasPrefix .Destination "#") -}}<!-- if it's a fragment -->
|
{{- if (strings.HasPrefix .Destination "#") -}}
|
||||||
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
||||||
{{- else if not (strings.HasPrefix .Destination $parsedDest.Scheme) -}}<!-- if it's a relative url -->
|
{{- else if not (strings.HasPrefix .Destination $parsedDest.Scheme) -}}
|
||||||
{{- $baseURL := trim .Page.Site.BaseURL "/" -}}
|
{{- $baseURL := trim .Page.Site.BaseURL "/" -}}
|
||||||
{{- $fragment := "" -}}
|
{{- $fragment := "" -}}
|
||||||
{{- with $parsedDest.Fragment -}}{{- $fragment = printf "#%s" . -}}{{- end -}}
|
{{- with $parsedDest.Fragment -}}{{- $fragment = printf "#%s" . -}}{{- end -}}
|
||||||
{{- $href := printf "%s%s%s" $baseURL $parsedDest.Path $fragment | absURL -}}
|
{{- $href := printf "%s%s%s" $baseURL $parsedDest.Path $fragment | absURL -}}
|
||||||
<a href="{{ $href }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
<a href="{{ $href }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
<a href="{{ .Destination | htmlEscape }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
<a href="{{ .Destination | htmlEscape }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{{- $parsedDest := urls.Parse (.Destination | absURL) -}}
|
{{- $parsedDest := urls.Parse (.Destination | absURL) -}}
|
||||||
{{- if (strings.HasPrefix .Destination "#") -}}<!-- if it's a fragment -->
|
{{- if (strings.HasPrefix .Destination "#") -}}
|
||||||
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
||||||
{{- else if not (strings.HasPrefix .Destination $parsedDest.Scheme) -}}<!-- if it's a relative url -->
|
{{- else if not (strings.HasPrefix .Destination $parsedDest.Scheme) -}}
|
||||||
{{- $baseURL := trim .Page.Site.BaseURL "/" -}}
|
{{- $baseURL := trim .Page.Site.BaseURL "/" -}}
|
||||||
{{- $fragment := "" -}}
|
{{- $fragment := "" -}}
|
||||||
{{- with $parsedDest.Fragment -}}{{- $fragment = printf "#%s" . -}}{{- end -}}
|
{{- with $parsedDest.Fragment -}}{{- $fragment = printf "#%s" . -}}{{- end -}}
|
||||||
{{- $href := printf "%s%s%s" $baseURL $parsedDest.Path $fragment | absURL -}}
|
{{- $href := printf "%s%s%s" $baseURL $parsedDest.Path $fragment | absURL -}}
|
||||||
<a href="{{ $href }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
<a href="{{ $href }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
|
@ -20,4 +20,5 @@ trap cleanup EXIT
|
||||||
export XMLLINT_INDENT=' '
|
export XMLLINT_INDENT=' '
|
||||||
export OUTPUT_DIR="$output_dir"
|
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 '*.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
|
# done
|
||||||
|
|
Loading…
Reference in a new issue