Skip to content

Commit

Permalink
Menu respects weight property.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidized committed Jan 2, 2023
1 parent 12c173e commit ace8404
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ paginate = 5
identifier = "about"
name = "About"
url = "/about"
weight = 2
[[languages.en.menu.main]]
identifier = "now"
name = "Now"
url = "/now"
weight = 1
[[languages.en.menu.main]]
identifier = "showcase"
name = "Showcase"
url = "/showcase"
weight = 3
8 changes: 4 additions & 4 deletions layouts/partials/menu.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav class="menu">
<ul class="menu__inner menu__inner--desktop">
{{ if or $.Site.Params.showMenuItems (eq $.Site.Params.showMenuItems 0) }}
{{ range first $.Site.Params.showMenuItems $.Site.Menus.main }}
{{ range first $.Site.Params.showMenuItems (sort $.Site.Menus.main "Weight") }}
{{ if not .HasChildren }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
Expand All @@ -15,7 +15,7 @@
>
</li>
<ul class="menu__sub-inner-more hidden">
{{ range last (sub (len $.Site.Menus.main) $.Site.Params.showMenuItems) $.Site.Menus.main }}
{{ range last (sub (len $.Site.Menus.main) $.Site.Params.showMenuItems) (sort $.Site.Menus.main "Weight") }}
{{ if not .HasChildren }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
Expand All @@ -24,7 +24,7 @@
</ul>
{{ end }}
{{ else }}
{{ range $.Site.Menus.main }}
{{ range sort $.Site.Menus.main "Weight" }}
{{ if not .HasChildren }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
Expand All @@ -33,7 +33,7 @@
</ul>

<ul class="menu__inner menu__inner--mobile">
{{ range $.Site.Menus.main }}
{{ range sort $.Site.Menus.main "Weight" }}
{{ if not .HasChildren }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
Expand Down

0 comments on commit ace8404

Please sign in to comment.