From fa01f4ab56541a5acc954f04cc48c67ffa2772ee Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sat, 25 Jun 2022 12:20:57 +1000 Subject: [PATCH] fix: avoid error if unset --- assets/js/index.js | 2 +- layouts/partials/footer/script-footer.html | 13 ++++++++----- layouts/partials/header/header.html | 9 ++++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index dbaaa28..2f47890 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -95,7 +95,7 @@ Source: // https://discourse.gohugo.io/t/range-length-or-last-element/3803/2 {{ $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") }} {{- else }} {{- $list = (where .Site.Pages "Type" "in" .Site.Params.options.searchSectionsIndex) }} diff --git a/layouts/partials/footer/script-footer.html b/layouts/partials/footer/script-footer.html index 8cfe03e..769494a 100644 --- a/layouts/partials/footer/script-footer.html +++ b/layouts/partials/footer/script-footer.html @@ -34,13 +34,16 @@ {{ $slice = $slice | append $instantPage -}} {{ end -}} -{{ if .Site.Params.options.flexSearch -}} +{{ $showFlexSearch := .Site.Params.options.flexSearch }} + +{{ if $showFlexSearch -}} {{ $flexSearch := resources.Get "js/vendor/flexsearch/dist/flexsearch.bundle.js" -}} {{ $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 -}} -{{ $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 -}} {{ $darkMode := resources.Get "js/darkmode.js" -}} {{ $darkMode := $darkMode | js.Build -}} @@ -79,7 +82,7 @@ {{ with .Params.mermaid -}} {{ end -}} - {{ if $includeFlexSearch -}} + {{ if $showFlexSearch -}} {{ end -}} {{ else -}} @@ -104,7 +107,7 @@ {{ with .Params.mermaid -}} {{ end -}} - {{ if $includeFlexSearch -}} + {{ if $showFlexSearch -}} {{ end -}} {{ end -}} diff --git a/layouts/partials/header/header.html b/layouts/partials/header/header.html index 5dfae5b..8b4e4ca 100644 --- a/layouts/partials/header/header.html +++ b/layouts/partials/header/header.html @@ -77,7 +77,14 @@ {{ end -}} - {{ 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 -}}