Improve image and smallimg support of webp

This commit is contained in:
Joe Hutchinson
2019-01-21 11:24:09 -05:00
parent 59b3abd760
commit 80344a5c6c
2 changed files with 21 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
<picture> <picture>
<source srcset="{{ replace (index .Params "src") (path.Ext (index .Params "src")) ".webp" | absURL }}" type="image/webp"> {{ if (fileExists (printf "%s/%s" "static" (replace (index .Params "src") (path.Ext (index .Params "src")) ".webp"))) -}}
<source srcset="{{ index .Params "src" | absURL }}"> <source srcset="{{ replace (index .Params "src") (path.Ext (index .Params "src")) ".webp" | absURL }}" type="image/webp">
{{- end }}
<source srcset="{{ index .Params "src" | absURL }}">
<img src="{{ index .Params "src" | absURL }}" {{ if isset .Params "alt" -}} alt="{{ index .Params "alt"}}" {{- end }}> <img src="{{ index .Params "src" | absURL }}" {{ if isset .Params "alt" -}} alt="{{ index .Params "alt"}}" {{- end }}>
</picture> </picture>

View File

@@ -1,11 +1,17 @@
<img src="{{ index .Params "src" }}" <picture>
{{- if isset .Params "alt" }} alt="{{ index .Params "alt"}}" {{ end -}} {{ if (fileExists (printf "%s/%s" "static" (replace (index .Params "src") (path.Ext (index .Params "src")) ".webp"))) -}}
class="small-img {{ if isset .Params "smartfloat" -}} <source srcset="{{ replace (index .Params "src") (path.Ext (index .Params "src")) ".webp" | absURL }}" type="image/webp">
{{- if eq .Params.smartfloat "left" -}} {{- end }}
smartfloat-left <source srcset="{{ index .Params "src" | absURL }}">
{{- else if eq .Params.smartfloat "right" -}} <img src="{{ index .Params "src" | absURL }}"
smartfloat-right {{- if isset .Params "alt" }} alt="{{ index .Params "alt"}}" {{ end -}}
{{- end -}} class="small-img {{ if isset .Params "smartfloat" -}}
{{- end }}" {{- if eq .Params.smartfloat "left" -}}
{{- if isset .Params "width" }} style="width: {{ index .Params "width" }};" {{- end -}} smartfloat-left
/> {{- else if eq .Params.smartfloat "right" -}}
smartfloat-right
{{- end -}}
{{- end }}"
{{- if isset .Params "width" }} style="width: {{ index .Params "width" }};" {{- end -}}
/>
</picture>