{{- $modified := partial "function-page-modified.html"
(dict
"Context" .
)
-}}
{{- $format := "embed.html" -}}
{{- $page := print "public/" (strings.TrimPrefix .Page.Site.BaseURL .Page.Permalink) $format -}}
{{- with $embed := resources.Get $page -}}
{{- if (in $embed.Content "/data/media/404.png") -}} {{- $modified = true -}} {{- end -}}
{{- end -}}
{{- if $modified -}}
{{- $href := "" -}}
{{- $cache := "" -}}
{{- $width := "" -}}
{{- $height := "" -}}
{{- $srcset := "" -}}
{{- $colors := "" -}}
{{- $type := "" -}}
{{- $source := $.Destination | safeURL -}}
{{- $public := print "public/" $source -}}
{{- $fetch := print (urls.Parse $source).Scheme "://" (urls.Parse $source).Host (urls.Parse $source).RequestURI -}}
{{- $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 "") -}}
{{- $storage := print $author "/media/" $immutable -}}
{{- $cached := fileExists (print "public/" $storage ".webp") -}}
{{- $prurl := eq (findRE `^/\w` $source | len) 0 -}}
{{- $moderns := slice ".webp" ".avif" -}}
{{- $fallbacks := slice ".png" ".jpg" ".gif" ".jpeg" ".svg" ".apng" ".jfif" ".pjpeg" ".pjp" -}}
{{- $mimes := slice "image/avif" "image/webp" "image/apng" "image/gif" "image/jpeg" "image/png" "image/svg+xml" -}}
{{- if not $cached -}}
{{- $remote := false -}}
{{- if and (isset site.Params.site "offline") (eq $.Page.Site.Params.site.offline false) -}}
{{- $remote = resources.GetRemote $fetch -}}
{{- end -}}
{{- with $remote -}}
{{- with .Err -}}
{{- if fileExists $public -}}
{{- with $local := resources.Get $public -}}
{{- $local = .Content | resources.FromString (print $storage (path.Base .)) -}}
{{- $local = .Fit (print $dimensions " webp") -}}
{{- $local = $local | resources.Copy (print $storage ".webp") -}}
{{- $srcset = $local.Permalink -}}
{{- $local = .Fit $dimensions -}}
{{- $local = $local | resources.Copy (print $storage (path.Ext $local)) -}}
{{- $width = $local.Width -}}
{{- $height = $local.Height -}}
{{- $colors = $local.Colors -}}
{{- $cache = $local.Permalink -}}
{{- end -}}
{{- $source = print ("" | absURL) $source -}}
{{- else -}}
{{- with $404image := resources.Get "data/media/404.png" -}}
{{- $width = $404image.Width -}}
{{- $height = $404image.Height -}}
{{- $source = $404image.Permalink -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- with $cache = $remote.Content | resources.FromString (print $storage (path.Base $remote)) -}}
{{- $cache = .Fit (print $dimensions " webp") -}}
{{- $cache = $cache | resources.Copy (print $storage ".webp") -}}
{{- $srcset = $cache.Permalink -}}
{{- $cache = .Fit $dimensions -}}
{{- $cache = $cache | resources.Copy (print $storage (path.Ext $cache)) -}}
{{- $width = $cache.Width -}}
{{- $height = $cache.Height -}}
{{- $colors = $cache.Colors -}}
{{- $cache = $cache.Permalink -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- with $cache = resources.Get (print "public/" $storage ".webp") -}}
{{- $width = $cache.Width -}}
{{- $height = $cache.Height -}}
{{- $colors = $cache.Colors -}}
{{- $type = $cache.MediaType -}}
{{- $srcset = print ("" | absURL) "/" $storage ".webp" -}}
{{- end -}}
{{- range $extension := $fallbacks -}}
{{- with resources.Get (print "public/" $storage $extension) -}}
{{- $cache = print ("" | absURL) "/" $storage $extension -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if lt $width $height -}}
{{- $orientation = "portrait" -}}
{{- end -}}
{{- if (and (strings.HasPrefix $source "/") (not $prurl)) -}}
{{- $href = print ("" | relURL) $source -}}
{{- end -}}
{{- $cache = partial "function-normalize-url.html" $cache -}}
{{- $source = partial "function-normalize-url.html" $source -}}
{{- $srcset = partial "function-normalize-url.html" $srcset -}}
{{- $href = partial "function-normalize-url.html" $href -}}
{{- with $caption := $.Title -}}
{{- $figcaption = $caption | markdownify -}}
{{ end }}
{{- /* This comment removes trailing newlines and white spaces. */ -}}
{{- with $srcset }}
{{- end }}
{{ $figcaption }}
Index: {{ with $cache }} {{ print "[Cache](" $cache ")" | markdownify }} ยท {{ end }}
{{ print "[Source](" $source ")" | markdownify }}
{{- /* This comment removes trailing newlines and white spaces. */ -}}
{{- end -}}