{{- $options := cond .IsNamedParams (.Get "src") (.Get 0) | dict "Src" -}}
{{- $options = cond .IsNamedParams (.Get "alt") (.Get 1) | .Page.RenderString | dict "Alt" | merge $options -}}
{{- $caption := cond .IsNamedParams (.Get "caption") (.Get 2) | .Page.RenderString -}}
{{- $options = dict "Caption" $caption | merge $options -}}
{{- $options = dict "Resources" .Page.Resources | merge $options -}}
{{- $optim := slice 
  (dict "Process" "resize 800x webp q75" "descriptor" "800w")
  (dict "Process" "resize 1200x webp q75" "descriptor" "1200w")
  (dict "Process" "resize 1600x webp q75" "descriptor" "1600w")
-}}
{{- $options = dict "OptimConfig" $optim | merge $options -}}
{{- $optimise := .Get "optimise" -}}
{{- $cacheRemote := .Get "cacheRemote" -}}

{{- if .IsNamedParams -}}
  {{- $options = dict "Title" (.Get "title") | merge $options -}}
  {{- $options = dict "Height" (.Get "height") | merge $options -}}
  {{- $options = dict "Width" (.Get "width") | merge $options -}}
  {{- $options = .Get "linked" | ne false | dict "Linked" | merge $options -}}
  {{- $options = dict "Rel" (.Get "rel") | merge $options -}}
  {{- $options = dict "Loading" (.Get "loading" | default "lazy") | merge $options -}}
  {{- if ne $optimise nil -}}{{- $options = dict "Optimise" $optimise | merge $options -}}{{- end -}}
  {{- if ne $cacheRemote nil -}}{{- $options = dict "CacheRemote" $cacheRemote | merge $options -}}{{- end -}}
{{- else -}}
  {{- $options = cond $caption true false | dict "Linked" | merge $options -}}
{{- end -}}

{{- $options = dict "Responsive" true | merge $options -}}

{{- with $caption -}}
  <figure{{ with cond $.IsNamedParams ($.Get "class") "" }} class="{{ . }}"{{ end }}>
    {{- partial "plugin/image.html" $options -}}
    <figcaption class="image-caption">
      {{- . | safeHTML -}}
    </figcaption>
  </figure>
{{- else -}}
  {{- partial "plugin/image.html" $options -}}
{{- end -}}
