add base image location
This commit is contained in:
@@ -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") }}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 }}>
|
||||
|
||||
@@ -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 }}>
|
||||
|
||||
@@ -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 }}>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user