{{ define "main" }}
{{$currentNode := . }}

{{ $graphOptions := newScratch }}
{{ range $k, $v := $.Site.Data.sandpointsnamegraph }}
    {{ if eq (substr $currentNode.File.Dir 0 -1) $k }}
        {{ $graphOptions.Set "plural" (index $v "plural") }}
        {{ $graphOptions.Set "depth" (index $v "depth") }}
        {{ with index $v "in" }}
            {{ $graphOptions.Set "in" (index $v "in") }}
        {{ end }}
        {{ with index $v "has" }}
            {{ $graphOptions.Set "has" (index $v "has") }}
        {{ end  }}
    {{ end }}
{{ end }}

<div class="{{ $graphOptions.Get "depth" }}title"><span class="sup">{{ substr .File.Dir 0 -1 }}⁄{{ substr .Title 0 1  }}</span>{{ substr .Title 1 }}</div></div>

<div class="grid">
    <div class="leftcolumn">
        {{ if ne (trim .Page.TableOfContents "\n") "<nav id=\"TableOfContents\"></nav>" }}
          {{ .Page.TableOfContents }}
        {{ end }}
    </div>
    <div class="rightcolumn">
        {{ if (not (eq ($graphOptions.Get "depth") "crust")) }}
        <div class="has">
            <span class="sup">has {{ index ($graphOptions.Get "has") 1 }}⁄</span>
        </div>
        <div class="afterhas">
          {{ range index $currentNode.Params (printf "has_%s" (index ($graphOptions.Get "has") 1) )}}
            {{ with $.GetPage (printf "%s%s" (printf "/%s/" (index ($graphOptions.Get "has") 0)) . ) }}
            <div class="{{ index ($graphOptions.Get "has") 0 }}">
              <a href="{{ .RelPermalink }}{{ if eq hugo.Environment "offline" }}index.html{{ end }}">{{ .Title }}</a>
            </div>
            {{ end }}
          {{ end }}
        {{ end }}

        {{ if eq ($graphOptions.Get "depth") "crust" }}
            <div class="has">
                <span class="sup">in {{ index ($graphOptions.Get "in") 1 }}⁄</span>
            </div>
          {{ range where $.Site.RegularPages ".Section" (index ($graphOptions.Get "in") 0) }}
            {{ if in (index .Params (printf "has_%s" ($graphOptions.Get "plural"))) $currentNode.File.LogicalName }}
                <div class="{{ substr .File.Dir 0 -1 }}">
                    <a href="{{ .RelPermalink }}{{ if eq hugo.Environment "offline" }}index.html{{ end }}">{{ .Title }}</a>
                </div>
            {{ else if in $currentNode.Params.is_in .File.LogicalName }}
                <div class="{{ substr .File.Dir 0 -1 }}">
                    <a href="{{ .RelPermalink }}{{ if eq hugo.Environment "offline" }}index.html{{ end }}">{{ .Title }}</a>
                </div>
            {{ end }}
          {{ end }}
        {{ end }}
        </div>
    </div>
</div>

<div class="content">{{ .Content }}</div>

{{ end }}
