Skip to content

Commit 554e3f8

Browse files
committed
Add a 'more' button to hide less popular tags
1 parent c8efdb1 commit 554e3f8

1 file changed

Lines changed: 49 additions & 9 deletions

File tree

_includes/filter_widget.html

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,45 @@
3434
</div>
3535

3636
<div class="filter-tag-row">
37-
<span class="filter-label">{{ include.label }}:</span>
38-
<button class="filter-btn active" onclick="applyTagFilter('all')">
39-
All <span class="count-pill">{{ include.items.size }}</span>
37+
<span class="filter-label">{{ include.label }}:</span>
38+
39+
{% comment %} Set your threshold here: tags with count < threshold are hidden {% endcomment %}
40+
{% assign threshold = 2 %}
41+
{% assign has_extra = false %}
42+
43+
<button class="filter-btn" onclick="applyTagFilter('all')">
44+
All <span class="count-pill">{{ include.items.size }}</span>
45+
</button>
46+
47+
{% for entry in sorted_tag_counts %}
48+
{% assign parts = entry | split: "|" %}
49+
{% assign tag = parts[1] %}
50+
{% assign count = parts[0] | plus: 0 %}
51+
52+
{% if tag != "" %}
53+
{% if count >= threshold %}
54+
<button class="filter-btn" onclick="applyTagFilter('{{ tag }}')">
55+
{{ tag }} <span class="count-pill">{{ count }}</span>
56+
</button>
57+
{% else %}
58+
{% if has_extra == false %}
59+
<span id="extra-tag-container" class="is-hidden" style="display: contents;">
60+
{% assign has_extra = true %}
61+
{% endif %}
62+
<button class="filter-btn" onclick="applyTagFilter('{{ tag }}')">
63+
{{ tag }} <span class="count-pill">{{ count }}</span>
64+
</button>
65+
{% endif %}
66+
{% endif %}
67+
{% endfor %}
68+
69+
{% if has_extra %}
70+
</span> <button id="toggle-more-btn" class="filter-btn" onclick="toggleExtraTags()" style="border-style: dashed; opacity: 0.7;">
71+
+ More
4072
</button>
41-
{% for entry in sorted_tag_counts %}
42-
{% assign parts = entry | split: "|" %}{% assign tag = parts[1] %}{% assign count = parts[0] | plus: 0 %}
43-
<button class="filter-btn" onclick="applyTagFilter('{{ tag }}')">
44-
{{ tag }} <span class="count-pill">{{ count }}</span>
45-
</button>
46-
{% endfor %}
73+
{% endif %}
4774
</div>
75+
4876
<div id="no-results" class="no-results-message is-hidden">
4977
Please select a tag to view items.
5078
</div>
@@ -206,4 +234,16 @@
206234
document.getElementById('search-input').value = '';
207235
window.applyTagFilter('all');
208236
};
237+
238+
window.toggleExtraTags = function() {
239+
const container = document.getElementById('extra-tag-container');
240+
const btn = document.getElementById('toggle-more-btn');
241+
242+
if (container && btn) {
243+
const isHidden = container.classList.toggle('is-hidden');
244+
btn.innerText = isHidden ? "+ More" : "- Less";
245+
// Optional: add a class to style the button differently when open
246+
btn.classList.toggle('active-toggle', !isHidden);
247+
}
248+
};
209249
</script>

0 commit comments

Comments
 (0)