diff --git a/assets/js/index.js b/assets/js/index.js index f3d8da1..15e09bb 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -94,7 +94,20 @@ Source: // https://discourse.gohugo.io/t/range-length-or-last-element/3803/2 - {{ $list := (where .Site.Pages "Section" "docs") -}} + {{ $list := slice }} + {{- if and (isset .Site.Params.options "searchsectionsindex") (not (eq (len .Site.Params.options.searchSectionsIndex) 0)) }} + {{- if eq .Site.Params.options.searchSectionsIndex "ALL" }} + {{- $list = .Site.Pages }} + {{- else }} + {{- $list = (where .Site.Pages "Type" "in" .Site.Params.options.searchSectionsIndex) }} + {{- if (in .Site.Params.options.searchSectionsIndex "HomePage") }} + {{ $list = $list | append .Site.Home }} + {{- end }} + {{- end }} + {{- else }} + {{- $list = (where .Site.Pages "Section" "docs") }} + {{- end }} + {{ $len := (len $list) -}} {{ range $index, $element := $list -}} diff --git a/config/_default/params.toml b/config/_default/params.toml index af0f6b3..e6821b6 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -83,6 +83,8 @@ lastMod = false clipBoard = true instantPage = true flexSearch = true + searchSectionsShow = [] + searchSectionsIndex = [] darkMode = true bootStrapJs = true breadCrumb = false diff --git a/layouts/partials/footer/script-footer.html b/layouts/partials/footer/script-footer.html index cc77b65..8799730 100644 --- a/layouts/partials/footer/script-footer.html +++ b/layouts/partials/footer/script-footer.html @@ -34,9 +34,14 @@ {{ $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 and (isset .Site.Params.options "searchsectionsshow") (not (eq .Site.Params.options.searchSectionsShow "ALL")) -}} + {{ $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) (and .IsHome (in .Site.Params.options.searchSectionsShow "HomePage")) -}} + {{ end -}} {{ end -}} {{ if .Site.Params.options.darkMode -}} @@ -83,7 +88,7 @@ {{ with .Params.mermaid -}} {{ end -}} - {{ if .Site.Params.options.flexSearch -}} + {{ if $showFlexSearch -}} {{ end -}} {{ else -}} @@ -108,7 +113,7 @@ {{ with .Params.mermaid -}} {{ end -}} - {{ if .Site.Params.options.flexSearch -}} + {{ if $showFlexSearch -}} {{ end -}} -{{ end -}} \ No newline at end of file +{{ end -}} diff --git a/layouts/partials/header/header.html b/layouts/partials/header/header.html index 65744ec..d6e0f6e 100644 --- a/layouts/partials/header/header.html +++ b/layouts/partials/header/header.html @@ -77,7 +77,14 @@ {{ end -}} - {{ if .Site.Params.options.flexSearch -}} + {{- $showFlexSearch := .Site.Params.options.flexSearch }} + {{- if $showFlexSearch }} + {{- if and (isset .Site.Params.options "searchsectionsshow") (not (eq .Site.Params.options.searchSectionsShow "ALL")) }} + {{- $showFlexSearch = or (eq (len .Site.Params.options.searchSectionsShow) 0) (in .Site.Params.options.searchSectionsShow .Section) (and .IsHome (in .Site.Params.options.searchSectionsShow "HomePage")) }} + {{- end }} + {{- end }} + + {{ if $showFlexSearch -}}