Cleanup the menu partials, utilize Hugo features and performance better.

This commit is contained in:
Fredrik Jonsson 2019-07-06 17:37:08 +02:00
commit 63399e6bf8
4 changed files with 16 additions and 13 deletions

View file

@ -225,6 +225,15 @@ To customise a layout included in the zen theme, copy it to the root layout dire
Add any new layouts to the root layout directory as well. This way they will not be overwritten when updating the theme.
#### Menu and sidebar layouts
The default menu will automatically have entries for the home page, each root page and each section, in that order.
If the default sidebar is activated it will display each section with all its pages listed below.
They are set up in `layouts/partials/menu.html`, `layouts/partials/mobilmenu.html` and `layouts/partials/sidebar.html`. The default works nicely for small sites but in many cases they will need to be customised.
### Styles and scripts
Styles and scripts are processed with Hugo pipes that was added in Hugo 0.46.

View file

@ -1,17 +1,14 @@
{{ $home := relLangURL "/" -}}
{{ $currentSection := .Section -}}
{{ $currentID := "" -}}
{{ with .File }}{{ $currentID = .UniqueID }}{{ end -}}
<nav class="main-menu layout__navigation">
<h2 class="visually-hidden">{{ i18n "menu_title" }}</h2>
<ul class="navbar">
<li><a class="{{ if .IsHome }}active{{ end }}" href="{{ $home }}">{{ i18n "menu_home" }}</a></li>
{{ range where .Site.Pages "Section" "" -}}
{{ if ne .RelPermalink (string $home) -}}
{{ with .Site.Home }}<li><a class="{{ if eq $currentID .File.UniqueID }}active{{ end }}" href="{{ .RelPermalink }}">{{ i18n "menu_home" }}</a></li>{{ end }}
{{ range where .Site.RegularPages "Section" "" -}}
<li><a class="{{ if eq $currentID .File.UniqueID }}active{{ end }}" href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end -}}
{{ end -}}
{{ range $.Site.Home.Sections -}}
{{ range .Site.Sections -}}
<li><a class="{{ if eq $currentSection .Section }}active{{ end }}" href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end -}}
</ul>

View file

@ -1,4 +1,3 @@
{{ $home := relLangURL "/" -}}
{{ $currentSection := .Section -}}
{{ $currentID := "" -}}
{{ with .File }}{{ $currentID = .UniqueID }}{{ end -}}
@ -13,13 +12,11 @@
<nav class="mobile-nav__main-menu">
<h2 class="visually-hidden">{{ i18n "menu_title" }}</h2>
<ul class="mobile-nav__navbar">
<li><a class="{{ if .IsHome }}active{{ end }}" href="{{ $home }}">{{ i18n "menu_home" }}</a></li>
{{ range where .Site.Pages "Section" "" -}}
{{ if ne .RelPermalink (string $home) -}}
{{ with .Site.Home }}<li><a class="{{ if eq $currentID .File.UniqueID }}active{{ end }}" href="{{ .RelPermalink }}">{{ i18n "menu_home" }}</a></li>{{ end }}
{{ range where .Site.RegularPages "Section" "" -}}
<li><a class="{{ if eq $currentID .File.UniqueID }}active{{ end }}" href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end -}}
{{ end -}}
{{ range $.Site.Home.Sections -}}
{{ range .Site.Sections -}}
<li><a class="{{ if eq $currentSection .Section }}active{{ end }}" href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end -}}
</ul>

View file

@ -2,7 +2,7 @@
{{ $currentID := "" -}}
{{ with .File }}{{ $currentID = .UniqueID }}{{ end -}}
<aside class="sidebar layout__second-sidebar">
{{ range $.Site.Home.Sections -}}
{{ range .Site.Sections -}}
<section>
<h4 class="menu"><a class="{{ if eq $currentSection .Section }}active{{ end }}" href="{{ .RelPermalink }}">{{ .Title }}</a></h4>
<ul class="menu">