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
|
# 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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue