From f73ed45de9583eea8647b758288babfc9739b2e0 Mon Sep 17 00:00:00 2001
From: Neil Lalonde
Date: Fri, 21 Feb 2020 16:13:06 -0500
Subject: [PATCH] FIX: blank popular posts in summary emails due to lightbox
images
When looking for the first paragraph with content in a post,
it was matching the lightboxed image paragraph as "".
Fix that and other potential empty paragraphs with the
p:not(:empty) selector.
Add a new selector to find the image links in lightboxed
images as valid content for emails.
---
app/helpers/user_notifications_helper.rb | 2 +-
.../helpers/user_notifications_helper_spec.rb | 35 ++++++++++++++++++-
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb
index 4389125bd1..eb0293183b 100644
--- a/app/helpers/user_notifications_helper.rb
+++ b/app/helpers/user_notifications_helper.rb
@@ -49,7 +49,7 @@ module UserNotificationsHelper
# If there is no first paragaph with text, return the first paragraph with
# something else (an image) or div (a onebox).
- doc.css('body > p, body > div').first
+ doc.css('body > p:not(:empty), body > div:not(:empty), body > p > div.lightbox-wrapper img').first
end
def email_excerpt(html_arg, post = nil)
diff --git a/spec/helpers/user_notifications_helper_spec.rb b/spec/helpers/user_notifications_helper_spec.rb
index b72dcf82c0..21e0a181fe 100644
--- a/spec/helpers/user_notifications_helper_spec.rb
+++ b/spec/helpers/user_notifications_helper_spec.rb
@@ -28,6 +28,22 @@ describe UserNotificationsHelper do
HTML
end
+ let(:image_paragraph) do
+ '
'
+ end
+
+ let(:lightbox_image) do
+ <<~HTML
+
+ HTML
+ end
+
+ let(:expected_lightbox_image) do
+ '
'
+ end
+
it "can return the first paragraph" do
SiteSetting.digest_min_excerpt_length = 50
expect(helper.email_excerpt(cooked)).to eq(paragraphs[0])
@@ -71,7 +87,7 @@ describe UserNotificationsHelper do
end
it "defaults to content after post quote (image w/ no text)" do
- image_paragraph = '
'
+
cooked = <<~HTML
#{post_quote}
#{image_paragraph}
@@ -87,6 +103,23 @@ describe UserNotificationsHelper do
HTML
expect(helper.email_excerpt(cooked)).to eq(aside_onebox)
end
+
+ it "defaults to content after post quote (lightbox image w/ no text)" do
+ cooked = <<~HTML
+ #{post_quote}
+ #{lightbox_image}
+ HTML
+ expect(helper.email_excerpt(cooked)).to eq(expected_lightbox_image)
+ end
+
+ it "handles when there's only an image" do
+ image_paragraph
+ expect(helper.email_excerpt("#{image_paragraph}")).to eq(image_paragraph)
+ end
+
+ it "handles when there's only a lightboxed image" do
+ expect(helper.email_excerpt("#{lightbox_image}")).to eq(expected_lightbox_image)
+ end
end
describe '#logo_url' do