{{- $page := . -}}
{{- $image := "" }}
{{- with $page.Params.headerimage }}
  <div class="header-image">
    {{- if eq $page.BundleType "leaf" }}
      {{- with $page.Resources.GetMatch .src }}
        {{- $image = . }}
      {{- end }}
    {{- else }}
      {{- with resources.GetMatch (printf "**/%s" .src) }}
        {{- $image = . }}
      {{- end }}
    {{- end }}
    {{- $processes := .processes | default (slice "fill 1000x440 webp" )}}
    {{- $filter := .filter }}
    {{- if not $image }}
      {{- warnf "Header image '%s' not found for page %s" .src $page.RelPermalink }}
    {{- else }}
      {{- $image = partial "image-processing" (dict "image" $image "processes" $processes "filter" $filter) -}}
      <img
        src="{{ $image.RelPermalink }}"
        {{- with .text }} title="{{ . }}" {{ end }}
        {{- with .alt }} alt="{{ . }}" {{ end }}
      />
      {{- with .text }}<p>{{ . | markdownify }}</p>{{ end }}
    {{- end }}
  </div>
{{- end }}
