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 /app.rb | |
| 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>
Diffstat (limited to 'app.rb')
| -rw-r--r-- | app.rb | 44 |
1 files changed, 27 insertions, 17 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) |
