{{- $imgs := slice -}}
{{- $shouldResize := .Get "shouldResize" | default true -}}

{{- if .Get "name" -}}
  {{- $imgs = $imgs | append (.Page.Resources.GetMatch (.Get "name")) -}}
{{- else if .Get "names" -}}
  {{- range (split (.Get "names") ",") -}}
    {{- $imgs = $imgs | append ($.Page.Resources.GetMatch .) -}}
  {{- end -}}
{{- else -}}
  {{ errorf "Missing name or names parameter to figures/image" }}
{{- end -}}

{{- if lt (len $imgs) 0 -}}
  {{ errorf "No images found for name(s) parameter" }}
{{- end -}}

{{- $class := .Get "class" -}}
{{- $shouldShowTitle := (.Get "shouldShowTitle") | default true -}}
{{- $size := .Get "size" | default "full" -}}

{{ if in (slice "full" "main") $size }}
  {{
    partial "page/figures/fullwidth.html" (dict
      "page" $.Page
      "name" (.Get "name")
      "size" $size
      "class" $class
      "shouldShowTitle" $shouldShowTitle
    )
  }}
{{ else if eq $size "small" }}
  {{
    partial "page/figures/small.html" (dict
      "page" $.Page
      "name" (.Get "name")
      "size" $size
      "class" $class
      "shouldShowTitle" $shouldShowTitle
    )
  }}
{{ end }}
