Skip to content

Commit

Permalink
Fixed menu highlight. (#313)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillermo Guerrero Ibarra <[email protected]>
  • Loading branch information
ryanfox1985 and guillermogue authored Aug 12, 2021
1 parent cabdeac commit 22efcc0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions layouts/partials/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,27 @@
<div class="navbar-collapse collapse" id="navigation">
<ul class="nav navbar-nav navbar-right">
{{ $current := . }}
{{ $topLevel := replace .URL "/" "" }}

{{ range .Site.Menus.main.ByWeight }}
{{ $topLevel := replace .URL "/" "" }}
{{ $active := "" }}
{{ if eq $current.RelPermalink .URL | or (eq $current.Type $topLevel) | or (and (eq (default (trim .URL "/") .Identifier) "blog") (in (slice "taxonomy" "taxonomyTerm") $current.Kind)) }}

{{ if eq $current.RelPermalink .URL }}
{{ $active = "active" }}
{{ end }}

{{ if eq $current.Type $topLevel }}
{{ $active = "active" }}
{{ end }}

{{ if and (or (eq $current.URL .URL) (eq "term" $current.Kind)) (in (slice "page" "term") $current.Kind) }}
{{ range (split .URL "/") }}
{{ if eq "blog" . }}
{{ $active = "active" }}
{{ end }}
{{ end }}
{{ end }}

{{ if .HasChildren }}
<!-- Check if the first child marks a menu section identifier -->
{{ $hasSections := (hasPrefix (index .Children 0).Identifier "section.") }}
Expand Down

0 comments on commit 22efcc0

Please sign in to comment.