summaryrefslogtreecommitdiffstats
path: root/app.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app.rb')
-rw-r--r--app.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/app.rb b/app.rb
index be88e37..f5c52d4 100644
--- a/app.rb
+++ b/app.rb
@@ -113,19 +113,21 @@ helpers do
sub_data = load_album(sub_dir)
next if sub_data['visible'] == false && !admin?
{
- name: name,
- title: sub_data['title'] || name,
- cover: album_cover(sub_dir, sub_data),
- dynamic: sub_data['cover_dynamic'] == true,
+ name: name,
+ title: sub_data['title'] || name,
+ cover: album_cover(sub_dir, sub_data),
}
end
data['sort_reverse'] ? albums.reverse : albums
end
def album_cover(dir, data)
- if (cover = data['cover'])
- return cover if File.exist?(File.join(dir, cover))
+ 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('.')) }
end
@@ -323,8 +325,7 @@ def save_edits(rel, dir)
data = load_album(dir)
data['title'] = blank_to_nil(params['album_title'])
data['description'] = blank_to_nil(params['album_description'])
- data['cover'] = blank_to_nil(params['album_cover'])
- data['cover_dynamic'] = params['album_cover_dynamic'] == '1'
+ data['cover'] = blank_to_nil(params['album_cover'])
data['sort_reverse'] = params['album_sort_reverse'] == '1'
data['visible'] = params['album_visible'] == '1'