{{- define "main" -}}
  {{- $svg := "" -}}
  {{- with .Params.hero.svg -}}
    {{- $match := $.Resources.GetMatch . -}}
    {{- if not $match -}}
      {{- $match = $.Resources.GetMatch (printf "img/%s" .) -}}
    {{- end -}}
    {{- with $match -}}
      {{- $svg = .Content -}}
    {{- end -}}
  {{- end -}}
  {{- $html := "" -}}
  {{- with .Params.hero.html -}}
    {{- $html = . -}}
  {{- end -}}

  <header>
    <hgroup>
      <h1>{{ with .Params.hero.title }}{{ . }}{{ else }}{{ .Title }}{{ end }}</h1>
      {{- with .Params.hero.deck -}}
      <p class="lede">{{ . | markdownify }}</p>
      {{- end -}}
      {{- if and (not .Params.hero.deck) .Summary -}}
      <p class="lede">{{ .Summary | markdownify }}</p>
      {{- end -}}
    </hgroup>
    {{- with .Params.study -}}
    <aside aria-label="Study metadata">
      {{- with .facts -}}
        {{- range . -}}
      <figure>
          {{- with .icon -}}
            {{ partial "icon.html" (dict "name" .) }}
          {{- end -}}
        <label>{{ .label }}</label>
        <figcaption {{ with .class }}class='{{ . }}'{{ end }}>{{ .value | markdownify }}</figcaption>
      </figure>
        {{- end -}}
      {{- end -}}
    </aside>
    {{- end -}}
    {{- with $svg -}}
    {{ . | safeHTML }}
    {{- end -}}
    {{- with $html -}}
    {{ . | safeHTML }}
    {{- end -}}
  </header>

  <article>
    {{- with .Params.study.toc -}}
    <nav aria-label="Table of contents">
      <ol>
        {{- range . -}}
        <li{{ with .children }} class="group"{{ end }}>
          {{- if .id -}}
          <a href="#{{ .id }}" {{- if .num -}}data-id="{{ .num }}"{{- end -}}>{{ .label }}</a>
          {{- else -}}
          <span>{{ .label }}</span>
          {{- end -}}
          {{- with .children -}}
          <ul>
            {{- range . -}}
            <li><a href="#{{ .id }}">{{ .label }}</a></li>
            {{- end -}}
          </ul>
          {{- end -}}
        </li>
        {{- end -}}
      </ol>
    </nav>
    {{- end -}}

    <div id="content">
      {{ .Content }}
    </div>
  </article>
{{- end -}}