{{ $currentSession := . }}

{{ $_ := newScratch }}
{{- range $k, $v := .Page.Site.Data.sandpointsnamegraph -}}
  {{ if eq $currentSession.File.Dir (printf "%s/" $k) }}
    {{ $_.Add "depth" (index $v "depth") }}
    {{ if eq (index $v "depth") "mantle" }}
      {{ $_.Add "home" (index $v "in" 0) }}
    {{ end }}
    {{ if eq (index $v "depth") "crust" }}
      {{ $_.Add "home" (index (index $currentSession.Site.Data.sandpointsnamegraph (index $v "in" 0)) "in" 0) }}
      {{ $_.Add "mantle" (index $v "in" 0) }}
      {{ $_.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 ($_.Get "depth") "core" }}
        <a href="{{ with $currentSession.Site.GetPage (printf "/%s/index.md" ($_.Get "home")) }}{{ .RelPermalink }}{{ end }}{{ if eq hugo.Environment "offline" }}index.html{{ end }}"><span class="sup">{{ with $currentSession.Site.GetPage (printf "/%s/index.md" ($_.Get "home")) }}{{ substr .Title 0 1  }}</span><i>{{ substr .Title 1 }}</i></a>{{ end }}
    {{ end  }}

    {{ if eq ($_.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 ($_.Get "depth") "crust" }}
        {{ $.Scratch.Set "counter" 0 }}
        {{ range where $.Site.RegularPages ".Section" ($_.Get "mantle") }}
            {{ if in (index .Params (printf "has_%s" ($_.Get "mantle_has"))) $currentSession.File.LogicalName }}
                {{ $.Scratch.Set "counter" (add ($.Scratch.Get "counter") 1) }}
                {{ if lt ($.Scratch.Get "counter")  2 }}
                  <span><i> » <a href="{{ .RelPermalink }}{{ if eq hugo.Environment "offline" }}index.html{{ end }}">{{ .Title }}</a></i></span>
                {{ end  }}
            {{ end }}
        {{ 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>
