|
81 | 81 | {{ $total_count := len $query }} |
82 | 82 | {{ $has_multiple_filters := gt (len $buttons) 1 }} |
83 | 83 |
|
84 | | -{{/* Limit (only when not using multiple filters, since Alpine filters client-side) */}} |
| 84 | +{{/* Limit */}} |
85 | 85 | {{ $count := partial "functions/coerce_int" (dict "value" (index $content "count") "default" 6 "min" 0) }} |
86 | | -{{ if and (gt $count 0) (not $has_multiple_filters) }} |
87 | | - {{ $query = first $count $query }} |
| 86 | +{{ if gt $count 0 }} |
| 87 | + {{ if $has_multiple_filters }} |
| 88 | + {{/* Build a union of up to $count items per button tag to keep filters populated while respecting count */}} |
| 89 | + {{ $collected := slice }} |
| 90 | + {{ $seen := dict }} |
| 91 | + {{ range $buttons }} |
| 92 | + {{ if reflect.IsMap . }} |
| 93 | + {{ $tag := "*" }} |
| 94 | + {{ with index . "tag" }}{{ $tag = strings.TrimSpace (printf "%v" .) }}{{ end }} |
| 95 | + {{ $tag_lower := lower $tag }} |
| 96 | + {{ $items := slice }} |
| 97 | + {{ if eq $tag_lower "*" }} |
| 98 | + {{ $items = first $count $query }} |
| 99 | + {{ else }} |
| 100 | + {{ $items = first $count (where $query "Params.tags" "intersect" (slice $tag_lower)) }} |
| 101 | + {{ if eq (len $items) 0 }} |
| 102 | + {{/* fallback to case-sensitive tags if lowercase intersect yields none */}} |
| 103 | + {{ $items = first $count (where $query "Params.tags" "intersect" (slice $tag)) }} |
| 104 | + {{ end }} |
| 105 | + {{ end }} |
| 106 | + {{ range $items }} |
| 107 | + {{ $key := .RelPermalink }} |
| 108 | + {{ if not (isset $seen $key) }} |
| 109 | + {{ $collected = $collected | append . }} |
| 110 | + {{ $seen = merge $seen (dict $key true) }} |
| 111 | + {{ end }} |
| 112 | + {{ end }} |
| 113 | + {{ end }} |
| 114 | + {{ end }} |
| 115 | + {{ if gt (len $collected) 0 }} |
| 116 | + {{ $query = $collected }} |
| 117 | + {{ end }} |
| 118 | + {{ else }} |
| 119 | + {{ $query = first $count $query }} |
| 120 | + {{ end }} |
88 | 121 | {{ end }} |
89 | 122 | {{ $displayed_count := len $query }} |
90 | 123 |
|
|
0 commit comments