FEATURE: Return only the first paragraph of text in HTML digests, unless

there is only one post. In that case return everything. Remove
dependency on 'html_truncator'
This commit is contained in:
Robin Ward
2014-01-22 12:37:37 -05:00
parent 502b4730c8
commit 39c6e48aa5
4 changed files with 10 additions and 7 deletions

View File

@ -29,7 +29,14 @@ module UserNotificationsHelper
"<a href='#{Discourse.base_url}'>#{@site_name}</a>"
end
def email_excerpt(html)
raw Sanitize.clean(HTML_Truncator.truncate(html, 300), Sanitize::Config::RELAXED)
def email_excerpt(html, posts_count)
# If there's only one post, include the whole thing.
if posts_count == 1
return raw Sanitize.clean(html, Sanitize::Config::RELAXED)
else
# Otherwise, try just the first paragraph.
first_paragraph = Nokogiri::HTML(html).at('p')
return raw Sanitize.clean(first_paragraph.to_s, Sanitize::Config::RELAXED)
end
end
end