diff --git a/layouts/_default/list.html b/layouts/_default/list.html
index 8d1fdab11d..c536b82900 100644
--- a/layouts/_default/list.html
+++ b/layouts/_default/list.html
@@ -1,10 +1,13 @@
-{{ partial "header.html" . }}
{{ if .Content }}
+{{ partial "header.html" . }}
{{ .Content }}
-{{ else }}
-{{ with (index (index .Site.Sections .Section) 0) }}
-{{ .Page.Content }}
-{{ $.Scratch.Set "uniqueId" .Page.UniqueID }}
-{{ end }}
-{{ end }}
{{ partial "footer.html" . }}
+{{ else }}
+{{ with (index (index .Site.Sections .Section) 0) }}
+{{ with .Page }}
+{{ partial "header.html" . }}
+{{ .Content }}
+{{ partial "footer.html" . }}
+{{ end }}
+{{ end }}
+{{ end }}
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index 8e84557123..2c75ee3897 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -1,5 +1,5 @@
- {{ $isChapter := or (eq .Kind "section") (.Params.chapter)}}
+ {{ $isChapter := .Params.chapter | default (eq .Kind "section")}}
{{ if $isChapter }}
{{ end }}
@@ -33,8 +33,7 @@
{{ if $.Site.Params.autoNav }}
{{ $allpages := $.Scratch.Get "_allpages" }}
{{ range $index, $element := $allpages }}
- {{ $uniqueid := ($.Scratch.Get "uniqueId" | default $.UniqueID ) }}
- {{if eq $element.UniqueID $uniqueid }}
+ {{if eq $element.UniqueID $.UniqueID }}
{{ if not (isset $.Params "prev") }}
{{ with index $allpages (sub $index 1) }}
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index c61851a5fe..a9882a9cb7 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -22,7 +22,7 @@
{{ partial "style.html" . }}
- {{ $isChapter := or (eq .Kind "section") (.Params.chapter)}}
+ {{ $isChapter := .Params.chapter | default (eq .Kind "section")}}
{{ partial "menu.html" . }}
@@ -51,14 +51,17 @@
{{ if and (not $isChapter) (.Params.toc) }}
{{ end }}
- {{ $type := .Type }}
- {{ $relLink := .RelPermalink }}
- {{ range $name , $value := .Site.Sections }}
- {{ if eq $name $type }}
- {{ $first := (index $value 0).Page }}
- {{ if ne $first.RelPermalink $relLink }}
- {{ $first.Title }}
- {{ end }}
+ {{ $section := index .Site.Sections .Section }}
+ {{ $sectionPage := $.Site.GetPage "section" $.Section }}
+ {{ if $sectionPage.Content }}
+ {{ $first := $.Site.GetPage "section" $.Section }}
+ {{ if ne $first.UniqueID $.UniqueID }}
+ {{ $first.Title }}
+ {{ end }}
+ {{ else if gt $section.Len 0 }}
+ {{ $first := (index $section 0).Page }}
+ {{ if ne $first.UniqueID $.UniqueID }}
+ {{ $first.Title }}
{{ end }}
{{ end }}
{{ with .Title }} {{ . }}{{ end }}
diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html
index 67d72026e9..8e60b3b658 100644
--- a/layouts/partials/menu.html
+++ b/layouts/partials/menu.html
@@ -11,13 +11,17 @@
- {{ $page := . }}
{{ if $.Site.Params.menu }}
{{ $.Scratch.Set "menuItems" $.Site.Params.menu }}
{{ else }}
{{ $.Scratch.Set "_pages" (slice) }}
{{ range $key, $value := .Site.Sections }}
- {{ $.Scratch.Add "_pages" ($.Site.GetPage "section" $key) }}
+ {{ $sectionPage := $.Site.GetPage "section" $key }}
+ {{ if $sectionPage.Content }}
+ {{ $.Scratch.Add "_pages" $sectionPage }}
+ {{ else if gt $value.Len 0 }}
+ {{ $.Scratch.Add "_pages" (index $value 0).Page }}
+ {{ end }}
{{ end }}
{{ $.Scratch.Set "menuItems" (slice)}}
{{ range $key, $value := sort ($.Scratch.Get "_pages") "Weight" }}
@@ -28,12 +32,12 @@
{{ range $i, $key := $menuItems }}
{{ if ne $key "" }}
- {{ $value := (index $page.Site.Sections $key) }}
+ {{ $value := (index $.Site.Sections $key) }}
{{ $.Scratch.Set "_value" $value }}
{{ with $index := $.Site.GetPage "section" $key }}
{{ if .Content }}
{{ $.Scratch.Set "first" $index }}
- {{ else }}
+ {{ else if gt $value.Len 0}}
{{ $.Scratch.Set "first" (index $value 0).Page }}
{{ if gt $value.Len 1 }}
{{ $.Scratch.Set "_value" (after 1 $value) }}
@@ -45,14 +49,14 @@
{{ $first := $.Scratch.Get "first" }}
{{ $value := $.Scratch.Get "_value" }}
- -
+
-
{{ if isset $first.Params "icon" }}
{{ printf $first.Params.icon | safeHTML }}
{{ end }}
{{ $first.Title }}
- {{ if $page.Site.Params.showVisitedLinks}}
+ {{ if $.Site.Params.showVisitedLinks}}
{{ end }}
@@ -60,9 +64,9 @@
{{ if gt $value.Len 0}}