sidebar-tree.html 5.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. {{/* We cache this partial for bigger sites and set the active class client side. */ -}}
  2. {{ $sidebarCacheLimit := .Site.Params.ui.sidebar_cache_limit | default 2000 -}}
  3. {{ $shouldDelayActive := ge (len .Site.Pages) $sidebarCacheLimit -}}
  4. <div id="td-sidebar-menu" class="td-sidebar__inner{{ if $shouldDelayActive }} d-none{{ end }}">
  5. {{ if not .Site.Params.ui.sidebar_search_disable -}}
  6. <form class="td-sidebar__search d-flex align-items-center">
  7. {{ partial "search-input.html" . }}
  8. <button class="btn btn-link td-sidebar__toggle d-md-none p-0 ms-3 fas fa-bars" type="button" data-bs-toggle="collapse" data-bs-target="#td-section-nav" aria-controls="td-section-nav" aria-expanded="false" aria-label="Toggle section navigation">
  9. </button>
  10. </form>
  11. {{ else -}}
  12. <div id="content-mobile">
  13. <form class="td-sidebar__search d-flex align-items-center">
  14. {{ partial "search-input.html" . }}
  15. <button class="btn btn-link td-sidebar__toggle d-md-none p-0 ms-3 fas fa-bars" type="button" data-bs-toggle="collapse" data-bs-target="#td-section-nav" aria-controls="td-section-nav" aria-expanded="false" aria-label="Toggle section navigation">
  16. </button>
  17. </form>
  18. </div>
  19. <div id="content-desktop"></div>
  20. {{ end -}}
  21. <nav class="td-sidebar-nav collapse
  22. {{- if .Site.Params.ui.sidebar_search_disable }} td-sidebar-nav--search-disabled{{ end -}}
  23. {{- if .Site.Params.ui.sidebar_menu_foldable }} foldable-nav{{ end -}}
  24. " id="td-section-nav">
  25. {{ if (gt (len .Site.Home.Translations) 0) -}}
  26. <div class="td-sidebar-nav__section nav-item dropdown d-block d-lg-none">
  27. {{ partial "navbar-lang-selector.html" . }}
  28. </div>
  29. {{ end -}}
  30. {{ $navRoot := cond (and (ne .Params.toc_root true) (eq .Site.Home.Type "docs")) .Site.Home .FirstSection -}}
  31. {{ $ulNr := 0 -}}
  32. {{ $ulShow := .Site.Params.ui.ul_show | default 1 -}}
  33. {{ $sidebarMenuTruncate := .Site.Params.ui.sidebar_menu_truncate | default 100 -}}
  34. <ul class="td-sidebar-nav__section pe-md-3 ul-{{ $ulNr }}">
  35. {{ template "section-tree-nav-section" (dict "page" . "section" $navRoot "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" (add $ulShow 1)) }}
  36. </ul>
  37. </nav>
  38. </div>
  39. {{ define "section-tree-nav-section" -}}
  40. {{ $s := .section -}}
  41. {{ $p := .page -}}
  42. {{ $shouldDelayActive := .shouldDelayActive -}}
  43. {{ $sidebarMenuTruncate := .sidebarMenuTruncate -}}
  44. {{ $treeRoot := cond (eq .ulNr 0) true false -}}
  45. {{ $ulNr := .ulNr -}}
  46. {{ $ulShow := .ulShow -}}
  47. {{ $active := and (not $shouldDelayActive) (eq $s $p) -}}
  48. {{ $activePath := and (not $shouldDelayActive) (or (eq $p $s) ($p.IsDescendant $s)) -}}
  49. {{ $show := cond (or (lt $ulNr $ulShow) $activePath (and (not $shouldDelayActive) (eq $s.Parent $p.Parent)) (and (not $shouldDelayActive) (eq $s.Parent $p)) (not $p.Site.Params.ui.sidebar_menu_compact) (and (not $shouldDelayActive) ($p.IsDescendant $s.Parent))) true false -}}
  50. {{ $mid := printf "m-%s" ($s.RelPermalink | anchorize) -}}
  51. {{ $pages_tmp := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true -}}
  52. {{ $pages := $pages_tmp | first $sidebarMenuTruncate -}}
  53. {{ $truncatedEntryCount := sub (len $pages_tmp) $sidebarMenuTruncate -}}
  54. {{ if gt $truncatedEntryCount 0 -}}
  55. {{ warnf "WARNING: %d sidebar entries have been truncated. To avoid this, increase `params.ui.sidebar_menu_truncate` to at least %d (from %d) in your config file. Section: %s"
  56. $truncatedEntryCount (len $pages_tmp) $sidebarMenuTruncate $s.Path -}}
  57. {{ end -}}
  58. {{ $withChild := gt (len $pages) 0 -}}
  59. {{ $manualLink := cond (isset $s.Params "manuallink") $s.Params.manualLink ( cond (isset $s.Params "manuallinkrelref") (relref $s $s.Params.manualLinkRelref) $s.RelPermalink) -}}
  60. {{ $manualLinkTitle := cond (isset $s.Params "manuallinktitle") $s.Params.manualLinkTitle $s.Title -}}
  61. <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">
  62. {{ if (and $p.Site.Params.ui.sidebar_menu_foldable (ge $ulNr 1)) -}}
  63. <input type="checkbox" id="{{ $mid }}-check"{{ if $activePath}} checked{{ end }}/>
  64. <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 }}">{{ with $s.Params.Icon}}<i class="{{ . }}"></i>{{ end }}<span class="{{ if $active }}td-sidebar-nav-active-item{{ end }}">{{ $s.LinkTitle }}</span></a></label>
  65. {{ else -}}
  66. <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 }}">{{ with $s.Params.Icon}}<i class="{{ . }}"></i>{{ end }}<span class="{{ if $active }}td-sidebar-nav-active-item{{ end }}">{{ $s.LinkTitle }}</span></a>
  67. {{- end }}
  68. {{- if $withChild }}
  69. {{- $ulNr := add $ulNr 1 }}
  70. <ul class="ul-{{ $ulNr }}{{ if (gt $ulNr 1)}} foldable{{end}}">
  71. {{ range $pages -}}
  72. {{ if (not (and (eq $s $p.Site.Home) (eq .Params.toc_root true))) -}}
  73. {{ template "section-tree-nav-section" (dict "page" $p "section" . "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" $ulShow) }}
  74. {{- end }}
  75. {{- end }}
  76. </ul>
  77. {{- end }}
  78. </li>
  79. {{- end -}}