{{ $currentSection := .Section | urlize }}

<nav class="nav">
    <ul class="flex flex-row flex-wrap gap-2">

        {{- partial "nav-before.html" . -}}

        <!-- SINGLE post pages -->
        {{ if eq .Kind "page" }}
        <!-- show the parent section if exists-->
        {{ if .Section }}
        <li class="section-page"><a class="pill-henryc text-xs" href="/{{.Section}}">{{ if eq .Section "blog"
                }}posts{{else}}{{.Section}}{{end}}</a></li>
        {{ end }}

        <!-- if BLOG post -->
        {{/* {{ if eq .Section "blog" }} */}}

        <!-- show Categories  -->
        {{ range $c := .Params.Categories }}
        <li class="category-page"><a class="pill-slate text-xs" href="/categories/{{ $c | urlize }}">#{{$c}}</a></li>
        {{ end }}

        <!-- show Tags  -->
        {{ range $t := .Params.Tags }}
        <li class="tag-page"><a class="pill-slate text-xs" href="/tags/{{ $t | urlize }}">#{{$t}}</a></li>
        {{ end }}

        {{ end }}
        {{/* {{ end }} */}}

        <!-- SECTION list pages like blog/episodes -->
        {{ if eq .Kind "section" }}

        <!-- show other sections  -->
        {{ $thisSection := .Page.Section }}
        {{ range .Site.Sections }}

        <!-- exclude section currently being show  -->
        {{ if not (eq .Section $thisSection) }}
        <!-- exclude invisible section if they exist -->
        {{ $invisibleSections := .Site.Params.InvisibleSections }}
        {{ if $invisibleSections }}
        {{ if not (in $invisibleSections .Section) }}
        <li class="section-section"><a class="pill-henryc text-xs" href="{{ .Permalink }}">{{.Section}}</a></li>
        {{ end }}
        {{ end }}
        {{ end }}

        {{ end }}

        <!-- in blog list page alone, show taxonomies/categories and tags  -->
        {{ if eq .Section "blog" }}
        {{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
        {{ if (gt (len $taxonomy) 0) }}
        <li class="taxonomy-section"><a class="pill-slate text-xs" href="{{ " /" | relLangURL}}{{ $taxonomyname | urlize
                }}">{{$taxonomyname}}</a></li>
        {{ end }}
        {{ end }}
        {{ end }}

        {{ end }}

        <!-- TAXONOMY pages like category/tag list pages -->
        {{ if eq .Kind "taxonomy" }}
        <!-- show all posts link  -->
        <li class="taxonomy"><a class="pill-slate text-xs" href="/blog">posts</a></li>
        {{ end }}

        <!-- if TAXONOMY list page has values like categories/tips/ -->
        {{ if eq .Kind "term" }}
        <li class="term"><a class="pill-slate text-xs" href="/{{.Section}}">{{.Section}}</a></li>
        {{ end }}


        {{ range $c := .Params.categories }}
        <!-- skip the parent section if exists-->
        {{ if ne ($c | urlize) $currentSection }}
        <li class="category"><a class="pill-henryc text-xs" href="/categories/{{ $c | urlize }}">{{ $c }}</a></li>
        {{ end }}
        {{ end }}



        {{- partial "nav-after.html" . -}}
    </ul>
</nav>