summaryrefslogtreecommitdiffstats
path: root/app.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app.rb')
-rw-r--r--app.rb44
1 files changed, 27 insertions, 17 deletions
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)