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

@ -71,7 +71,6 @@ gem 'redis', :require => ["redis", "redis/connection/hiredis"]
gem 'active_model_serializers'
gem 'html_truncator'
# we had issues with latest, stick to the rev till we figure this out
# PR that makes it all hang together welcome

View File

@ -123,8 +123,6 @@ GEM
highline (1.6.20)
hike (1.2.3)
hiredis (0.4.5)
html_truncator (0.3.1)
nokogiri (~> 1.5)
httpauth (0.2.0)
i18n (0.6.9)
ice_cube (0.11.1)
@ -410,7 +408,6 @@ DEPENDENCIES
handlebars-source (~> 1.1.2)
highline
hiredis
html_truncator
image_optim
image_sorcery
librarian (>= 0.0.25)

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

View File

@ -17,7 +17,7 @@
<%- if t.best_post.present? %>
<div class='digest-post'>
<%= email_excerpt(t.best_post.cooked) %>
<%= email_excerpt(t.best_post.cooked, @featured_topics.size) %>
</div>
<%- end %>