Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(search): allow complete section customization #799

Merged
merged 5 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down
2 changes: 2 additions & 0 deletions config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ lastMod = false
clipBoard = true
instantPage = true
flexSearch = true
searchSectionsShow = []
searchSectionsIndex = []
darkMode = true
bootStrapJs = true
breadCrumb = false
Expand Down
13 changes: 9 additions & 4 deletions layouts/partials/footer/script-footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down Expand Up @@ -77,7 +82,7 @@
{{ with .Params.mermaid -}}
<script src="{{ $mermaid.RelPermalink }}" defer></script>
{{ end -}}
{{ if .Site.Params.options.flexSearch -}}
{{ if $showFlexSearch -}}
<script src="{{ $index.RelPermalink }}" defer></script>
{{ end -}}
{{ else -}}
Expand All @@ -102,7 +107,7 @@
{{ with .Params.mermaid -}}
<script src="{{ $mermaid.RelPermalink }}" integrity="{{ $mermaid.Data.Integrity }}" crossorigin="anonymous" defer></script>
{{ end -}}
{{ if .Site.Params.options.flexSearch -}}
{{ if $showFlexSearch -}}
<script src="{{ $index.Permalink }}" integrity="{{ $index.Data.Integrity }}" crossorigin="anonymous" defer></script>
{{ end -}}
{{ end -}}
{{ end -}}
9 changes: 8 additions & 1 deletion layouts/partials/header/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ <h2 class="h5 offcanvas-title ps-2" id="offcanvasDoksLabel"><a class="text-dark"
{{ end -}}
</ul>

{{ 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 -}}
<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">
<input id="search" class="form-control is-search" type="search" placeholder="Search docs..." aria-label="Search docs..." autocomplete="off">
Expand Down