Skip to content

Commit d1d1c8a

Browse files
committed
fix(portfolio): respect per-filter count while keeping filters populated
1 parent 1096b74 commit d1d1c8a

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

modules/blox/blox/portfolio/block.html

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,43 @@
8181
{{ $total_count := len $query }}
8282
{{ $has_multiple_filters := gt (len $buttons) 1 }}
8383

84-
{{/* Limit (only when not using multiple filters, since Alpine filters client-side) */}}
84+
{{/* Limit */}}
8585
{{ $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 }}
88121
{{ end }}
89122
{{ $displayed_count := len $query }}
90123

0 commit comments

Comments
 (0)