mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
1
Gemfile
1
Gemfile
@@ -71,7 +71,6 @@ gem 'redis', :require => ["redis", "redis/connection/hiredis"]
|
|||||||
|
|
||||||
gem 'active_model_serializers'
|
gem 'active_model_serializers'
|
||||||
|
|
||||||
gem 'html_truncator'
|
|
||||||
|
|
||||||
# we had issues with latest, stick to the rev till we figure this out
|
# we had issues with latest, stick to the rev till we figure this out
|
||||||
# PR that makes it all hang together welcome
|
# PR that makes it all hang together welcome
|
||||||
|
|||||||
@@ -123,8 +123,6 @@ GEM
|
|||||||
highline (1.6.20)
|
highline (1.6.20)
|
||||||
hike (1.2.3)
|
hike (1.2.3)
|
||||||
hiredis (0.4.5)
|
hiredis (0.4.5)
|
||||||
html_truncator (0.3.1)
|
|
||||||
nokogiri (~> 1.5)
|
|
||||||
httpauth (0.2.0)
|
httpauth (0.2.0)
|
||||||
i18n (0.6.9)
|
i18n (0.6.9)
|
||||||
ice_cube (0.11.1)
|
ice_cube (0.11.1)
|
||||||
@@ -410,7 +408,6 @@ DEPENDENCIES
|
|||||||
handlebars-source (~> 1.1.2)
|
handlebars-source (~> 1.1.2)
|
||||||
highline
|
highline
|
||||||
hiredis
|
hiredis
|
||||||
html_truncator
|
|
||||||
image_optim
|
image_optim
|
||||||
image_sorcery
|
image_sorcery
|
||||||
librarian (>= 0.0.25)
|
librarian (>= 0.0.25)
|
||||||
|
|||||||
@@ -29,7 +29,14 @@ module UserNotificationsHelper
|
|||||||
"<a href='#{Discourse.base_url}'>#{@site_name}</a>"
|
"<a href='#{Discourse.base_url}'>#{@site_name}</a>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def email_excerpt(html)
|
def email_excerpt(html, posts_count)
|
||||||
raw Sanitize.clean(HTML_Truncator.truncate(html, 300), Sanitize::Config::RELAXED)
|
# 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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<%- if t.best_post.present? %>
|
<%- if t.best_post.present? %>
|
||||||
<div class='digest-post'>
|
<div class='digest-post'>
|
||||||
<%= email_excerpt(t.best_post.cooked) %>
|
<%= email_excerpt(t.best_post.cooked, @featured_topics.size) %>
|
||||||
</div>
|
</div>
|
||||||
<%- end %>
|
<%- end %>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user