FIX: excerpts in summary email are too short when there are images or links
This commit is contained in:
parent
5f133e20f2
commit
ab2f3e43eb
|
@ -32,14 +32,16 @@ module UserNotificationsHelper
|
|||
"<a href='#{Discourse.base_url}' style='color: ##{color}'>#{@site_name}</a>"
|
||||
end
|
||||
|
||||
def first_paragraph_from(html)
|
||||
def first_paragraphs_from(html)
|
||||
doc = Nokogiri::HTML(html)
|
||||
|
||||
result = ""
|
||||
length = 0
|
||||
doc.css('body > p, aside.onebox').each do |node|
|
||||
if node.text.present?
|
||||
result << node.to_s
|
||||
return result if result.size >= SiteSetting.digest_min_excerpt_length
|
||||
length += node.inner_text.length
|
||||
return result if length >= SiteSetting.digest_min_excerpt_length
|
||||
end
|
||||
end
|
||||
return result unless result.blank?
|
||||
|
@ -49,7 +51,7 @@ module UserNotificationsHelper
|
|||
end
|
||||
|
||||
def email_excerpt(html_arg)
|
||||
html = (first_paragraph_from(html_arg) || html_arg).to_s
|
||||
html = (first_paragraphs_from(html_arg) || html_arg).to_s
|
||||
PrettyText.format_for_email(html).html_safe
|
||||
end
|
||||
|
||||
|
|
|
@ -20,5 +20,19 @@ describe UserNotificationsHelper do
|
|||
SiteSetting.digest_min_excerpt_length = 100
|
||||
expect(helper.email_excerpt(cooked)).to eq(paragraphs.join)
|
||||
end
|
||||
|
||||
it "doesn't count emoji images" do
|
||||
with_emoji = "<p>Hi <img src=\"/images/emoji/twitter/smile.png?v=5\" title=\":smile:\" class=\"emoji\" alt=\":smile:\"></p>"
|
||||
arg = ([with_emoji] + paragraphs).join("\n")
|
||||
SiteSetting.digest_min_excerpt_length = 50
|
||||
expect(helper.email_excerpt(arg)).to eq([with_emoji, paragraphs[0]].join)
|
||||
end
|
||||
|
||||
it "only counts link text" do
|
||||
with_link = "<p>Hi <a href=\"https://really-long.essays.com/essay/number/9000/this-one-is-about-friends-and-got-a-C-minus-in-grade-9\">friends</a>!</p>"
|
||||
arg = ([with_link] + paragraphs).join("\n")
|
||||
SiteSetting.digest_min_excerpt_length = 50
|
||||
expect(helper.email_excerpt(arg)).to eq([with_link, paragraphs[0]].join)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue