mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-30 03:03:09 +00:00
arrow-nav: fix broken links on (and below) hidden pages #61
complete rewrite of logic
This commit is contained in:
parent
7800611d01
commit
2e364fdb2b
2 changed files with 43 additions and 30 deletions
|
@ -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 "") }}
|
||||
{{ $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 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 }}
|
||||
{{ end }}
|
||||
|
||||
{{ $currentNode.Scratch.Set "pages" .menu.Pages }}
|
||||
{{ if .menu.IsHome}}
|
||||
|
@ -36,23 +49,22 @@
|
|||
|
||||
{{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 }}
|
||||
{{ template "menu-nextprev" dict "menu" . "currentnode" $currentNode "hidden" $hidden }}
|
||||
{{end}}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{$showPrevNext := (and (not .Params.disableNextPrev) (not .Site.Params.disableNextPrev))}}
|
||||
{{if $showPrevNext}}
|
||||
{{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}}
|
||||
{{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>
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue