Files
docker-docs/layouts/partials/sidebar.html
T
2024-09-16 14:43:05 +02:00

91 lines
3.2 KiB
HTML

<!-- section tree -->
<nav class="md:text-sm flex flex-col">
<div
class="block py-4 md:hidden text-gray-light dark:text-gray-dark">This section</div>
{{/* The current page is in the table of contents */}}
<ul>
{{ template "renderChildren" .FirstSection }}
</ul>
</nav>
{{ define "renderChildren" }}
{{- $pages := .Pages }}
{{- if .Params.sidebar.reverse }}
{{ $pages = .Pages.Reverse }}
{{- end }}
{{- range $pages }}
{{- if eq .Params.sitemap false }}
{{- continue }}
{{- end }}
{{- if .IsSection }}
{{- template "renderList" . }}
{{- else }}
{{- template "renderSingle" . }}
{{- end }}
{{- end }}
{{ end }}
{{/* Recursive template for sidebar items */}}
{{ define "renderList" }}
{{ $isCurrent := eq page . }}
{{ $expanded := or $isCurrent (page.IsDescendant .) }}
<li x-data="{ expanded: {{$expanded}} }">
<div class="rounded px-4 w-full flex items-center justify-between{{ if $isCurrent }} bg-gray-light-200 dark:bg-gray-dark-200{{ end }}">
<div class="w-full py-2 truncate">
{{- if .Permalink }}
{{/* If the link is not empty, use it */}}
<a class="block select-none hover:text-blue-light hover:dark:text-blue-dark"
href="{{ .Permalink }}">
{{ template "renderTitle" . }}
</a>
{{- else }}
{{/* Otherwise, just expand the section */}}
<button @click="expanded = !expanded"
class="w-full text-left select-none hover:text-blue-light hover:dark:text-blue-dark">
{{ template "renderTitle" . }}
</button>
{{- end }}
</div>
<button @click="expanded = !expanded" class="hover:bg-gray-light-300 hover:dark:bg-gray-dark-300 rounded">
<span :class="{ 'hidden' : expanded }" class="icon-svg {{ if $expanded }}hidden{{ end }}">
{{ partialCached "icon" "expand_more" "expand_more" }}
</span>
<span :class="{ 'hidden' : !expanded }" class="icon-svg {{ if not $expanded }}hidden{{ end }}">
{{ partialCached "icon" "expand_less" "expand_less" }}
</span>
</button>
</div>
<ul :class="{ 'hidden' : !expanded }" class="{{if not $expanded}}hidden {{end}}ml-3">
{{ template "renderChildren" . }}
</ul>
</li>
{{ end }}
{{ define "renderSingle" }}
{{- if .Params.goto }}
<li class="pl-4 hover:text-blue-light hover:dark:text-blue-dark">
<a class="py-2 w-full truncate block"
href="{{ .Params.goto }}"
title="{{ .LinkTitle }}">
{{ template "renderTitle" . }}
</a>
</li>
{{- else }}
{{ $isCurrent := eq page . }}
<li class="pl-4 hover:text-blue-light hover:dark:text-blue-dark
{{ if $isCurrent }} bg-gray-light-200 dark:bg-gray-dark-200{{ end }}">
<a {{ if $isCurrent }}aria-current="page" {{ end }} class="py-2 w-full truncate block"
href="{{ .Permalink }}" title="{{ .LinkTitle }}">
{{ template "renderTitle" . }}
</a>
</li>
{{- end }}
{{ end }}
{{ define "renderTitle" }}
{{ .LinkTitle }}
{{- with .Params.sidebar.badge }}
<span>{{- partial "components/badge.html" (dict "color" .color "content" .text) }}</span>
{{- end }}
{{ end }}