{{ $image := resources.GetMatch (.Get "src") }}
{{ $size := .Get "size" }}
{{/* Set the right options for Resize */}}
{{ $options := printf "%s %s %s" $size "jpg q90" "Box"}}
{{ $imagethumbnail := $image.Resize $options }}

<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
    <a href="{{ $image.RelPermalink }}">
    <img class="thumbnail" src="{{ $imagethumbnail.RelPermalink }}"
    {{- if or (.Get "alt") (.Get "caption") }}
    alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
    {{- end -}}
    />
    </a>
    {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
        <figcaption class="center">
            {{ with (.Get "title") -}}
                <h4>{{ . }}</h4>
            {{- end -}}
            {{- if or (.Get "caption") (.Get "attr") -}}<p class="f5 lh-copy center">
                {{- .Get "caption" | markdownify -}}
                {{- with .Get "attrlink" }}
                    <a href="{{ . }}">
                {{- end -}}
                {{- .Get "attr" | markdownify -}}
                {{- if .Get "attrlink" }}</a>{{ end }}</p>
            {{- end }}
        </figcaption>
    {{- end }}
</figure>

