Skip to content

Commit

Permalink
feat: add the filter_years parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed May 13, 2023
1 parent bcb43a0 commit 34d9f83
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions assets/search/js/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export default class Form {
})

this.years = this.ele.querySelector('.search-years') as HTMLElement
this.years.addEventListener('change', () => {
this.years?.addEventListener('change', () => {
this.submit()
})

Expand Down Expand Up @@ -292,7 +292,7 @@ export default class Form {

getYears(): Array<string> {
const v: Array<string> = []
this.years.querySelectorAll('.search-dropdown-item.active').forEach((item) => {
this.years?.querySelectorAll('.search-dropdown-item.active').forEach((item) => {
v.push(item.getAttribute('data-value') ?? '')
})
return v
Expand Down
1 change: 1 addition & 0 deletions exampleSite/config/_default/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ LanguageDirection = 'rtl'
# min_match_char_length = 3
# lazy_loading = false
# filter_taxonomies = false
# filter_years = false
1 change: 1 addition & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ index_content = false
expand_results_meta = false
lazy_loading = true
filter_taxonomies = true
filter_years = true
16 changes: 9 additions & 7 deletions layouts/partials/search/assets/js-resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
{{- end }}
{{/* years. */}}
{{- $years := slice }}
{{- $indexAllPages := default true .Site.Params.search.index_all_pages }}
{{- $pages := cond $indexAllPages .Site.AllPages .Site.AllRegularPages }}
{{- $pages = where $pages "Params.noindex" "ne" true }}
{{- with $pages.GroupByDate "2006" }}
{{- range . }}
{{- $years = $years | append .Key }}
{{- if default true site.Params.search.filter_years }}
{{- $indexAllPages := default true .Site.Params.search.index_all_pages }}
{{- $pages := cond $indexAllPages .Site.AllPages .Site.AllRegularPages }}
{{- $pages = where $pages "Params.noindex" "ne" true }}
{{- with $pages.GroupByDate "2006" }}
{{- range . }}
{{- $years = $years | append .Key }}
{{- end }}
{{- $years = sort $years }}
{{- end }}
{{- $years = sort $years }}
{{- end }}
{{/* taxonomies. */}}
{{- $taxonomies := newScratch }}
Expand Down

0 comments on commit 34d9f83

Please sign in to comment.