diff --git a/layouts/index.json b/layouts/index.json
index 4128c70bfc..dc4d9cff74 100644
--- a/layouts/index.json
+++ b/layouts/index.json
@@ -1,6 +1,6 @@
{{- $pages := slice }}
{{- range .Site.Pages }}
-{{- if and (ne .Site.Params.disableSearchHiddenPages true) (or (ne .Params.hidden true) (ne .Title "")) }}
+{{- if or (ne (.Scratch.Get "relearnIsHiddenTree") true) (ne .Site.Params.disableSearchHiddenPages true) }}
{{- $pages = $pages | append (dict "uri" .RelPermalink "title" .Title "tags" .Params.tags "description" .Description "content" (.Plain | htmlUnescape)) }}
{{- end }}
{{- end }}
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index d72f2e75b2..3df7b1ce7c 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -7,63 +7,12 @@
- {{ $currentNode := . }}
-
- {{ $currentNode.Scratch.Set "selfFound" nil }}
- {{ $currentNode.Scratch.Set "prevPage" nil }}
- {{ $currentNode.Scratch.Set "nextPage" nil }}
- {{ template "menu-nextprev" dict "menu" .Site.Home "currentnode" $currentNode "hidden" false }}
-
- {{ define "menu-nextprev" }}
- {{ $currentNode := .currentnode }}
- {{ $isSelf := eq $currentNode.RelPermalink .menu.RelPermalink }}
- {{ $isDescendant := and (not $isSelf) (.menu.IsDescendant $currentNode) }}
- {{ $isAncestor := and (not $isSelf) (.menu.IsAncestor $currentNode) }}
- {{ $isOther := and (not $isDescendant) (not $isSelf) (not $isAncestor) }}
-
- {{ if $isSelf }}
- {{ $currentNode.Scratch.Set "selfFound" true }}
- {{end}}
- {{ $isSelfFound := eq ($currentNode.Scratch.Get "selfFound") true }}
- {{ $isPreSelf := and (not $isSelfFound) (not $isSelf) }}
- {{ $isPostSelf := and ($isSelfFound) (not $isSelf) }}
-
- {{ $page_hidden := or (.menu.Params.hidden) (eq .menu.Title "") }}
- {{ $hidden := or (and $page_hidden (not $isAncestor) (not $isSelf) ) (and .hidden (or $isPreSelf $isPostSelf $isDescendant) ) }}
-
- {{ if not $hidden }}
- {{if and $isPreSelf (or $isOther $isAncestor ) }}
- {{ $currentNode.Scratch.Set "prevPage" .menu }}
- {{else if and $isPostSelf (or $isOther $isDescendant) (eq ($currentNode.Scratch.Get "nextPage") nil) }}
- {{ $currentNode.Scratch.Set "nextPage" .menu }}
- {{end}}
- {{ end }}
-
- {{ $currentNode.Scratch.Set "pages" .menu.Pages }}
- {{ if .menu.IsHome}}
- {{ $currentNode.Scratch.Set "pages" .menu.Sections }}
- {{ else if .menu.Sections}}
- {{ $currentNode.Scratch.Set "pages" (.menu.Pages | union .menu.Sections) }}
- {{end}}
- {{ $pages := ($currentNode.Scratch.Get "pages") }}
-
- {{if eq .Site.Params.ordersectionsby "title"}}
- {{ range $pages.ByTitle }}
- {{ template "menu-nextprev" dict "menu" . "currentnode" $currentNode "hidden" $hidden }}
- {{end}}
- {{else}}
- {{ range $pages.ByWeight }}
- {{ template "menu-nextprev" dict "menu" . "currentnode" $currentNode "hidden" $hidden }}
- {{end}}
- {{ end }}
- {{ end }}
-
{{$showPrevNext := (and (not .Params.disableNextPrev) (not .Site.Params.disableNextPrev))}}
{{if $showPrevNext}}
- {{with ($.Scratch.Get "prevPage")}}
+ {{with ($.Scratch.Get "relearnPrevPage")}}
{{end}}
- {{with ($.Scratch.Get "nextPage")}}
+ {{with ($.Scratch.Get "relearnNextPage")}}
{{end}}
{{end}}
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index cf9dc7ad46..dc049fee5e 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -38,6 +38,59 @@
{{ partial "custom-header.html" . }}
+ {{- $currentNode := . }}
+ {{- $currentNode.Scratch.Set "relearnIsSelfFound" nil }}
+ {{- $currentNode.Scratch.Set "relearnPrevPage" nil }}
+ {{- $currentNode.Scratch.Set "relearnNextPage" nil }}
+ {{- template "relearn-structure" dict "node" .Site.Home "currentnode" $currentNode "hidden" false }}
+
+ {{- define "relearn-structure" }}
+ {{- $currentNode := .currentnode }}
+ {{- $isSelf := eq $currentNode.RelPermalink .node.RelPermalink }}
+ {{- $isDescendant := and (not $isSelf) (.node.IsDescendant $currentNode) }}
+ {{- $isAncestor := and (not $isSelf) (.node.IsAncestor $currentNode) }}
+ {{- $isOther := and (not $isDescendant) (not $isSelf) (not $isAncestor) }}
+
+ {{- if $isSelf }}
+ {{- $currentNode.Scratch.Set "relearnIsSelfFound" true }}
+ {{- end}}
+ {{- $isSelfFound := eq ($currentNode.Scratch.Get "relearnIsSelfFound") true }}
+ {{- $isPreSelf := and (not $isSelfFound) (not $isSelf) }}
+ {{- $isPostSelf := and ($isSelfFound) (not $isSelf) }}
+
+ {{- $hidden_node := or (.node.Params.hidden) (eq .node.Title "") }}
+ {{- $hidden_tree:= or $hidden_node .hidden }}
+ {{- $hidden_from_current := or (and $hidden_node (not $isAncestor) (not $isSelf) ) (and .hidden (or $isPreSelf $isPostSelf $isDescendant) ) }}
+ {{- .node.Scratch.Set "relearnIsHiddenNode" $hidden_node}}
+ {{- .node.Scratch.Set "relearnIsHiddenTree" $hidden_tree}}
+ {{- .node.Scratch.Set "relearnIsHiddenFromCurrent" $hidden_from_current}}
+
+ {{- if not $hidden_from_current }}
+ {{- if and $isPreSelf (or $isOther $isAncestor ) }}
+ {{- $currentNode.Scratch.Set "relearnPrevPage" .node }}
+ {{- else if and $isPostSelf (or $isOther $isDescendant) (eq ($currentNode.Scratch.Get "relearnNextPage") nil) }}
+ {{- $currentNode.Scratch.Set "relearnNextPage" .node }}
+ {{- end}}
+ {{- end }}
+
+ {{- $currentNode.Scratch.Set "relearnSubPages" .node.Pages }}
+ {{- if .node.IsHome}}
+ {{- $currentNode.Scratch.Set "relearnSubPages" .node.Sections }}
+ {{- else if .node.Sections}}
+ {{- $currentNode.Scratch.Set "relearnSubPages" (.node.Pages | union .node.Sections) }}
+ {{- end}}
+ {{- $pages := ($currentNode.Scratch.Get "relearnSubPages") }}
+
+ {{- if eq .Site.Params.ordersectionsby "title"}}
+ {{- range $pages.ByTitle }}
+ {{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hidden" $hidden_from_current }}
+ {{- end}}
+ {{- else}}
+ {{- range $pages.ByWeight }}
+ {{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hidden" $hidden_from_current }}
+ {{- end}}
+ {{- end }}
+ {{- end }}
{{ partial "menu.html" . }}