|
| 1 | +{%- if include.keys -%} |
| 2 | + {%- assign keys = include.keys -%} |
| 3 | +{%- endif -%} |
| 4 | + |
| 5 | +<div class="tags-grid-container"> |
| 6 | + <!-- Tags Grid --> |
| 7 | + <div class="tags-grid"> |
| 8 | + {% for tag in keys %} |
| 9 | + {% assign post_count = site.tags[tag] | size %} |
| 10 | + <div class="tag-item" onclick="showTagPosts('{{ tag | slugify }}')"> |
| 11 | + <span class="tag-name">{{ tag }}</span> |
| 12 | + <span class="tag-count">({{ post_count }})</span> |
| 13 | + </div> |
| 14 | + {% endfor %} |
| 15 | + </div> |
| 16 | + |
| 17 | + <!-- Tag Posts Section --> |
| 18 | + <div class="tag-posts-container"> |
| 19 | + {% for tag in keys %} |
| 20 | + {% assign tag_posts = site.tags[tag] %} |
| 21 | + {% assign post_count = tag_posts | size %} |
| 22 | + |
| 23 | + <div class="tag-posts-section" id="tag-{{ tag | slugify }}" style="display: none;"> |
| 24 | + <h2 class="tag-section-title"> |
| 25 | + {{ tag }} ({{ post_count }}) |
| 26 | + <span class="close-tag" onclick="closeTagPosts()">✕</span> |
| 27 | + </h2> |
| 28 | + <ul class="tag-posts-list"> |
| 29 | + {% for post in tag_posts %} |
| 30 | + <li>{% assign item = post %}{% include views/post-item.html %}</li> |
| 31 | + {% endfor %} |
| 32 | + </ul> |
| 33 | + </div> |
| 34 | + {% endfor %} |
| 35 | + </div> |
| 36 | +</div> |
| 37 | + |
| 38 | +<script> |
| 39 | +let currentOpenTag = null; |
| 40 | + |
| 41 | +function showTagPosts(tagSlug) { |
| 42 | + const tagSection = document.getElementById('tag-' + tagSlug); |
| 43 | + const container = document.querySelector('.tag-posts-container'); |
| 44 | + |
| 45 | + // Close previously open tag |
| 46 | + if (currentOpenTag && currentOpenTag !== tagSlug) { |
| 47 | + document.getElementById('tag-' + currentOpenTag).style.display = 'none'; |
| 48 | + } |
| 49 | + |
| 50 | + // Toggle current tag |
| 51 | + if (tagSection.style.display === 'none') { |
| 52 | + tagSection.style.display = 'block'; |
| 53 | + container.style.display = 'block'; |
| 54 | + currentOpenTag = tagSlug; |
| 55 | + |
| 56 | + // Scroll to the tag section |
| 57 | + tagSection.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); |
| 58 | + } else { |
| 59 | + tagSection.style.display = 'none'; |
| 60 | + if (!document.querySelector('.tag-posts-section[style*="display: block"]')) { |
| 61 | + container.style.display = 'none'; |
| 62 | + } |
| 63 | + currentOpenTag = null; |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +function closeTagPosts() { |
| 68 | + if (currentOpenTag) { |
| 69 | + document.getElementById('tag-' + currentOpenTag).style.display = 'none'; |
| 70 | + currentOpenTag = null; |
| 71 | + |
| 72 | + const container = document.querySelector('.tag-posts-container'); |
| 73 | + if (!document.querySelector('.tag-posts-section[style*="display: block"]')) { |
| 74 | + container.style.display = 'none'; |
| 75 | + } |
| 76 | + } |
| 77 | +} |
| 78 | +</script> |
0 commit comments