diff options
| author | Ken D'Ambrosio <ken@jots.org> | 2026-06-16 19:18:45 +0000 |
|---|---|---|
| committer | Ken D'Ambrosio <ken@jots.org> | 2026-06-16 19:18:45 +0000 |
| commit | 7eff38478b64cb67de9599f4239705a3afbb183a (patch) | |
| tree | 1f30b958e182bd9946aa75208e6ba139b678ef5a | |
| parent | 612afca9f70e65de8b6511b7b0c008e563313a39 (diff) | |
Split album count into separate photo and video counts
Replace media_count helper with media_counts returning {photos, videos}.
Album overview shows photo count as before, plus a coloured ▶ N badge
only when an album (or its sub-albums) contains videos.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rw-r--r-- | app.rb | 44 | ||||
| -rw-r--r-- | public/css/style.css | 1 | ||||
| -rw-r--r-- | views/album.erb | 2 |
3 files changed, 29 insertions, 18 deletions
@@ -146,30 +146,40 @@ helpers do sub_dir = File.join(dir, name) sub_data = load_album(sub_dir) next if sub_data['visible'] == false && !admin? + counts = media_counts(sub_dir, sub_data) { - name: name, - title: sub_data['title'] || name, - cover: album_cover(sub_dir, sub_data), - count: media_count(sub_dir, sub_data), + name: name, + title: sub_data['title'] || name, + cover: album_cover(sub_dir, sub_data), + count: counts[:photos] + counts[:videos], + photo_count: counts[:photos], + video_count: counts[:videos], } end data['sort_reverse'] ? albums.reverse : albums end - def media_count(dir, data) + def media_counts(dir, data) files = data['files'] || {} - direct = Dir.children(dir) - .count { |n| MEDIA_EXTS.include?(File.extname(n).downcase.delete_prefix('.')) && - (admin? || (files[n] || {}).fetch('visible', true)) } - sub_total = Dir.children(dir) - .select { |n| !n.start_with?('.') && File.directory?(File.join(dir, n)) } - .sum do |n| - sub_dir = File.join(dir, n) - sub_data = load_album(sub_dir) - next 0 if sub_data['visible'] == false && !admin? - media_count(sub_dir, sub_data) - end - direct + sub_total + photos = 0; videos = 0 + Dir.children(dir).each do |n| + ext = File.extname(n).downcase.delete_prefix('.') + next unless MEDIA_EXTS.include?(ext) + next unless admin? || (files[n] || {}).fetch('visible', true) + if VIDEO_EXTS.include?(ext) + videos += 1 + elsif IMAGE_EXTS.include?(ext) || AUDIO_EXTS.include?(ext) + photos += 1 + end + end + Dir.children(dir).select { |n| !n.start_with?('.') && File.directory?(File.join(dir, n)) }.each do |n| + sub_dir = File.join(dir, n) + sub_data = load_album(sub_dir) + next if sub_data['visible'] == false && !admin? + sub = media_counts(sub_dir, sub_data) + photos += sub[:photos]; videos += sub[:videos] + end + { photos: photos, videos: videos } end def format_duration(secs) diff --git a/public/css/style.css b/public/css/style.css index b907f0e..09de0b3 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -152,6 +152,7 @@ main { max-width: 1400px; margin: 0 auto; padding: 24px; } .album-label { padding: 6px 8px; font-size: .88rem; font-weight: 500; color: var(--text); display: flex; align-items: baseline; justify-content: space-between; gap: 6px; } .album-count { font-size: .75rem; font-weight: 400; color: var(--text-dim); white-space: nowrap; } +.album-video-count { color: var(--accent, #c57); } .duration-badge { position: absolute; bottom: 6px; left: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: .72rem; padding: 2px 5px; border-radius: 3px; pointer-events: none; } #album-search { display: block; width: 100%; max-width: 280px; margin-bottom: 14px; padding: 5px 10px; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: .9rem; } .card-meta { padding: 6px 8px; } diff --git a/views/album.erb b/views/album.erb index d13ced9..4f261c4 100644 --- a/views/album.erb +++ b/views/album.erb @@ -41,7 +41,7 @@ <div class="thumb-placeholder">📁</div> <% end %> </div> - <div class="album-label"><%= a[:title] %><% if a[:count] && a[:count] > 0 %><span class="album-count"><%= a[:count] %></span><% end %></div> + <div class="album-label"><%= a[:title] %><% if (a[:photo_count] || a[:count]).to_i > 0 %><span class="album-count"><%= a[:photo_count] || a[:count] %></span><% end %><% if a[:video_count].to_i > 0 %><span class="album-count album-video-count">▶ <%= a[:video_count] %></span><% end %></div> </a> <% end %> </div> |
