fix: avoid error if unset

This commit is contained in:
James Elliott 2022-06-25 12:20:57 +10:00
parent 00e4a7886e
commit fa01f4ab56
No known key found for this signature in database
GPG Key ID: 0F1C4A096E857E49
3 changed files with 17 additions and 7 deletions

View File

@ -95,7 +95,7 @@ Source:
// https://discourse.gohugo.io/t/range-length-or-last-element/3803/2 // https://discourse.gohugo.io/t/range-length-or-last-element/3803/2
{{ $list := slice }} {{ $list := slice }}
{{- if eq (len .Site.Params.options.searchSectionsIndex) 0 }} {{- if or (not (isset .Site.Params.options "searchsectionsindex")) (eq (len .Site.Params.options.searchSectionsIndex) 0) }}
{{- $list = (where .Site.Pages "Section" "docs") }} {{- $list = (where .Site.Pages "Section" "docs") }}
{{- else }} {{- else }}
{{- $list = (where .Site.Pages "Type" "in" .Site.Params.options.searchSectionsIndex) }} {{- $list = (where .Site.Pages "Type" "in" .Site.Params.options.searchSectionsIndex) }}

View File

@ -34,13 +34,16 @@
{{ $slice = $slice | append $instantPage -}} {{ $slice = $slice | append $instantPage -}}
{{ end -}} {{ end -}}
{{ if .Site.Params.options.flexSearch -}} {{ $showFlexSearch := .Site.Params.options.flexSearch }}
{{ if $showFlexSearch -}}
{{ $flexSearch := resources.Get "js/vendor/flexsearch/dist/flexsearch.bundle.js" -}} {{ $flexSearch := resources.Get "js/vendor/flexsearch/dist/flexsearch.bundle.js" -}}
{{ $slice = $slice | append $flexSearch -}} {{ $slice = $slice | append $flexSearch -}}
{{ if (isset .Site.Params.options "searchsectionsshow") -}}
{{ $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) -}}
{{ end -}}
{{ end -}} {{ end -}}
{{ $includeFlexSearch := and .Site.Params.options.flexSearch (or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section)) }}
{{ if .Site.Params.options.darkMode -}} {{ if .Site.Params.options.darkMode -}}
{{ $darkMode := resources.Get "js/darkmode.js" -}} {{ $darkMode := resources.Get "js/darkmode.js" -}}
{{ $darkMode := $darkMode | js.Build -}} {{ $darkMode := $darkMode | js.Build -}}
@ -79,7 +82,7 @@
{{ with .Params.mermaid -}} {{ with .Params.mermaid -}}
<script src="{{ $mermaid.RelPermalink }}" defer></script> <script src="{{ $mermaid.RelPermalink }}" defer></script>
{{ end -}} {{ end -}}
{{ if $includeFlexSearch -}} {{ if $showFlexSearch -}}
<script src="{{ $index.RelPermalink }}" defer></script> <script src="{{ $index.RelPermalink }}" defer></script>
{{ end -}} {{ end -}}
{{ else -}} {{ else -}}
@ -104,7 +107,7 @@
{{ with .Params.mermaid -}} {{ with .Params.mermaid -}}
<script src="{{ $mermaid.RelPermalink }}" integrity="{{ $mermaid.Data.Integrity }}" crossorigin="anonymous" defer></script> <script src="{{ $mermaid.RelPermalink }}" integrity="{{ $mermaid.Data.Integrity }}" crossorigin="anonymous" defer></script>
{{ end -}} {{ end -}}
{{ if $includeFlexSearch -}} {{ if $showFlexSearch -}}
<script src="{{ $index.Permalink }}" integrity="{{ $index.Data.Integrity }}" crossorigin="anonymous" defer></script> <script src="{{ $index.Permalink }}" integrity="{{ $index.Data.Integrity }}" crossorigin="anonymous" defer></script>
{{ end -}} {{ end -}}
{{ end -}} {{ end -}}

View File

@ -77,7 +77,14 @@
{{ end -}} {{ end -}}
</ul> </ul>
{{ if and .Site.Params.options.flexSearch (or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section)) -}} {{- $showFlexSearch := .Site.Params.options.flexSearch }}
{{- if $showFlexSearch }}
{{- if (isset .Site.Params.options "searchsectionsshow") }}
{{- $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) }}
{{- end }}
{{- end }}
{{ if $showFlexSearch -}}
<hr class="text-black-50 my-4 d-lg-none"> <hr class="text-black-50 my-4 d-lg-none">
<form class="doks-search position-relative flex-grow-1 ms-lg-auto me-lg-2"> <form class="doks-search position-relative flex-grow-1 ms-lg-auto me-lg-2">
<input id="search" class="form-control is-search" type="search" placeholder="Search docs..." aria-label="Search docs..." autocomplete="off"> <input id="search" class="form-control is-search" type="search" placeholder="Search docs..." aria-label="Search docs..." autocomplete="off">