book_menu.html 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. {{ define "book-menu" }}
  2. {{- $first := false -}}
  3. {{- $current_node := .current_node -}}
  4. {{- $is_root := .is_root -}}
  5. {{- $order_by := .order_by -}}
  6. {{ $icon := "" }}
  7. {{ with .sect }}
  8. {{ if .IsSection }}
  9. {{ if not $is_root }}
  10. {{- $first = (eq $current_node.FirstSection.Type "book") | and (eq $current_node.FirstSection .) -}}
  11. {{ end }}
  12. {{- safeHTML $current_node.FirstSection.Params.pre_nav -}}
  13. {{/* Get section icon. */}}
  14. {{ $pack := or .Params.icon_pack "fas" }}
  15. {{ $pack_prefix := $pack }}
  16. {{ if in (slice "fab" "fas" "far" "fal") $pack }}
  17. {{ $pack_prefix = "fa" }}
  18. {{ end }}
  19. {{ with .Params.icon }}
  20. {{- if eq $pack "emoji" -}}
  21. {{- . | emojify -}}
  22. {{- else if eq $pack "custom" -}}
  23. {{- $svg_icon := resources.Get (printf "media/icons/%s.svg" .) -}}
  24. {{- if $svg_icon -}}
  25. {{ $icon = printf "<img src=\"%s\" alt=\"%s\" class=\"svg-icon svg-baseline pr-1\">" $svg_icon.RelPermalink . }}
  26. {{- end -}}
  27. {{- else -}}
  28. {{ $icon = printf "<i class=\"%s %s-%s pr-1\"></i>" $pack $pack_prefix . }}
  29. {{- end -}}
  30. {{ end }}
  31. {{ if $first }}
  32. <ul class="nav docs-sidenav">
  33. <li class="{{ if and .File $current_node.File | and (eq .File.UniqueID $current_node.File.UniqueID) }}active{{ end }}"><a href="{{ .RelPermalink }}">{{ safeHTML $icon }}{{ .LinkTitle | default .Title }}</a></li>
  34. {{else}}
  35. <div class="docs-toc-item">
  36. <a class="docs-toc-link {{ if and .File $current_node.File | and (eq .File.UniqueID $current_node.File.UniqueID) }} active{{ end }}" href="{{ .RelPermalink }}">{{ safeHTML $icon }}{{ .LinkTitle | default .Title }}</a>
  37. {{end}}
  38. {{- $page_count := (add (len .Pages) (len .Sections)) -}}
  39. {{ if ne $page_count 0 }}
  40. {{ if not $first }}
  41. <ul class="nav docs-sidenav">
  42. {{end}}
  43. {{- .Scratch.Set "pages" .Pages -}}
  44. {{- if .Sections -}}
  45. {{- .Scratch.Set "pages" (.Pages | union .Sections) -}}
  46. {{- end -}}
  47. {{- $pages := (.Scratch.Get "pages") -}}
  48. {{- if eq $order_by "title" -}}
  49. {{- range $pages.ByTitle -}}
  50. {{ template "book-menu" dict "sect" . "current_node" $current_node "order_by" $order_by }}
  51. {{- end -}}
  52. {{- else if eq $order_by "title_desc" -}}
  53. {{- range $pages.ByTitle.Reverse -}}
  54. {{ template "book-menu" dict "sect" . "current_node" $current_node "order_by" $order_by }}
  55. {{- end -}}
  56. {{- else -}}
  57. {{- range $pages.ByWeight -}}
  58. {{ template "book-menu" dict "sect" . "current_node" $current_node "order_by" $order_by }}
  59. {{- end -}}
  60. {{- end}}
  61. {{ if not $first }}
  62. </ul>
  63. {{end}}
  64. {{end}}
  65. {{ if not $first }}
  66. </div>
  67. {{else}}
  68. </ul>
  69. {{end}}
  70. {{- else -}}
  71. {{- if not .Params.Hidden -}}
  72. <li class="{{ if and .File $current_node.File | and (eq .File.UniqueID $current_node.File.UniqueID) }}active{{ end }}"><a href="{{ .RelPermalink }}">{{ safeHTML $icon }}{{ .LinkTitle | default .Title }}</a></li>
  73. {{- end -}}
  74. {{ end -}}
  75. {{- end -}}
  76. {{/* End define. */}}
  77. {{ end -}}