add base image location

This commit is contained in:
2025-08-23 22:54:08 -02:30
parent 72183e14a3
commit adb7e7ac3f
9 changed files with 69 additions and 58 deletions
+1
View File
@@ -16,6 +16,7 @@
"img" .
"resizer" (default "responsive" site.Params.lazyimg.resizer)
"renderer" (default "lqip" site.Params.lazyimg.renderer)
"imageBasePath" (default "/images/lazyimg" site.Params.lazyimg.imageBasePath)
)}}
{{ if reflect.IsMap . }}
{{ $userParams := dict }}
+5 -4
View File
@@ -1,8 +1,9 @@
{{/* Input: Input: dict {"responsive": [RESOURCE, ...]}. Output: srcset string */}}
{{/* Input: dict {"responsive": [RESOURCE, ...], "imageBasePath": "/images/lazyimg"} */}}
{{ $images := .responsive }}
{{ $base := default "/images/lazyimg" .imageBasePath }}
{{ $srcset := slice }}
{{ range $images }}
{{ $srcset = append (printf "%s %dw" .Permalink .Width) $srcset }}
{{ $u := path.Join $base (strings.TrimPrefix "/" .RelPermalink) }}
{{ $srcset = append (printf "%s %dw" $u .Width) $srcset }}
{{ end }}
{{ return (delimit $srcset ",\n") }}
{{ return (delimit $srcset ",\n") }}
+15 -13
View File
@@ -3,17 +3,19 @@
{{ $imgDict := .imgDict }}
{{ $imgDictFallback := .imgDictFallback }}
{{ $base := default "/images/lazyimg" .imageBasePath }}
<picture>
<source type="image/webp"
{{- with $imgDict.lqip -}}
{{- $placeholderB64 := .Content | base64Encode -}}
{{- if gt (len $placeholderB64) 2048 }}
srcset="{{ .Permalink }}"
{{- else }}
srcset="data:{{ .MediaType }};base64,{{ $placeholderB64 }}"
{{- end }}
{{- end -}}
{{- with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{- end -}}
{{- if $imgDict.responsive -}}{{ with partial "renderer/_srcset" $imgDict }} data-sizes="auto" data-srcset="{{ . }}"{{- end }} {{- end -}}>
{{ partial "renderer/lqip" (merge . (dict "imgDict" $imgDictFallback)) }}
</picture>
<source type="image/webp"
{{ with $imgDict.lqip -}}
{{ $placeholderB64 := .Content | base64Encode }}
{{ if gt (len $placeholderB64) 2048 }}
{{ $lqipURL := path.Join $base (strings.TrimPrefix "/" .RelPermalink) }}
srcset="{{ $lqipURL }}"
{{ else }}
srcset="data:{{ .MediaType }};base64,{{ $placeholderB64 }}"
{{ end }}
{{- end }}
{{ with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{ end }}
{{ if $imgDict.responsive }}{{ with partial "renderer/_srcset" (merge $imgDict (dict "imageBasePath" $base)) }} data-sizes="auto" data-srcset="{{ . }}"{{ end }}{{ end }}>
{{ partial "renderer/lqip" (merge . (dict "imgDict" $imgDictFallback "imageBasePath" $base)) }}
</picture>
+21 -20
View File
@@ -2,24 +2,25 @@
{{ $alt := .alt }}
{{ $noscriptSupport := .noscript }}
{{ $imgDict := .imgDict }}
{{- if $noscriptSupport -}}
<noscript>
{{ partial "renderer/native" . }}
</noscript>
{{- end -}}
<img
{{- with $imgDict.lqip -}}
{{- $placeholderB64 := .Content | base64Encode -}}
{{- if gt (len $placeholderB64) 2048 }}
src="{{ .Permalink }}"
{{- else }}
src="data:{{ .MediaType }};base64,{{ $placeholderB64 }}"
{{- end }}
data-src="{{ $imgDict.default.Permalink }}"
class="{{ with $class }}{{ . }} {{ end }}blur-up lazyload"
{{ if $noscriptSupport }}<noscript>{{ partial "renderer/native" . }}</noscript>{{ end }}
{{ $base := default "/images/lazyimg" .imageBasePath }}
{{ $defaultURL := path.Join $base (strings.TrimPrefix "/" $imgDict.default.RelPermalink) }}
<img
{{ with $imgDict.lqip -}}
{{ $placeholderB64 := .Content | base64Encode }}
{{ if gt (len $placeholderB64) 2048 }}
{{ $lqipURL := path.Join $base (strings.TrimPrefix "/" .RelPermalink) }}
src="{{ $lqipURL }}"
{{ else }}
src="data:{{ .MediaType }};base64,{{ $placeholderB64 }}"
{{ end }}
data-src="{{ $defaultURL }}"
class="{{ with $class }}{{ . }} {{ end }}blur-up lazyload"
{{ else }}
src="{{ $imgDict.default.Permalink }}" class="{{ $class }} lazyload"
{{- end -}}
{{- with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{- end -}}
{{- if $imgDict.responsive -}}{{ with partial "renderer/_srcset" $imgDict }} data-sizes="auto" data-srcset="{{ . }}"{{- end }} {{- end -}}
{{- with $alt }} alt="{{ . }}" {{- end }}>
src="{{ $defaultURL }}" class="{{ $class }} lazyload"
{{ end -}}
{{ with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{ end }}
{{ if $imgDict.responsive }}{{ with partial "renderer/_srcset" (merge $imgDict (dict "imageBasePath" $base)) }} data-sizes="auto" data-srcset="{{ . }}"{{ end }}{{ end }}
{{ with $alt }} alt="{{ . }}" {{ end }}>
+8 -5
View File
@@ -2,8 +2,11 @@
{{ $alt := .alt }}
{{ $imgDict := .imgDict }}
<img src="{{ $imgDict.default.Permalink }}"
class="{{ $class }}" loading="lazy"
{{- with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{- end -}}
{{- if $imgDict.responsive -}} {{ with partial "renderer/_srcset" $imgDict }} srcset="{{ . }}"{{- end }} {{- end -}}
{{- with $alt }} alt="{{ . }}" {{- end }}>
{{ $base := default "/images/lazyimg" .imageBasePath }}
{{ $src := path.Join $base (strings.TrimPrefix "/" $imgDict.default.RelPermalink) }}
<img src="{{ $src }}"
class="{{ $class }}" loading="lazy"
{{ with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{ end }}
{{ if $imgDict.responsive }}{{ with partial "renderer/_srcset" (merge $imgDict (dict "imageBasePath" $base)) }} srcset="{{ . }}"{{ end }}{{ end }}
{{ with $alt }} alt="{{ . }}" {{ end }}>
+9 -9
View File
@@ -2,12 +2,12 @@
{{ $alt := .alt }}
{{ $noscriptSupport := .noscript }}
{{ $imgDict := .imgDict }}
{{- if $noscriptSupport -}}
<noscript>
{{ partial "renderer/native" . }}
</noscript>
{{- end -}}
<img data-src="{{ $imgDict.default.Permalink }}" class="{{ $class }} lazyload"
{{- with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{- end -}}
{{- if $imgDict.responsive -}}{{ with partial "renderer/_srcset" $imgDict }} data-sizes="auto" data-srcset="{{ . }}"{{- end }} {{- end -}}
{{- with $alt }} alt="{{ . }}" {{- end }}>
{{ if $noscriptSupport }}<noscript>{{ partial "renderer/native" . }}</noscript>{{ end }}
{{ $base := default "/images/lazyimg" .imageBasePath }}
{{ $dataSrc := path.Join $base (strings.TrimPrefix "/" $imgDict.default.RelPermalink) }}
<img data-src="{{ $dataSrc }}" class="{{ $class }} lazyload"
{{ with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{ end }}
{{ if $imgDict.responsive }}{{ with partial "renderer/_srcset" (merge $imgDict (dict "imageBasePath" $base)) }} data-sizes="auto" data-srcset="{{ . }}"{{ end }}{{ end }}
{{ with $alt }} alt="{{ . }}" {{ end }}>
+6 -5
View File
@@ -3,9 +3,10 @@
{{ $imgDict := .imgDict }}
{{ $imgDictFallback := .imgDictFallback }}
{{ $base := default "/images/lazyimg" .imageBasePath }}
<picture>
<source type="image/webp"
{{- with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{- end -}}
{{- if $imgDict.responsive -}}{{ with partial "renderer/_srcset" $imgDict }} data-sizes="auto" data-srcset="{{ . }}"{{- end }} {{- end -}}>
{{ partial "renderer/simple" (merge . (dict "imgDict" $imgDictFallback)) }}
</picture>
<source type="image/webp"
{{ with $imgDict.default }} height="{{ .Height }}" width="{{ .Width }}" {{ end }}
{{ if $imgDict.responsive }}{{ with partial "renderer/_srcset" (merge $imgDict (dict "imageBasePath" $base)) }} data-sizes="auto" data-srcset="{{ . }}"{{ end }}{{ end }}>
{{ partial "renderer/simple" (merge . (dict "imgDict" $imgDictFallback "imageBasePath" $base)) }}
</picture>