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,50 +9,62 @@
<!-- Next prev page --> <!-- Next prev page -->
{{ $currentNode := . }} {{ $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" }} {{ define "menu-nextprev" }}
{{$currentNode := .currentnode }} {{ $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 not $hidden }}
{{if hasPrefix $currentNode.RelPermalink .menu.RelPermalink }} {{if and $isPreSelf (or $isOther $isAncestor ) }}
{{ $currentNode.Scratch.Set "NextPageOK" "OK" }} {{ $currentNode.Scratch.Set "prevPage" .menu }}
{{ $currentNode.Scratch.Set "prevPage" ($currentNode.Scratch.Get "prevPageTmp") }} {{else if and $isPostSelf (or $isOther $isDescendant) (eq ($currentNode.Scratch.Get "nextPage") nil) }}
{{else}} {{ $currentNode.Scratch.Set "nextPage" .menu }}
{{if eq ($currentNode.Scratch.Get "NextPageOK") "OK"}}
{{ $currentNode.Scratch.Set "NextPageOK" nil }}
{{ $currentNode.Scratch.Set "nextPage" .menu }}
{{end}}
{{end}} {{end}}
{{ $currentNode.Scratch.Set "prevPageTmp" .menu }} {{ end }}
{{ $currentNode.Scratch.Set "pages" .menu.Pages }} {{ $currentNode.Scratch.Set "pages" .menu.Pages }}
{{ if .menu.IsHome}} {{ if .menu.IsHome}}
{{ $currentNode.Scratch.Set "pages" .menu.Sections }} {{ $currentNode.Scratch.Set "pages" .menu.Sections }}
{{ else if .menu.Sections}} {{ else if .menu.Sections}}
{{ $currentNode.Scratch.Set "pages" (.menu.Pages | union .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}}
{{ $pages := ($currentNode.Scratch.Get "pages") }}
{{if eq .Site.Params.ordersectionsby "title"}}
{{ range $pages.ByTitle }}
{{ template "menu-nextprev" dict "menu" . "currentnode" $currentNode }}
{{end}}
{{else}}
{{ range $pages.ByWeight }}
{{ template "menu-nextprev" dict "menu" . "currentnode" $currentNode }}
{{end}}
{{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{$showPrevNext := (and (not .Params.disableNextPrev) (not .Site.Params.disableNextPrev))}} {{$showPrevNext := (and (not .Params.disableNextPrev) (not .Site.Params.disableNextPrev))}}
{{if $showPrevNext}} {{if $showPrevNext}}
{{with ($.Scratch.Get "prevPage")}} {{with ($.Scratch.Get "prevPage")}}
<a class="nav nav-prev" href="{{.RelPermalink}}" title="{{.Title}}"> <i class="fa fa-chevron-left"></i></a> <a class="nav nav-prev" href="{{.RelPermalink}}" title="{{.Title}}"><i class="fa fa-chevron-left"></i></a>
{{end}} {{end}}
{{with ($.Scratch.Get "nextPage")}} {{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}}
{{end}} {{end}}
</div> </div>

View file

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