summaryrefslogtreecommitdiffstats
path: root/app.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app.rb')
-rw-r--r--app.rb29
1 files changed, 18 insertions, 11 deletions
diff --git a/app.rb b/app.rb
index a609f75..dca8825 100644
--- a/app.rb
+++ b/app.rb
@@ -170,17 +170,9 @@ helpers do
end
def og_image_url
- first_img = Array(@entries).find { |e| e[:type] == :image }
- if first_img
- fr = @rel.to_s.empty? ? first_img[:name] : "#{@rel}/#{first_img[:name]}"
- return "#{request.base_url}/thumb/#{fr}"
- end
- first_album = Array(@albums).first
- if first_album&.dig(:cover)
- cr = @rel.to_s.empty? ? "#{first_album[:name]}/#{first_album[:cover]}" : "#{@rel}/#{first_album[:name]}/#{first_album[:cover]}"
- return "#{request.base_url}/thumb/#{cr}"
- end
- nil
+ return nil unless @og_image_rel
+ type = @og_use_media ? 'media' : 'thumb'
+ "#{request.base_url}/#{type}/#{@og_image_rel}"
end
end
@@ -214,6 +206,21 @@ def browse_album(rel)
@albums = child_albums(dir, data)
@entries = album_files(dir, data)
@crumbs = breadcrumbs(rel)
+
+ if params[:photo] && !params[:photo].empty?
+ photo_name = File.basename(params[:photo])
+ @og_image_rel = rel.empty? ? photo_name : "#{rel}/#{photo_name}"
+ @og_use_media = true
+ else
+ first_img = @entries.find { |e| %i[image video].include?(e[:type]) }
+ @og_image_rel = if first_img
+ rel.empty? ? first_img[:name] : "#{rel}/#{first_img[:name]}"
+ else
+ cover = cover_candidates(dir).first
+ cover ? (rel.empty? ? cover : "#{rel}/#{cover}") : nil
+ end
+ end
+
erb :album
end