{{ $currentSession := . }}

{{- range $k, $v := .Page.Site.Data.sandpointsnamegraph -}}
  {{ if eq $currentSession.File.Dir (printf "%s/" $k) }}
    {{ $.Scratch.Add "depth" (index $v "depth") }}
    {{ if eq (index $v "depth") "mantle" }}
      {{ $.Scratch.Add "home" (index $v "in" 0) }}
    {{ end }}
    {{ if eq (index $v "depth") "crust" }}
      {{ $.Scratch.Add "home" (index (index $currentSession.Site.Data.sandpointsnamegraph (index $v "in" 0)) "in" 0) }}
      {{ $.Scratch.Add "mantle" (index $v "in" 0) }}
      {{ $.Scratch.Add "mantle_has" (index (index $currentSession.Site.Data.sandpointsnamegraph (index $v "in" 0)) "has" 1) }}
    {{ end }}
  {{ end }}
{{- end -}}

<div class="header">
    <a title="{{ $.Site.Home.Title }}'s Bibliotheke" href="/library/BROWSE_LIBRARY.html" class="bibliotheke" target="_blank">
        <img src="/images/bibliotheke.svg" />
    </a>
    <div class="breadcrumbs">
    {{ if ne ($.Scratch.Get "depth") "core" }}
        <a href="{{ with $currentSession.Site.GetPage (printf "/%s/index.md" ($.Scratch.Get "home")) }}{{ .RelPermalink }}{{ end }}{{ if eq hugo.Environment "offline" }}index.html{{ end }}"><span class="sup">{{ with $currentSession.Site.GetPage (printf "/%s/index.md" ($.Scratch.Get "home")) }}{{ substr .Title 0 1  }}</span><i>{{ substr .Title 1 }}</i></a>{{ end }}
    {{ end  }}

    {{ if eq ($.Scratch.Get "depth") "mantle" }}
        <span class="mantlebar"><i> » <a href="{{ .RelPermalink }}{{ if eq hugo.Environment "offline" }}index.html{{ end }}">{{ .Title }}</a></i></span>
    {{ end  }}

    {{ if eq ($.Scratch.Get "depth") "crust" }}
      {{ range first 1 (where (where $.Site.RegularPages ".Section" ($.Scratch.Get "mantle")) ".Params.has_sessions" "intersect" (slice $currentSession.File.LogicalName)) }}
        <span><i> » <a href="{{ .RelPermalink }}{{ if eq hugo.Environment "offline" }}index.html{{ end }}">{{ .Title }}</a></i></span>
      {{ end }}
        <span class="mantlebar"><i> » <a href="{{ $currentSession.RelPermalink }}{{ if eq hugo.Environment "offline" }}index.html{{ end }}">{{ $currentSession.Title }}</a></i></span>
    {{ end  }}
    </div>
</div>