{{- $source := $.Destination | safeURL -}} {{- $public := print "public/" $source -}} {{- $local := "" -}} {{- $cache := "" -}} {{- $exists := "" -}} {{- $width := "" -}} {{- $height := "" -}} {{- $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-media.html") "/" $author "/" $immutable -}} {{- if not (or (fileExists (print "public/" $fileCache ".webp")) (fileExists (print "public/" $fileCache (path.Ext $source)))) -}} {{- with $remote := resources.GetRemote $source -}} {{- with .Err -}} {{- if fileExists $public -}} {{- $local = resources.Get $public -}} {{- with $local -}} {{- $local = .Content | resources.FromString (print (partial "function-paths-media.html") "/" $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.RelPermalink -}} {{- end -}} {{- else -}} {{- $cache = .Content | resources.FromString (print (partial "function-paths-media.html") "/" $author "/" (path.Base .)) -}} {{- end -}} {{- end -}} {{- else -}} {{- $exists = resources.Get (print "public/" $fileCache (path.Ext $source)) -}} {{- $exists = $exists.Content | resources.FromString (print (partial "function-paths-media.html") "/" $author "/" (path.Base $exists)) -}} {{ end }} {{- /* This comment removes trailing newlines and white spaces. */ -}}
{{- with $local }} {{- $local = .Fit (print $dimensions " webp") }} {{- $local = $local | resources.Copy (print (partial "function-paths-media.html") "/" $author "/" $immutable ".webp") }} {{- $local = .Fit $dimensions }} {{- $local = $local | resources.Copy (print (partial "function-paths-media.html") "/" $author "/" $immutable (path.Ext $local)) }} {{- $width = $local.Width -}} {{- $height = $local.Height -}} {{- $writeToFile := $local.Permalink }} {{- end }} {{- with $cache }} {{- $cache = .Fit (print $dimensions " webp") }} {{- $cache = $cache | resources.Copy (print $author "/media/" $immutable ".webp") }} {{- $cache = .Fit $dimensions }} {{- $cache = $cache | resources.Copy (print (partial "function-paths-media.html") "/" $author "/" $immutable (path.Ext $cache)) }} {{- $width = $cache.Width -}} {{- $height = $cache.Height -}} {{- $cache = $cache.RelPermalink }} {{- end -}} {{- with $exists }} {{- if fileExists (print "public/" $fileCache ".webp") -}} {{- end -}} {{- if fileExists (print "public/" $author "/media/" $immutable ".webp") -}} {{- end -}} {{- $width = .Width -}} {{- $height = .Height -}} {{- $cache = .RelPermalink }} {{- end -}} {{ $.Text | htmlUnescape }}
{{ with $.Title -}} {{ . | markdownify }} {{ else -}} Image/Picture {{ end -}}
Index: {{ with $cache }} {{ print "[Cache](" . ")" | markdownify }} · {{ end }} {{ print "[Source](" $source ")" | markdownify }}
{{- /* This comment removes trailing newlines and white spaces. */ -}}