|
| 1 | +{{ $context := .context -}} |
| 2 | +{{ $sidebarRoot := .sidebarRoot -}} |
| 3 | +{{ $sidebarRootID := .sidebarRootID -}} |
| 4 | +{{ $cacheSidebar := .cacheSidebar -}} |
| 5 | + |
| 6 | +{{ with $context -}} |
| 7 | + |
| 8 | +{{/* When the sidebar is cached, "active" class is set client side. */ -}} |
| 9 | +{{ $shouldDelayActive := $cacheSidebar -}} |
| 10 | + |
| 11 | +<div id="td-sidebar-menu" class="td-sidebar__inner{{ if $shouldDelayActive }} d-none{{ end }}"> |
| 12 | + {{ if not .Site.Params.ui.sidebar_search_disable -}} |
| 13 | + |
| 14 | + <form class="td-sidebar__search d-flex align-items-center"> |
| 15 | + {{ partial "search-input.html" . }} |
| 16 | + <button class="hamburger" type="button" aria-label="Toggle Menu" data-bs-toggle="collapse" data-bs-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation"> |
| 17 | + <span class="hamburger-box"> |
| 18 | + <span class="hamburger-inner"></span> |
| 19 | + </span> |
| 20 | + </button> |
| 21 | + </form> |
| 22 | + <div class="search-by-tag"> |
| 23 | + <a href="{{ "tags/" | relLangURL }}">...or browse by tag</a> |
| 24 | + </div> |
| 25 | + |
| 26 | + {{- else -}} |
| 27 | + |
| 28 | + <div id="content-mobile"> |
| 29 | + <form class="td-sidebar__search d-flex align-items-center"> |
| 30 | + {{ partial "search-input.html" . }} |
| 31 | + <button class="hamburger" type="button" aria-label="Toggle Menu" data-bs-toggle="collapse" data-bs-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation"> |
| 32 | + <span class="hamburger-box"> |
| 33 | + <span class="hamburger-inner"></span> |
| 34 | + </span> |
| 35 | + </button> |
| 36 | + </form> |
| 37 | + </div> |
| 38 | + <div id="content-desktop"></div> |
| 39 | + |
| 40 | + {{- end }} |
| 41 | + {{/* */ -}} |
| 42 | + |
| 43 | + <nav class="td-sidebar-nav collapse |
| 44 | + {{- if .Site.Params.ui.sidebar_search_disable }} td-sidebar-nav--search-disabled{{ end -}} |
| 45 | + {{- if .Site.Params.ui.sidebar_menu_foldable }} foldable-nav{{ end }}" {{/**/ -}} |
| 46 | + id="td-section-nav" |
| 47 | + {{- if .Site.Params.ui.sidebar_root_enabled }} data-sidebar-root-id="{{ $sidebarRootID }}"{{ end -}} |
| 48 | + > |
| 49 | + {{ if and .Site.Params.ui.sidebar_lang_menu (gt (len .Site.Home.Translations) 0) -}} |
| 50 | + <div class="td-sidebar-nav__section nav-item d-block d-lg-none"> |
| 51 | + {{ partial "navbar-lang-selector.html" . }} |
| 52 | + </div> |
| 53 | + {{ end -}} |
| 54 | + {{/* Always use Site.Home as navRoot to show glossary terms on all pages (matching v0.6 behavior) */}} |
| 55 | + {{/* Ignore $sidebarRoot to ensure terms are always shown in sidebar */}} |
| 56 | + {{ $navRoot := .Site.Home -}} |
| 57 | + {{ $ulNr := 0 -}} |
| 58 | + {{ $ulShow := .Site.Params.ui.ul_show | default 1 -}} |
| 59 | + {{ $sidebarMenuTruncate := .Site.Params.ui.sidebar_menu_truncate | default 100 -}} |
| 60 | + <ul class="td-sidebar-nav__section pe-md-3 ul-{{ $ulNr }}"> |
| 61 | + {{ template "section-tree-nav-section" (dict "page" . "section" $navRoot "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" (add $ulShow 1)) }} |
| 62 | + </ul> |
| 63 | + </nav> |
| 64 | +</div> |
| 65 | + |
| 66 | +{{- end }}{{/* with $context */ -}} |
| 67 | + |
| 68 | +{{ define "section-tree-nav-section" -}} |
| 69 | + {{/* cSpell:ignore manuallink manuallinkrelref manuallinktitle */ -}} |
| 70 | + {{ $s := .section -}} |
| 71 | + {{ $p := .page -}} |
| 72 | + {{ $shouldDelayActive := .shouldDelayActive -}} |
| 73 | + {{ $sidebarMenuTruncate := .sidebarMenuTruncate -}} |
| 74 | + {{ $treeRoot := cond (eq .ulNr 0) true false -}} |
| 75 | + {{ $ulNr := .ulNr -}} |
| 76 | + {{ $ulShow := .ulShow -}} |
| 77 | + {{ $active := and (not $shouldDelayActive) (eq $s $p) -}} |
| 78 | + {{ $activePath := and (not $shouldDelayActive) (or (eq $p $s) ($p.IsDescendant $s)) -}} |
| 79 | + {{ $show := cond |
| 80 | + (or |
| 81 | + (lt $ulNr $ulShow) |
| 82 | + $activePath |
| 83 | + (and (not $shouldDelayActive) (eq $s.Parent $p.Parent)) |
| 84 | + (and (not $shouldDelayActive) (eq $s.Parent $p)) |
| 85 | + ) true false |
| 86 | + -}} |
| 87 | + {{ $mid := printf "m-%s" ($s.RelPermalink | anchorize) }} |
| 88 | + {{ $pages := where $s.Pages "Params.toc_hide" "ne" true -}} |
| 89 | + {{ $withChild := gt (len $pages) 0 -}} |
| 90 | + {{ $manualLink := $s.RelPermalink -}} |
| 91 | + {{ with $s.Params.manualLink -}} |
| 92 | + {{ $manualLink = . -}} |
| 93 | + {{ end -}} |
| 94 | + {{ with $s.Params.manualLinkRelref -}} |
| 95 | + {{ $manualLink = relref $s . -}} |
| 96 | + {{ end -}} |
| 97 | + {{ $manualLinkTitle := $s.LinkTitle -}} |
| 98 | + {{ with $s.Params.manualLinkTitle -}} |
| 99 | + {{ $manualLinkTitle = . -}} |
| 100 | + {{ end -}} |
| 101 | + |
| 102 | +<li class="td-sidebar-nav__section-title td-sidebar-nav__section{{ if $withChild }} with-child{{ else }} without-child{{ end }}{{ if $activePath }} active-path{{ end }}{{ if (not (or $show $p.Site.Params.ui.sidebar_menu_foldable )) }} collapse{{ end }}" id="{{ $mid }}-li"> |
| 103 | + {{ if (and $p.Site.Params.ui.sidebar_menu_foldable (ge $ulNr 1)) -}} |
| 104 | + <input type="checkbox" id="{{ $mid }}-check"{{ if $activePath}} checked{{ end }}/> |
| 105 | + <label for="{{ $mid }}-check"><a href="{{ $manualLink }}"{{ if ne $s.LinkTitle $manualLinkTitle }} title="{{ $manualLinkTitle }}"{{ end }}{{ with $s.Params.manualLinkTarget }} target="{{ . }}"{{ if eq . "_blank" }} rel="noopener"{{ end }}{{ end }} class="align-left ps-0 {{ if $active}} active{{ end }} td-sidebar-link{{ if $s.IsPage }} td-sidebar-link__page{{ else }} td-sidebar-link__section{{ end }}{{ if $treeRoot }} tree-root{{ end }}" id="{{ $mid }}"><span class="{{ if $active }}td-sidebar-nav-active-item{{ end }}">{{ $s.LinkTitle }}</span></a></label> |
| 106 | + {{ else -}} |
| 107 | + {{ if not $treeRoot }} |
| 108 | + <a href="{{ $manualLink }}"{{ if ne $s.LinkTitle $manualLinkTitle }} title="{{ $manualLinkTitle }}"{{ end }}{{ with $s.Params.manualLinkTarget }} target="{{ . }}"{{ if eq . "_blank" }} rel="noopener"{{ end }}{{ end }} class="align-left ps-0{{ if $active}} active{{ end }} td-sidebar-link{{ if $s.IsPage }} td-sidebar-link__page{{ else }} td-sidebar-link__section{{ end }}{{ if $treeRoot }} tree-root{{ end }}" id="{{ $mid }}"><span class="{{ if $active }}td-sidebar-nav-active-item{{ end }}">{{ $s.LinkTitle }}</span></a> |
| 109 | + {{- end }} |
| 110 | + {{- end }} |
| 111 | + {{- if $withChild }} |
| 112 | + <ul class="ul-{{ add $ulNr 1 }}{{ if (not (or $show $p.Site.Params.ui.sidebar_menu_foldable )) }} collapse{{ end }}"> |
| 113 | + {{ range $pages -}} |
| 114 | + {{ if (le (len .Title) $sidebarMenuTruncate) -}} |
| 115 | + {{ template "section-tree-nav-section" (dict "page" $p "section" . "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" (add $ulNr 1) "ulShow" $ulShow) }} |
| 116 | + {{ else -}} |
| 117 | + {{ if $p.Site.Params.ui.sidebar_menu_truncate_warn -}} |
| 118 | + {{ warnf "%.40s title [%.40s] > ui.sidebar_menu_truncate: title has %d chars which is > %d. Consider trimming. See https://www.docsy.dev/docs/adding-content/navigation/#menu-size-limit" .Path .Title (len .Title) $sidebarMenuTruncate -}} |
| 119 | + {{ end -}} |
| 120 | + {{ end -}} |
| 121 | + {{ end -}} |
| 122 | + </ul> |
| 123 | + {{- end }} |
| 124 | +</li> |
| 125 | +{{ end -}} |
0 commit comments