{{- $source := $.Destination | safeURL -}} {{- $public := print "public/" $source -}} {{- $local := "" -}} {{- $cache := "" -}} {{- $exists := "" -}} {{- $width := "" -}} {{- $height := "" -}} {{- $srcset := "" -}} {{- $colors := "" -}} {{- $figcaption := "Image/Picture" -}} {{- $orientation := "landscape" -}} {{- $dimensions := "600x360" -}} {{- $author := .Page.Section -}} {{- $relURL := strings.TrimPrefix .Page.Site.BaseURL .Page.Permalink -}} {{- $immutable := print ($relURL | humanize | urlize) "-" ($source | sha256 | truncate 8 "") -}} {{- $fileCache := print (partial "function-paths.html" "media") "/" $author "/" $immutable -}} {{- $cached := and (fileExists (print "public/" $fileCache ".webp")) (fileExists (print "public/" $fileCache (path.Ext $source))) -}} {{- if not $cached -}} {{- with $remote := resources.GetRemote $source -}} {{- with .Err -}} {{- if fileExists $public -}} {{- $local = resources.Get $public -}} {{- with $local -}} {{- $local = .Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/" (path.Base .)) -}} {{- end -}} {{- $source = print ("" | absURL) $source -}} {{- else -}} {{- $404image := resources.Get "data/media/404.png" -}} {{- with $404image -}} {{- $width = .Width -}} {{- $height = .Height -}} {{- end -}} {{- $source = $404image.Permalink -}} {{- end -}} {{- else -}} {{- $cache = .Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/" (path.Base .)) -}} {{- end -}} {{- end -}} {{- else -}} {{- $exists = resources.Get (print "public/" $fileCache (path.Ext $source)) -}} {{- $exists = $exists.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/" (path.Base $exists)) -}} {{- end -}} {{- with $local }} {{- $local = .Fit (print $dimensions " webp") }} {{- $local = $local | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable ".webp") }} {{- $srcset = $local.Permalink -}} {{- $local = .Fit $dimensions }} {{- $local = $local | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable (path.Ext $local)) }} {{- $width = $local.Width -}} {{- $height = $local.Height -}} {{- $colors = $local.Colors -}} {{- $writeToFile := $local.Permalink }} {{- end }} {{- with $cache }} {{- $cache = .Fit (print $dimensions " webp") }} {{- $cache = $cache | resources.Copy (print $author "/media/" $immutable ".webp") }} {{- $srcset = $cache.Permalink -}} {{- $cache = .Fit $dimensions }} {{- $cache = $cache | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable (path.Ext $cache)) }} {{- $width = $cache.Width -}} {{- $height = $cache.Height -}} {{- $colors = $cache.Colors -}} {{- $cache = $cache.Permalink }} {{- end -}} {{- with $exists }} {{- if fileExists (print "public/" $fileCache ".webp") -}} {{- $srcset = print "/" $fileCache ".webp" -}} {{- end -}} {{- if fileExists (print "public/" $author "/media/" $immutable ".webp") -}} {{- $srcset = print "/" $author "/media/" $immutable ".webp" -}} {{- end -}} {{- $width = .Width -}} {{- $height = .Height -}} {{- $colors = .Colors -}} {{- $cache = .Permalink }} {{- end -}} {{- if lt $width $height -}} {{- $orientation = "portrait" -}} {{- end -}} {{- with $.Title -}} {{- $figcaption = . | markdownify -}} {{ end }} {{- /* This comment removes trailing newlines and white spaces. */ -}}
{{- with $srcset }} {{- end }} {{ $.Text | htmlUnescape }}
{{ $figcaption }}
Index: {{ with $cache }} {{ print "[Cache](" $cache ")" | markdownify }} · {{ end }} {{ print "[Source](" $source ")" | markdownify }}
{{- /* This comment removes trailing newlines and white spaces. */ -}}