mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:15:05 +08:00
FIX: Optimize images in Onebox (#8471)
This commit ensures that images in Onebox are being optimized, but not converted to lightbox too.
This commit is contained in:
parent
f62b8990ac
commit
ebe6fa95be
|
@ -206,9 +206,7 @@ class CookedPostProcessor
|
|||
# minus data images
|
||||
@doc.css("img[src^='data']") -
|
||||
# minus emojis
|
||||
@doc.css("img.emoji") -
|
||||
# minus oneboxed images
|
||||
oneboxed_images
|
||||
@doc.css("img.emoji")
|
||||
end
|
||||
|
||||
def extract_images_for_post
|
||||
|
@ -346,7 +344,10 @@ class CookedPostProcessor
|
|||
end
|
||||
end
|
||||
|
||||
add_lightbox!(img, original_width, original_height, upload, cropped: crop) if img.ancestors('.quote').blank?
|
||||
if img.ancestors('.onebox, .onebox-body, .quote').blank? && !img.classes.include?("onebox")
|
||||
add_lightbox!(img, original_width, original_height, upload, cropped: crop)
|
||||
end
|
||||
|
||||
optimize_image!(img, upload, cropped: crop) if upload
|
||||
end
|
||||
|
||||
|
|
|
@ -946,6 +946,21 @@ describe CookedPostProcessor do
|
|||
expect(doc.css('.lightbox-wrapper').size).to eq(0)
|
||||
expect(doc.css('img').first['srcset']).to_not eq(nil)
|
||||
end
|
||||
|
||||
it "optimizes images in Onebox" do
|
||||
Oneboxer.expects(:onebox)
|
||||
.with("https://discourse.org", anything)
|
||||
.returns("<aside class='onebox'><img src='#{upload.url}' width='512' height='384'></aside>")
|
||||
|
||||
post = Fabricate(:post, raw: "https://discourse.org")
|
||||
|
||||
cpp = CookedPostProcessor.new(post, disable_loading_image: true)
|
||||
cpp.post_process
|
||||
|
||||
doc = Nokogiri::HTML::fragment(cpp.html)
|
||||
expect(doc.css('.lightbox-wrapper').size).to eq(0)
|
||||
expect(doc.css('img').first['srcset']).to_not eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "#post_process_oneboxes" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user