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:
Dan Ungureanu 2019-12-09 15:39:25 +02:00 committed by GitHub
parent f62b8990ac
commit ebe6fa95be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -206,9 +206,7 @@ class CookedPostProcessor
# minus data images # minus data images
@doc.css("img[src^='data']") - @doc.css("img[src^='data']") -
# minus emojis # minus emojis
@doc.css("img.emoji") - @doc.css("img.emoji")
# minus oneboxed images
oneboxed_images
end end
def extract_images_for_post def extract_images_for_post
@ -346,7 +344,10 @@ class CookedPostProcessor
end end
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 optimize_image!(img, upload, cropped: crop) if upload
end end

View File

@ -946,6 +946,21 @@ describe CookedPostProcessor do
expect(doc.css('.lightbox-wrapper').size).to eq(0) expect(doc.css('.lightbox-wrapper').size).to eq(0)
expect(doc.css('img').first['srcset']).to_not eq(nil) expect(doc.css('img').first['srcset']).to_not eq(nil)
end 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 end
context "#post_process_oneboxes" do context "#post_process_oneboxes" do