theme: optimize image loading #393

This commit is contained in:
Sören Weber 2022-11-18 21:49:02 +01:00
parent 3bac832eb0
commit c7f6cbf71b
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D

View file

@ -7,13 +7,19 @@
{{- $height := "auto" }} {{- $height := "auto" }}
{{- $width := "auto" }} {{- $width := "auto" }}
{{- $dest_url := urls.Parse $url }} {{- $dest_url := urls.Parse $url }}
{{- $dest_path := $dest_url.Path }} {{- $dest_path := path.Clean $dest_url.Path }}
{{- $image := $context.Resources.GetMatch $dest_path }} {{- $image := "" }}
{{- if not $image }} {{- if ($dest_url.IsAbs) }}
{{- $image = .Resources.GetMatch $dest_path }} {{/* this image does not belong to the site, get it from external */}}
{{- end }} {{- $image = resources.GetRemote $url }}
{{- if not $image }} {{- else }}
{{- $image = .Resources.GetRemote $url }} {{- /* Get local page resource image. */}}
{{- $image = $context.Resources.Get $dest_path }}
{{- if not $image }}
{{- /* Get local image from assets directory. */}}
{{- $dest_path := path.Clean $dest_url.Path }}
{{- $image = resources.Get $dest_path }}
{{- end }}
{{- end }} {{- end }}
{{- if $image }} {{- if $image }}
{{- $url = $image.RelPermalink }} {{- $url = $image.RelPermalink }}
@ -26,7 +32,7 @@
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- if $dest_url.RawQuery }} {{- if $dest_url.RawQuery }}
{{- $classes = (replaceRE "\\s+" " " (replaceRE "," " " ($dest_url.Query.Get "classes") ) ) }} {{- $classes = delimit (split ($dest_url.Query.Get "classes") ",") " " }}
{{- $featherlight = (ne ($dest_url.Query.Get "featherlight") "false") }} {{- $featherlight = (ne ($dest_url.Query.Get "featherlight") "false") }}
{{- if or ($dest_url.Query.Get "height") ($dest_url.Query.Get "width") }} {{- if or ($dest_url.Query.Get "height") ($dest_url.Query.Get "width") }}
{{- $height = "auto" }} {{- $height = "auto" }}