arrow-nav: fix broken links on (and below) hidden pages #61

complete rewrite of logic
This commit is contained in:
Sören Weber 2021-08-27 14:11:29 +02:00
parent 7800611d01
commit 2e364fdb2b
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
2 changed files with 43 additions and 30 deletions

View file

@ -9,22 +9,35 @@
<!-- Next prev page -->
{{ $currentNode := . }}
{{ template "menu-nextprev" dict "menu" .Site.Home "currentnode" $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 }}
{{ $hidden := or (.menu.Params.hidden) (eq .menu.Title "") }}
{{ $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 hasPrefix $currentNode.RelPermalink .menu.RelPermalink }}
{{ $currentNode.Scratch.Set "NextPageOK" "OK" }}
{{ $currentNode.Scratch.Set "prevPage" ($currentNode.Scratch.Get "prevPageTmp") }}
{{else}}
{{if eq ($currentNode.Scratch.Get "NextPageOK") "OK"}}
{{ $currentNode.Scratch.Set "NextPageOK" nil }}
{{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 "prevPageTmp" .menu }}
{{ $currentNode.Scratch.Set "pages" .menu.Pages }}
{{ if .menu.IsHome}}
@ -36,12 +49,11 @@
{{if eq .Site.Params.ordersectionsby "title"}}
{{ range $pages.ByTitle }}
{{ template "menu-nextprev" dict "menu" . "currentnode" $currentNode }}
{{ template "menu-nextprev" dict "menu" . "currentnode" $currentNode "hidden" $hidden }}
{{end}}
{{else}}
{{ range $pages.ByWeight }}
{{ template "menu-nextprev" dict "menu" . "currentnode" $currentNode }}
{{end}}
{{ template "menu-nextprev" dict "menu" . "currentnode" $currentNode "hidden" $hidden }}
{{end}}
{{ end }}
{{ end }}
@ -52,7 +64,7 @@
<a class="nav nav-prev" href="{{.RelPermalink}}" title="{{.Title}}"><i class="fa fa-chevron-left"></i></a>
{{end}}
{{with ($.Scratch.Get "nextPage")}}
<a class="nav nav-next" href="{{.RelPermalink}}" title="{{.Title}}" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
<a class="nav nav-next" href="{{.RelPermalink}}" title="{{.Title}}"><i class="fa fa-chevron-right"></i></a>
{{end}}
{{end}}
</div>

View file

@ -375,6 +375,7 @@ textarea:focus, input[type="email"]:focus, input[type="number"]:focus, input[typ
left: 0;
}
#body .nav.nav-next {
margin-right: 0px;
right: 0;
}
#chapter {