diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb index 1b224db4974..728f4cd9ea7 100644 --- a/app/helpers/user_notifications_helper.rb +++ b/app/helpers/user_notifications_helper.rb @@ -39,9 +39,15 @@ module UserNotificationsHelper def first_paragraph_from(html) doc = Nokogiri::HTML(html) + + result = "" doc.css('p').each do |p| - return p if p.text.present? + if p.text.present? + result << p.to_s + return result if result.size >= 100 + end end + return result unless result.blank? # If there is no first paragaph, return the first div (onebox) doc.css('div').first @@ -54,7 +60,7 @@ module UserNotificationsHelper else # Otherwise, try just the first paragraph. para = first_paragraph_from(html) - raw Sanitize.clean(para.to_s, UserNotificationsHelper.sanitize_options) + raw Sanitize.clean(para, UserNotificationsHelper.sanitize_options) end end end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 7894fb35365..5fd111a2ca7 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -785,6 +785,7 @@ en: allow_uploaded_avatars: "Allow users to upload their custom avatars" allow_animated_avatars: "Allow users to use animated gif for avatars. WARNING: it is highly recommended to run the avatars:regenerate rake task after changing that setting." + digest_min_excerpt_length: "How many characters we're aiming for for each post in the email digest" default_digest_email_frequency: "How often users receive digest emails by default. They can change this setting in their preferences." default_external_links_in_new_tab: "Open external links in a new tab. Users can change this in their preferences." diff --git a/config/site_settings.yml b/config/site_settings.yml index 33c6190b1e2..a88b1234d54 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -213,6 +213,7 @@ posting: email: email_time_window_mins: 10 email_posts_context: 5 + digest_min_excerpt_length: 100 default_digest_email_frequency: default: 7 enum: 'DigestEmailSiteSetting'