search: disable search in hidden branches #76

1-1-1-1 was previously displayed in the search results
This commit is contained in:
Sören Weber 2021-09-03 22:20:53 +02:00
parent 97336b2339
commit 06486bdc3c
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
3 changed files with 56 additions and 54 deletions

View file

@ -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 }}

View file

@ -7,63 +7,12 @@
<div id="navigation">
<!-- Next prev page -->
{{ $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")}}
<a class="nav nav-prev" href="{{.RelPermalink}}" title="{{.Title}}"><i class="fa fa-chevron-left"></i></a>
{{end}}
{{with ($.Scratch.Get "nextPage")}}
{{with ($.Scratch.Get "relearnNextPage")}}
<a class="nav nav-next" href="{{.RelPermalink}}" title="{{.Title}}"><i class="fa fa-chevron-right"></i></a>
{{end}}
{{end}}

View file

@ -38,6 +38,59 @@
</style>
{{ partial "custom-header.html" . }}
</head>
{{- $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 }}
<body class="" data-url="{{ .RelPermalink }}">
{{ partial "menu.html" . }}
<section id="body">