{{- $url := .Destination | safeURL -}}
{{- $img := .Page.Resources.GetMatch .Destination -}}

{{- if and (not $img) .Page.File -}}
        {{ with .Page.File }}
                {{ $path := path.Join .Dir $url }}
                {{- $img = resources.Get $path -}}
        {{ end }}
{{- end -}}

{{- if and (not $img) .Page.File -}}
        {{- $img = resources.Get .Destination -}}
{{- end -}}

{{- with $img -}}
        <figure>
                <a href="{{ $img.RelPermalink }}" data-download="true">
                {{ if eq .MediaType.SubType "svg" }}
                        <img class="actual-article-img" src="{{ $img.RelPermalink }}" alt="{{ $.Text }}">
                {{ else }}
                        <img class="actual-article-img" width="{{ $img.Width }}" height="{{ $img.Height }}" src="{{ $img.RelPermalink }}" alt="{{ $.Text }}">
                {{ end }}
                </a>

                <figcaption><i>{{ $.Text | safeHTML }}</i></figcaption>
        </figure>
{{- else -}}
        <em>Unable to find image {{ $url }}!</em>
{{- end -}}
