From 7eff38478b64cb67de9599f4239705a3afbb183a Mon Sep 17 00:00:00 2001 From: Ken D'Ambrosio Date: Tue, 16 Jun 2026 19:18:45 +0000 Subject: Split album count into separate photo and video counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app.rb | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'app.rb') diff --git a/app.rb b/app.rb index 64599c3..9cef024 100644 --- a/app.rb +++ b/app.rb @@ -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) -- cgit v1.2.3