fix: skip image processing if size is origin (#815)

This commit is contained in:
Robert Kaussow 2024-04-07 20:15:01 +02:00 committed by GitHub
parent 0c894d3581
commit 7b52c98f17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,7 +8,7 @@
{{- $caption := default .Title $customAlt }} {{- $caption := default .Title $customAlt }}
{{- $isSVG := (eq .MediaType.SubType "svg") }} {{- $isSVG := (eq .MediaType.SubType "svg") }}
{{- $origin := .Permalink }} {{- $origin := . }}
{{- if $isSVG }} {{- if $isSVG }}
{{- $data.SetInMap "size" "profile" "180" }} {{- $data.SetInMap "size" "profile" "180" }}
{{- $data.SetInMap "size" "tiny" "320" }} {{- $data.SetInMap "size" "tiny" "320" }}
@ -16,40 +16,46 @@
{{- $data.SetInMap "size" "medium" "1200" }} {{- $data.SetInMap "size" "medium" "1200" }}
{{- $data.SetInMap "size" "large" "1800" }} {{- $data.SetInMap "size" "large" "1800" }}
{{- else }} {{- else }}
{{- $data.SetInMap "size" "profile" (.Fill "180x180 Center").Permalink }} {{- $data.SetInMap "size" "profile" "180x180 Center" }}
{{- $data.SetInMap "size" "tiny" (.Resize "320x").Permalink }} {{- $data.SetInMap "size" "tiny" "320x"}}
{{- $data.SetInMap "size" "small" (.Resize "600x").Permalink }} {{- $data.SetInMap "size" "small" "600x" }}
{{- $data.SetInMap "size" "medium" (.Resize "1200x").Permalink }} {{- $data.SetInMap "size" "medium" "1200x" }}
{{- $data.SetInMap "size" "large" (.Resize "1800x").Permalink }} {{- $data.SetInMap "size" "large" "1800x" }}
{{- end }} {{- end }}
<div class="flex justify-center"> <div class="flex justify-center">
<figure <figure
class="gdoc-markdown__figure class="gdoc-markdown__figure
{{- if eq $customSize "profile" }}{{ print " gdoc-post__figure--round" }}{{ end }}" {{- if eq $customSize "profile" }}{{ print " gdoc-markdown__figure--round" }}{{ end }}"
> >
<a class="gdoc-markdown__link--raw" href="{{ .Permalink }}"> <a class="gdoc-markdown__link--raw" href="{{ .Permalink }}">
<picture> <picture>
{{- $size := $data.Get "size" }} {{- $size := $data.Get "size" }}
{{- if not $isSVG }} {{- if not $isSVG }}
{{- if ne $customSize "origin" }}
<source <source
{{- with $customSize }} {{- with $customSize }}
srcset="{{ index $size $customSize }}" {{- if eq $customSize "profile" }}
srcset="{{ ($origin.Fill (index $size $customSize)).Permalink }}"
{{- else}}
srcset="{{ ($origin.Resize (index $size $customSize)).Permalink }}"
{{- end}}
{{- else }} {{- else }}
srcset="{{ $size.small }} 600w, {{ $size.medium }} 1200w" sizes="100vw" srcset="{{ ($origin.Resize (index $size "small")).Permalink }} 600w, {{ ($origin.Resize (index $size "medium")).Permalink }} 1200w" sizes="100vw"
{{- end }} {{- end }}
/> />
{{- end }} {{- end }}
{{- end }}
<img <img
{{- if $isSVG }} {{- if $isSVG }}
src="{{ $origin }}" width="{{ index $size (default "medium" $customSize) }}" src="{{ $origin.Permalink }}" width="{{ index $size (default "medium" $customSize) }}"
{{- else }} {{- else }}
{{- if $lazyLoad }}{{ print " loading=\"lazy\"" | safeHTMLAttr }}{{- end }} {{- if $lazyLoad }}{{ print " loading=\"lazy\"" | safeHTMLAttr }}{{- end }}
{{- if eq $customSize "origin" }} {{- if eq $customSize "origin" }}
src="{{ $origin }}" src="{{ $origin.Permalink }}"
{{- else }} {{- else }}
src="{{ $size.large }}" src="{{ ($origin.Resize (index $size "large")).Permalink }}"
{{- end }} {{- end }}
alt="{{ $caption }}" alt="{{ $caption }}"
{{- end }} {{- end }}