mirror of
https://github.com/discourse/discourse.git
synced 2025-04-17 12:11:27 +08: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:
parent
502b4730c8
commit
39c6e48aa5
1
Gemfile
1
Gemfile
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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 %>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user