{{ $original := .Page.Resources.GetMatch (printf "*%s*" (.Get 0)) }}
{{ $command := strings.ToLower (printf "%s" (.Get 1)) }}
{{ $options := .Get 2 }}
{{ if eq $command "fit"}}
    {{ .Scratch.Set "image" ($original.Fit $options) }}
{{ else if eq $command "resize"}}
    {{ .Scratch.Set "image" ($original.Resize $options) }}
{{ else if eq $command "fill"}}
    {{ .Scratch.Set "image" ($original.Fill $options) }}
{{ else }}
    {{ errorf "Invalid image processing command: Must be one of Fit, Fill or Resize. Is: %s" ($command)}}
{{ end }}
{{ $image := .Scratch.Get "image" }}
<figure class="post-figure">
    <a href="{{ $original.RelPermalink }}">
        <img class="post-figure__img" src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}">
    </a>
    <figcaption class="post-figure__caption">
    <small>
    {{ with not .Inner }}
        {{ $original.Title }}
    {{ end }}
    </small>
    </figcaption>
</figure>
