1
Fork 0

Clean up navbar code more

This commit is contained in:
Jake Howard 2017-09-23 14:53:17 +01:00
parent 8f80a63f5c
commit c9c90eea4b
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 48 additions and 29 deletions

View file

@ -1,37 +1,15 @@
<header id="header" {{ if .IsHome }}class="alt"{{ end }}>
<h1><a href="/" class="navbar-brand">{{ title .Site.Title }}</a></h1>
<nav id="nav">
<ul>
{{ $home := .Site.GetPage "home" }}
{{ range where .Site.Pages.ByTitle "Kind" "section" }}
{{ if eq .Parent $home }}
{{ $sorted_pages := sort .Site.Pages (default "Title" .Params.sort_by) (default "asc" .Params.sort_order)}}
{{ $valid_children := where $sorted_pages ".Parent" "!=" nil }}
{{ $children := where $valid_children ".Parent.UniqueID" .UniqueID }}
{{ $children := where $children ".Params.hide_in_nav" "!=" "true" }}
<li class="top-level">
{{ partial "navbar/link-item.html" . }}
{{ if $children }}
<ul>
{{ range first .Site.Params.nav_items $children }}
<li>
{{ partial "navbar/link-item.html" . }}
<ul>{{ range .Pages }}<li>{{ partial "navbar/link-item.html" . }}</li>{{ end }}</ul>
</li>
{{ end }}
{{ if ge (len $children) .Site.Params.nav_items }}
<li><a href="{{ .Permalink }}"><i>See more</i></a></li>
{{ end }}
</ul>
{{ end }}
</li>
{{ end }}
{{ end }}
{{ partial "navbar/sections.html" . }}
{{ range where .Site.Pages.ByTitle "Kind" "page" }}
{{ if eq .Section "" }}<li class="top-level">{{ partial "navbar/link-item.html" . }}</li>{{ end }}
{{ end }}
<li class="top-level"><a class="show-mobile" href="/">Home</a></li>
{{ partial "navbar/pages.html" . }}
<li class="top-level">
<a class="show-mobile" href="/">Home</a>
</li>
</ul>
</nav>
</header>

View file

@ -0,0 +1,7 @@
{{ range where .Site.Pages.ByTitle "Kind" "page" }}
{{ if eq .Section "" }}
<li class="top-level">
{{ partial "navbar/link-item.html" . }}
</li>
{{ end }}
{{ end }}

View file

@ -0,0 +1,34 @@
{{ $valid_children := where (where .Site.Pages ".Parent" "!=" nil) ".Params.hide_in_nav" "!=" "true" }}
{{ $home := .Site.GetPage "home" }}
{{ range where .Site.Pages.ByTitle "Kind" "section" }}
{{ if eq .Parent $home }}
{{ $sorted_pages := sort $valid_children (default "Title" .Params.sort_by) (default "asc" .Params.sort_order)}}
{{ $children := where $sorted_pages ".Parent.UniqueID" .UniqueID }}
<li class="top-level">
{{ partial "navbar/link-item.html" . }}
{{ if $children }}
<ul>
{{ range first .Site.Params.nav_items $children }}
<li>
{{ partial "navbar/link-item.html" . }}
{{ $children := where $sorted_pages ".Parent.UniqueID" .UniqueID }}
{{ if $children }}
<ul>
{{ range first .Site.Params.nav_items $children }}<li>{{ partial "navbar/link-item.html" . }}</li>{{ end }}
{{ if ge (len $children) .Site.Params.nav_items }}
<li><a href="{{ .Permalink }}"><i>See more</i></a></li>
{{ end }}
</ul>
{{ end }}
</li>
{{ end }}
{{ if ge (len $children) .Site.Params.nav_items }}
<li><a href="{{ .Permalink }}"><i>See more</i></a></li>
{{ end }}
</ul>
{{ end }}
</li>
{{ end }}
{{ end }}