1
Fork 0

Add dropdowns to nav

This commit is contained in:
Jake Howard 2017-10-28 16:28:45 +01:00
parent 2f8ac87c87
commit 92f24f8644
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 26 additions and 10 deletions

View file

@ -15,21 +15,13 @@
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-black fixed-top">
<a class="navbar-brand" href="{{ .Site.BaseURL }}">/home/{{ lower .Site.Title }}</a>
<a class="navbar-brand" href="{{ .Site.BaseURL }}"><code>/home/{{ lower .Site.Title }}</code></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
{{ partial "nav_pages.html" . }}
</ul>
<div class="d-none d-sm-block">

View file

@ -0,0 +1,24 @@
{{ $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="nav-item{{ if $children }} dropdown{{ end }}">
<a href="{{ .Permalink }}" class="nav-link{{ if $children }}{{ end }}"{{ if $children }} data-toggle="dropdown"{{ end }}><code>~/{{ .LinkTitle }}</code></a>
{{ if $children }}
<div class="dropdown-menu">
{{ range first .Site.Params.nav_items $children }}
<a class="dropdown-item" href="{{ .Permalink }}"><code>{{ .LinkTitle }}</code></a>
{{ end }}
{{ if ge (len $children) .Site.Params.nav_items }}
<div class="dropdown-divider"></div>
<a class="dropdown-item font-italic" href="{{ .Permalink }}"><code>See More</code></a>
{{ end }}
</div>
{{ end }}
</li>
{{ end }}
{{ end }}