diff options
| author | Ken D'Ambrosio <ken@jots.org> | 2026-05-09 09:08:38 +0000 |
|---|---|---|
| committer | Ken D'Ambrosio <ken@jots.org> | 2026-05-09 09:08:38 +0000 |
| commit | ab2ab15a397f2c7bd19dc002d6a2185269cc8a39 (patch) | |
| tree | f57254a25ac347e94ef1a95e0df6f005964f0841 /app.rb | |
| parent | f607462f31d52d6287ef056c26ff518160805ef9 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'app.rb')
| -rw-r--r-- | app.rb | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -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. |
