switch post previews to use flexbox, add better styling for cropped thumbnails

This commit is contained in:
Albert Yi
2018-07-05 16:51:10 -07:00
parent ec44aa84fa
commit a610111658
11 changed files with 62 additions and 64 deletions

View File

@@ -21,15 +21,13 @@ class PostPresenter < Presenter
end
path = options[:path_prefix] || "/posts"
if Danbooru.config.enable_image_cropping && CurrentUser.id == 1 && options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
src = post.crop_file_url
imgClass = "cropped"
if Danbooru.config.enable_image_cropping && options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
cropped_src = post.crop_file_url
else
src = post.preview_file_url
imgClass = nil
cropped_src = post.preview_file_url
end
html = %{<article itemscope itemtype="http://schema.org/ImageObject" id="post_#{post.id}" class="#{imgClass} #{preview_class(post, options[:pool], options)}" #{data_attributes(post)}>}
html = %{<article itemscope itemtype="http://schema.org/ImageObject" id="post_#{post.id}" class="#{preview_class(post, options[:pool], options)}" #{data_attributes(post)}>}
if options[:tags].present? && !CurrentUser.is_anonymous?
tag_param = "?tags=#{CGI::escape(options[:tags])}"
elsif options[:pool_id] || options[:pool]
@@ -42,7 +40,11 @@ class PostPresenter < Presenter
html << %{<a href="#{path}/#{post.id}#{tag_param}">}
tooltip = "#{post.tag_string} rating:#{post.rating} score:#{post.score}"
html << %{<img class="#{imgClass}" itemprop="thumbnailUrl" src="#{src}" title="#{h(tooltip)}" alt="#{h(post.tag_string)}">}
html << %{<picture>}
html << %{<source media="(max-width: 660px)" srcset="#{cropped_src}">}
html << %{<source media="(min-width: 660px)" srcset="#{post.preview_file_url}">}
html << %{<img itemprop="thumbnailUrl" src="#{post.preview_file_url}" title="#{h(tooltip)}" alt="#{h(post.tag_string)}">}
html << %{</picture>}
html << %{</a>}
if options[:pool]

View File

@@ -12,7 +12,7 @@ module PostSetPresenters
end
posts.each do |post|
html << PostPresenter.preview(post, options.merge(:show_cropped => true, :tags => @post_set.tag_string, :raw => @post_set.raw))
html << PostPresenter.preview(post, options.merge(:tags => @post_set.tag_string, :raw => @post_set.raw))
html << "\n"
end

View File

@@ -11,6 +11,10 @@ module PostSetPresenters
@tag_set_presenter ||= TagSetPresenter.new(related_tags)
end
def post_previews_html(template, options = {})
super(template, options.merge(show_cropped: true))
end
def related_tags
if post_set.is_pattern_search?
pattern_tags