mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
FIX: email excerpts for posts starting with a quote were displaying a username
If a post starts with a post quote and has no other text content, then the email excerpt was the name of the person quoted and nothing else. The intention was to show the contents of the first paragraph or div after the quote. With this change, a quote followed by an image will use the image as the excerpt. A quote followed by a onebox will use the onebox.
This commit is contained in:
parent
7ba2b677a6
commit
565a967192
@ -47,8 +47,9 @@ module UserNotificationsHelper
|
||||
|
||||
return result unless result.blank?
|
||||
|
||||
# If there is no first paragaph, return the first div (onebox)
|
||||
doc.css('div').first
|
||||
# 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
|
||||
end
|
||||
|
||||
def email_excerpt(html_arg, post = nil)
|
||||
|
@ -13,6 +13,19 @@ describe UserNotificationsHelper do
|
||||
paragraphs.join("\n")
|
||||
end
|
||||
|
||||
let(:post_quote) do
|
||||
<<~HTML
|
||||
<aside class="quote no-group" data-post="859" data-topic="30">
|
||||
<div class="title">
|
||||
<div class="quote-controls"></div>
|
||||
<img alt width="20" height="20" src="https://example.com/m.png" class="avatar"> modman:</div>
|
||||
<blockquote>
|
||||
<p>This is a post quote</p>
|
||||
</blockquote>
|
||||
</aside>
|
||||
HTML
|
||||
end
|
||||
|
||||
it "can return the first paragraph" do
|
||||
SiteSetting.digest_min_excerpt_length = 50
|
||||
expect(helper.email_excerpt(cooked)).to eq(paragraphs[0])
|
||||
@ -54,6 +67,24 @@ describe UserNotificationsHelper do
|
||||
|
||||
expect(helper.email_excerpt(cooked)).to eq "<p>BEFORE</p><blockquote>\n <p>This is a user quote</p>\n</blockquote><p>AFTER</p>"
|
||||
end
|
||||
|
||||
it "defaults to content after post quote (image w/ no text)" do
|
||||
image_paragraph = '<p><img src="//localhost:3000/uploads/b9.png" width="300" height="300"></p>'
|
||||
cooked = <<~HTML
|
||||
#{post_quote}
|
||||
#{image_paragraph}
|
||||
HTML
|
||||
expect(helper.email_excerpt(cooked)).to eq(image_paragraph)
|
||||
end
|
||||
|
||||
it "defaults to content after post quote (onebox)" do
|
||||
aside_onebox = '<aside class="onebox wikipedia"><article class="onebox-body"><p>Onebox excerpt here</p></article><div class="onebox-metadata"></div></aside>'
|
||||
cooked = <<~HTML
|
||||
#{post_quote}
|
||||
#{aside_onebox}
|
||||
HTML
|
||||
expect(helper.email_excerpt(cooked)).to eq(aside_onebox)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#logo_url' do
|
||||
|
Loading…
Reference in New Issue
Block a user