{{ $page := .Page }} {{ $thumbnails := slice }} {{ with $thumbnailNamesList := $page.Params "thumbnails" }} {{/* Specify a list of thumbnails to use with the page "thumbnails" param */}} {{ range $thumbnailNamesList }} {{ with $page.Resources.GetMatch . }} {{ $thumbnails = $thumbnails | append . }} {{ else }} {{ errorf "No image resources available for %s from thumbnails param" . }} {{ end }} {{ end }} {{ else }} {{/* Get a list of all the image resources and see if any of them specify thumbnails for themselves. If they do, use those, otherwise use the image resource itself. */}} {{ range $img := $page.Resources.ByType "image" }} {{ with $thumbnailResourceName := $img.params.thumbnail }} {{ with $page.Resources.GetMatch $thumbnailResourceName }} {{ $thumbnails = $thumbnails | append . }} {{ else }} {{ errorf "No image resources available for '%s' from thumbnail param for image resources %s" $thumbnailResourceName $img.Name }} {{ end }} {{ else }} {{/* TODO: Look for a named image that indicates it's a thumbnail of another resources. Something like ${imgBasename}_thumbnail.${ext}. I don't know how easy Hugo makes filename processing, so this could be painful. */}} {{ $thumbnails = $thumbnails | append $img }} {{ end }} {{ end }} {{ end }} {{ if eq (len $thumbnails) 0 }} {{ errorf "Couldn't find any thumbnails for %s" $page.Permalink }} {{ end }} {{ $thumbnailOptions := dict }} {{ if isset . "Width" }}{{ $thumbnailOptions = $thumbnailOptions | merge (dict "Width" .Width) }}{{ end }} {{ if isset . "Height" }}{{ $thumbnailOptions = $thumbnailOptions | merge (dict "Height" .Height) }}{{ end }} {{ $processedThumbnails := slice }} {{ range $thumbnails }} {{ $options := $thumbnailOptions | merge "Image" . }} {{ $processedThumbnail := partial "photos/thumbnail_for_list.html" $options }} {{ $processedThumbnails = $processedThumbnails | append $processedThumbnail }} {{ end }} {{ return $processedThumbnails }}