{{- $src := .Get "src" -}}
{{- $alt := .Get "alt" | default "" -}}
{{- $class := .Get "class" -}}
{{- $caption := .Get "caption" | default "" -}}
{{- $resource := .Page.Resources.GetMatch $src -}}
{{- $url := $src -}}
{{- with $resource -}}
  {{- $url = .RelPermalink -}}
{{- end -}}
<figure {{ with $class }}class="{{ . }}"{{ end }}>
  <img src="{{ $url }}" alt="{{ $alt }}" />
  {{- with $caption }}
  <figcaption>
    {{ $caption | markdownify }}
    <a href="{{ $url }}" class="tablet-hide">Expand</a>
  </figcaption>
  {{- end }}
</figure>