Image shortcodes now resize images to reduce file size
This commit is contained in:
@@ -1,7 +1,14 @@
|
|||||||
<picture>
|
<picture>
|
||||||
{{ if (fileExists (printf "%s/%s" "content" (replace (index .Params "src") (path.Ext (index .Params "src")) ".webp"))) -}}
|
{{ if (fileExists (printf "%s/%s" "content" (replace (.Get "src") (path.Ext (.Get "src")) ".webp"))) -}}
|
||||||
<source srcset="{{ replace (index .Params "src") (path.Ext (index .Params "src")) ".webp" | absURL }}" type="image/webp">
|
<source srcset="{{ replace (.Get "src") (path.Ext (.Get "src")) ".webp" | absURL }}" type="image/webp">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
<source srcset="{{ index .Params "src" | absURL }}">
|
{{ $image := $.Page.Resources.GetMatch (.Get "src") }}
|
||||||
<img src="{{ index .Params "src" | absURL }}" {{ if isset .Params "alt" -}} alt="{{ index .Params "alt"}}" {{- end }}>
|
{{ if gt $image.Width 800 -}}
|
||||||
|
{{ $resized := $image.Resize "800x Lanczos" }}
|
||||||
|
<source srcset="{{ $resized.Permalink }}">
|
||||||
|
<img src="{{ $resized.Permalink }}" {{ if isset .Params "alt" -}} alt="{{ .Get "alt"}}" {{- end }}>
|
||||||
|
{{ else }}
|
||||||
|
<source srcset="{{ $image.Permalink }}">
|
||||||
|
<img src="{{ $image.Permalink }}" {{ if isset .Params "alt" -}} alt="{{ .Get "alt"}}" {{- end }}>
|
||||||
|
{{- end}}
|
||||||
</picture>
|
</picture>
|
||||||
@@ -1,17 +1,38 @@
|
|||||||
<picture>
|
<picture>
|
||||||
{{ if (fileExists (printf "%s/%s" "content" (replace (index .Params "src") (path.Ext (index .Params "src")) ".webp"))) -}}
|
{{ if (fileExists (printf "%s/%s" "content" (replace (.Get "src") (path.Ext (.Get "src")) ".webp"))) -}}
|
||||||
<source srcset="{{ replace (index .Params "src") (path.Ext (index .Params "src")) ".webp" | absURL }}" type="image/webp">
|
<source srcset="{{ replace (.Get "src") (path.Ext (.Get "src")) ".webp" | absURL }}" type="image/webp">
|
||||||
|
{{- end }}
|
||||||
|
{{ $image := $.Page.Resources.GetMatch (.Get "src") }}
|
||||||
|
{{ if or (gt $image.Width 800) (and (isset .Params "width") (gt $image.Width (.Get "width"))) -}}
|
||||||
|
{{ $.Scratch.Set "imgwidth" 800 }}
|
||||||
|
{{ if lt (.Get "width") 800 -}}
|
||||||
|
{{ $.Scratch.Set "imgwidth" (trim (.Get "width") "px") }}
|
||||||
|
{{- end }}
|
||||||
|
{{ $resized := $image.Resize (printf "%sx Lanczos" ($.Scratch.Get "imgwidth")) }}
|
||||||
|
<source srcset="{{ $resized.Permalink }}">
|
||||||
|
<img src="{{ $resized.Permalink }}"
|
||||||
|
{{- if isset .Params "alt" }} alt="{{ .Get "alt"}}" {{ end -}}
|
||||||
|
class="small-img {{ if isset .Params "smartfloat" -}}
|
||||||
|
{{- if eq .Params.smartfloat "left" -}}
|
||||||
|
smartfloat-left
|
||||||
|
{{- else if eq .Params.smartfloat "right" -}}
|
||||||
|
smartfloat-right
|
||||||
|
{{- end -}}
|
||||||
|
{{- end }}"
|
||||||
|
{{- if isset .Params "width" }} style="width: {{ .Get "width" }};" {{- end -}}
|
||||||
|
/>
|
||||||
|
{{ else }}
|
||||||
|
<source srcset="{{ $image.Permalink }}">
|
||||||
|
<img src="{{ $image.Permalink }}"
|
||||||
|
{{- if isset .Params "alt" }} alt="{{ .Get "alt"}}" {{ end -}}
|
||||||
|
class="small-img {{ if isset .Params "smartfloat" -}}
|
||||||
|
{{- if eq .Params.smartfloat "left" -}}
|
||||||
|
smartfloat-left
|
||||||
|
{{- else if eq .Params.smartfloat "right" -}}
|
||||||
|
smartfloat-right
|
||||||
|
{{- end -}}
|
||||||
|
{{- end }}"
|
||||||
|
{{- if isset .Params "width" }} style="width: {{ .Get "width" }};" {{- end -}}
|
||||||
|
/>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
<source srcset="{{ index .Params "src" | absURL }}">
|
|
||||||
<img src="{{ index .Params "src" | absURL }}"
|
|
||||||
{{- if isset .Params "alt" }} alt="{{ index .Params "alt"}}" {{ end -}}
|
|
||||||
class="small-img {{ if isset .Params "smartfloat" -}}
|
|
||||||
{{- if eq .Params.smartfloat "left" -}}
|
|
||||||
smartfloat-left
|
|
||||||
{{- else if eq .Params.smartfloat "right" -}}
|
|
||||||
smartfloat-right
|
|
||||||
{{- end -}}
|
|
||||||
{{- end }}"
|
|
||||||
{{- if isset .Params "width" }} style="width: {{ index .Params "width" }};" {{- end -}}
|
|
||||||
/>
|
|
||||||
</picture>
|
</picture>
|
||||||
Reference in New Issue
Block a user