mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-26 19:15:16 +02:00
feat: add filtering and sorting options to Portfolio widget
Add content.filters.folders and content.filters.tags to filter on folders or tags. Add content.sort_by (str) and content.sort_ascending (bool) options. Close #2666
This commit is contained in:
parent
94fc0df0b8
commit
06921addf2
1 changed files with 19 additions and 6 deletions
|
@ -3,7 +3,6 @@
|
|||
{{/* Initialise */}}
|
||||
{{ $ := .root }}
|
||||
{{ $st := .page }}
|
||||
{{ $items_type := $st.Params.content.page_type | default "project" }}
|
||||
{{ $columns := $st.Params.design.columns | default "2" }}
|
||||
{{ $view := $st.Params.design.view | default "masonry" }}
|
||||
|
||||
|
@ -47,12 +46,26 @@
|
|||
|
||||
<div class="{{ if or $st.Params.content.filter_button (in (slice "masonry" 3) $view) }}isotope projects-container{{end}} {{if in (slice "masonry" 3) $view}}js-layout-masonry{{else}}row js-layout-row{{end}} {{ if eq $view "showcase" }}project-showcase{{end}}">
|
||||
|
||||
{{ $query := "" }}
|
||||
{{ if $st.Params.content.filters.tags }}
|
||||
{{ $query = where site.Pages "Params.tags" "intersect" $st.Params.content.filters.tags }}
|
||||
{{ else }}
|
||||
{{ $query = where site.RegularPages "Type" $items_type }}
|
||||
{{/* Query */}}
|
||||
{{ $query := site.RegularPages }}
|
||||
|
||||
{{/* Filters */}}
|
||||
{{ with $st.Params.content.page_type }}
|
||||
{{/* Legacy filter, superseded by `filters.folders` */}}
|
||||
{{ $query = where $query "Type" . }}
|
||||
{{ end }}
|
||||
{{ with $st.Params.content.filters.folders }}
|
||||
{{ $query = where $query "Section" "in" . }}
|
||||
{{ end }}
|
||||
{{ with $st.Params.content.filters.tags }}
|
||||
{{ $query = where $query "Params.tags" "intersect" . }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Sort */}}
|
||||
{{ $sort_by := $st.Params.content.sort_by | default "Date" }}
|
||||
{{ $sort_ascending := $st.Params.content.sort_ascending | default (eq $st.Params.content.order "asc") | default false }}
|
||||
{{ $sort_order := cond $sort_ascending "asc" "desc" }}
|
||||
{{ $query = sort $query $sort_by $sort_order }}
|
||||
|
||||
{{ range $index, $item := $query }}
|
||||
{{ $js_tag_classes := delimit (apply (apply $item.Params.tags "replace" "." " " "-") "printf" "js-id-%s" ".") " " }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue