{{ $docsVersionBasePath := printf "%s" (delimit (first 3 (split .RelPermalink "/")) "/") }}
{{ $docsHome   := $.GetPage $docsVersionBasePath }}
{{ $allDocs    := where $docsHome.Pages "Section" "docs" }}
{{ $docs       := where $allDocs ".Params.kind" "eq" "documentation" }}
{{ $kubernetes := where $allDocs ".Params.kind" "eq" "kubernetes" }}
{{ $envoy      := where $allDocs ".Params.kind" "eq" "envoy" }}
{{ $tutorials  := where $allDocs ".Params.kind" "eq" "tutorial" }}
{{ $operations := where $allDocs ".Params.kind" "eq" "operations" }}
{{ $management := where $allDocs ".Params.kind" "eq" "management" }}
{{ $contrib    := where $allDocs ".Params.kind" "eq" "contrib" }}
{{/* Drop all ecosystem pages in historic versions in favor of hard coded link below */}}
{{ $misc       := where (where $allDocs ".Params.kind" "eq" "misc") ".Title" "ne" "Ecosystem" }}
{{ $support    := where (where (where $allDocs ".Params.kind" "eq" "support") ".Title" "ne" "Ecosystem") ".Title" "ne" "OPA Ecosystem" }}
{{ $pageUrl    := .Permalink }}
{{ $isDocsHome := eq .Permalink $docsHome.Permalink }}
{{ $version    := index (split .File.Path "/") 1 }}
{{ $latest     := index $.Site.Data.releases 1 }}

<span class="docs-nav-title">
  Core Docs
</span>

{{ $docsHomeVersion := $version }}
{{ if or (eq $version $latest) }}
{{ $docsHomeVersion = "latest" }}
{{ end }}
<a class="docs-nav-item{{ if $isDocsHome }} is-active{{ end }}" href="/docs/{{ $docsHomeVersion }}">
  {{ $docsHome.Name }}
</a>

{{ if $isDocsHome }}
<div class="toc">
  {{ .TableOfContents }}
</div>
{{ end }}

{{ range $docs }}
{{ partial "docs/sidenav-link.html" (dict "ctx" . "pageUrl" $pageUrl "version" $version) }}
{{ end }}

{{ partial "docs/sidenav-section.html" ( dict "ctx" . "sectionTitle" "Kubernetes" "section" $kubernetes "pageUrl" $pageUrl "version" $version ) }}

{{ partial "docs/sidenav-section.html" ( dict "ctx" . "sectionTitle" "Envoy" "section" $envoy "pageUrl" $pageUrl "version" $version ) }}

{{ partial "docs/sidenav-section.html" ( dict "ctx" . "sectionTitle" "Other Use Cases" "section" $tutorials "pageUrl" $pageUrl "version" $version ) }}

{{ partial "docs/sidenav-section.html" ( dict "ctx" . "sectionTitle" "Operations" "section" $operations "pageUrl" $pageUrl "version" $version ) }}

{{ partial "docs/sidenav-section.html" ( dict "ctx" . "sectionTitle" "Management APIs" "section" $management "pageUrl" $pageUrl "version" $version ) }}

{{ partial "docs/sidenav-section.html" ( dict "ctx" . "sectionTitle" "Contributing" "section" $contrib "pageUrl" $pageUrl "version" $version ) }}

{{ partial "docs/sidenav-section.html" ( dict "ctx" . "sectionTitle" "Miscellaneous" "section" $misc "pageUrl" $pageUrl "version" $version ) }}

{{ partial "docs/sidenav-section.html" ( dict "ctx" . "sectionTitle" "Support" "section" $support "pageUrl" $pageUrl "version" $version ) }}

<a class="docs-nav-item" href="/ecosystem">OPA Ecosystem</a>
<a class="docs-nav-item" href="/support">Enterprise</a>
