From ab2ab15a397f2c7bd19dc002d6a2185269cc8a39 Mon Sep 17 00:00:00 2001 From: Ken D'Ambrosio Date: Sat, 9 May 2026 09:08:38 +0000 Subject: Search subdirs recursively for album cover candidates Albums with no top-level photos (only sub-albums) now find a cover by walking the full directory tree. Extracted cover_candidates() does a recursive glob and returns paths relative to the album dir so the existing thumb URL construction works unchanged. Co-Authored-By: Claude Sonnet 4.6 --- app.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app.rb b/app.rb index f5c52d4..f58a99d 100644 --- a/app.rb +++ b/app.rb @@ -123,12 +123,17 @@ helpers do def album_cover(dir, data) cover = data['cover'] - if cover == '__random__' - candidates = Dir.children(dir).select { |n| (IMAGE_EXTS + VIDEO_EXTS).include?(File.extname(n).downcase.delete_prefix('.')) } - return candidates.sample - end - return cover if cover && File.exist?(File.join(dir, cover)) - Dir.children(dir).sort.find { |n| (IMAGE_EXTS + VIDEO_EXTS).include?(File.extname(n).downcase.delete_prefix('.')) } + return cover if cover && cover != '__random__' && File.exist?(File.join(dir, cover)) + candidates = cover_candidates(dir) + cover == '__random__' ? candidates.sample : candidates.first + end + + def cover_candidates(dir) + exts = (IMAGE_EXTS + VIDEO_EXTS).to_set + Dir.glob(File.join(dir, '**', '*')) + .select { |f| File.file?(f) && exts.include?(File.extname(f).downcase.delete_prefix('.')) } + .sort + .map { |f| f.delete_prefix("#{dir}/") } end # Returns the absolute path or halts with 404. -- cgit v1.2.3