{{- /*
  Responsive image grid.
    {{< gallery "a.jpg" "b.jpg" >}}   explicit, ordered
    {{< gallery >}}                   every image resource of the page
  Thumbnails link to the full-size original.
*/ -}}
{{- $page := .Page -}}
{{- $images := slice -}}
{{- if .Params -}}
  {{- range .Params -}}
    {{- with $page.Resources.GetMatch . -}}
      {{- $images = $images | append . -}}
    {{- else -}}
      {{- warnf "gallery: %q not found in %s" . $page.Path -}}
    {{- end -}}
  {{- end -}}
{{- else -}}
  {{- $images = $page.Resources.ByType "image" -}}
{{- end -}}

{{- if $images -}}
<div class="gallery">
  {{- range $images }}
    {{- $thumb := .Fill "400x300 Center webp q80" }}
    {{- $full := .Resize "1600x webp q82" }}
    <a class="gallery-item" href="{{ $full.RelPermalink }}">
      <img src="{{ $thumb.RelPermalink }}" width="{{ $thumb.Width }}" height="{{ $thumb.Height }}"
           alt="" loading="lazy" decoding="async">
    </a>
  {{- end }}
</div>
{{- end -}}
