{{- $folder := .Folder -}}
{{- $files := slice -}}
{{- $dimensions := "320x320" -}}
{{- $author := strings.TrimPrefix "public/" (strings.TrimSuffix "/media/" $folder) -}}
{{- $prefix := print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" -}}
{{- $mimes := slice
"image/apng"
"image/avif"
"image/gif"
"image/jpeg"
"image/png"
"image/svg+xml"
"image/webp"
-}}
{{- if fileExists $folder -}}
{{- range readDir $folder -}}
{{- if not .IsDir -}}
{{- $file := path.Join $folder .Name -}}
{{- with resources.Get $file -}}
{{- if in $mimes (string .MediaType) -}}
{{-
$files = $files | append (dict
"Path" .Name
)
-}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if eq (len $files) 6 -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if and $files (resources.Get (index (first 1 $files) 0).Path) -}}
{{- range $files -}}
{{- with $image := resources.Get .Path -}}
{{- if in $mimes (string .MediaType) -}}
{{- $srcset := (.Content | resources.FromString (print $prefix (path.Base .))).Fit (print $dimensions " webp") -}}
{{- $image = (.Content | resources.FromString (print $prefix (path.Base .))).Fit (print $dimensions " png") -}}
{{- $decodedURL := print "/" (replaceRE "-" "/" (path.Base .Name) 2 | replaceRE "-.........webp" "") "/" -}}
{{- $relatedPage := or (in $decodedURL "/messages/") (in $decodedURL "/feeds/") -}}
{{- if not $relatedPage -}}
{{- $decodedURL = print "/" $author "/" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- end -}}