mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Patrick Kollitsch
19 hours ago c70b22c0c65d21fc25eda46a8182eb042da11da0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{{- /* @deprecated 2.21.0 remove in 3.0.0: remove this marker, it only detects site overrides of this partial (see #1120) */ -}}
{{- .Store.Set "ananke.deprecated.theme-partial.site-navigation.html" true -}}
{{- /*
  Site header navigation.
 
  The layout comes from `ananke.header.navigation` (page front matter or site
  parameters): a list of groups, and each group is a list of component names
  (or one component name). Every component renders through the header hooks
  (see `header/component.html`). Each group gets one role:
 
    - panel (`ananke-nav-panel`): the first group with the `menu` component.
      Below the Tachyons `-l` breakpoint it collapses behind the menu button,
      which is rendered directly before it.
    - lead (`ananke-nav-lead`): the first group with the `logo` component, or
      else the first other group. Below `-l` it shares the first row with the
      menu button.
    - slot (`ananke-nav-slot`): every other group, for example a search box.
      Below `-l` it gets its own row; from `-l` it can grow.
 
  Every element has a stable `ananke-nav-*` or `ananke-submenu*` hook class
  for custom CSS. The Tachyons classes next to it are defaults; replace them
  per element with `[params.ananke.navigation.classes]`. Collapsing and the
  dropdown position are in _styles.css.
 
  Without JavaScript, the menu and all submenus are visible and the toggle
  buttons stay hidden. site-scripts.html enhances both.
*/ -}}
{{- $classes := partials.Include "func/header/GetNavigationClasses.html" . -}}
{{- $mode := partials.Include "func/header/GetSubmenuMode.html" (dict "page" .) -}}
{{- $header := collections.Dictionary
  "page" .
  "region" "navigation"
  "featured_image" (partials.Include "func/GetFeaturedImage.html" .)
  "classes" $classes
  "submenu_mode" $mode
-}}
 
{{- /* Normalise the layout to a list of non-empty groups. Each group is a
       dictionary, because Hugo cannot append a slice to a slice of slices. */ -}}
{{- $layout := .Param "ananke.header.navigation" | compare.Default (collections.Slice
  (collections.Slice "logo")
  (collections.Slice "languages" "menu" "social")
) -}}
{{- $groups := collections.Slice -}}
{{- range $layout -}}
  {{- $group := . -}}
  {{- if not (reflect.IsSlice $group) -}}
    {{- $group = collections.Slice $group -}}
  {{- end -}}
  {{- with $group -}}
    {{- $groups = $groups | collections.Append (collections.Dictionary "components" .) -}}
  {{- end -}}
{{- end -}}
 
{{- /* Find the panel group and the lead group (see above). */ -}}
{{- $panel := -1 -}}
{{- range $index, $group := $groups -}}
  {{- if and (compare.Lt $panel 0) (collections.In $group.components "menu") -}}
    {{- $panel = $index -}}
  {{- end -}}
{{- end -}}
{{- $lead := -1 -}}
{{- range $index, $group := $groups -}}
  {{- if and (compare.Lt $lead 0) (compare.Ne $index $panel) (collections.In $group.components "logo") -}}
    {{- $lead = $index -}}
  {{- end -}}
{{- end -}}
{{- if compare.Lt $lead 0 -}}
  {{- range $index, $group := $groups -}}
    {{- if and (compare.Lt $lead 0) (compare.Ne $index $panel) -}}
      {{- $lead = $index -}}
    {{- end -}}
  {{- end -}}
{{- end -}}
 
<nav class="ananke-nav {{ $classes.nav }}" role="navigation" data-submenu-mode="{{ $mode }}">
  <div class="ananke-nav-inner {{ $classes.inner }}">
    {{- range $index, $group := $groups }}
    {{- if compare.Eq $index $panel }}
    {{- if $.Site.Menus.main }}
    <button type="button" class="ananke-nav-toggle {{ $classes.toggle }}" aria-expanded="false" aria-controls="ananke-nav-panel" hidden>
      {{- partials.Include "header/menu-toggle-icon.html" -}}
      <span class="ananke-nav-toggle-label">{{ lang.Translate "menuToggle" }}</span>
    </button>
    {{- end }}
    <div id="ananke-nav-panel" class="ananke-nav-group ananke-nav-panel {{ $classes.panel }}">
    {{- else }}
    <div class="ananke-nav-group {{ compare.Conditional (compare.Eq $index $lead) "ananke-nav-lead" "ananke-nav-slot" }} {{ $classes.group }}">
    {{- end }}
      {{- range $group.components }}
      {{ partials.Include "header/component.html" (collections.Dictionary "name" . "context" $header) }}
      {{- end }}
    </div>
    {{- end }}
  </div>
</nav>