new-web

No description
git clone git://niliara.net/new-web
Log | Files | Refs

menu.html (1507B)


      1 <nav>
      2     <a href="/">home</a>
      3     {{ range where site.RegularPages "Section" "" }}
      4         <a href="{{ .RelPermalink }}">{{ .Title }}</a>
      5     {{ end }}
      6 </nav>
      7 
      8 
      9 {{- /*
     10 Renders a menu for the given menu ID.
     11 
     12 @context {page} page The current page.
     13 @context {string} menuID The menu ID.
     14 
     15 @example: {{ partial "menu.html" (dict "menuID" "main" "page" .) }}
     16 
     17 
     18 {{- $page := .page }}
     19 {{- $menuID := .menuID }}
     20 
     21 {{- with index site.Menus $menuID }}
     22   <nav>
     23     <ul>
     24       {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
     25     </ul>
     26   </nav>
     27 {{- end }}
     28 
     29 {{- define "_partials/inline/menu/walk.html" }}
     30   {{- $page := .page }}
     31   {{- range .menuEntries }}
     32     {{- $attrs := dict "href" .URL }}
     33     {{- if $page.IsMenuCurrent .Menu . }}
     34       {{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }}
     35     {{- else if $page.HasMenuCurrent .Menu .}}
     36       {{- $attrs = merge $attrs (dict "class" "ancestor" "aria-current" "true") }}
     37     {{- end }}
     38     {{- $name := .Name }}
     39     {{- with .Identifier }}
     40       {{- with T . }}
     41         {{- $name = . }}
     42       {{- end }}
     43     {{- end }}
     44     <li>
     45       <a
     46         {{- range $k, $v := $attrs }}
     47           {{- with $v }}
     48             {{- printf " %s=%q" $k $v | safeHTMLAttr }}
     49           {{- end }}
     50         {{- end -}}
     51       >{{ $name }}</a>
     52       {{- with .Children }}
     53         <ul>
     54           {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
     55         </ul>
     56       {{- end }}
     57     </li>
     58   {{- end }}
     59 {{- end }}
     60 */}}