diff --git a/app/helpers/email_helper.rb b/app/helpers/email_helper.rb index f738ac4973..ed24cb8ed1 100644 --- a/app/helpers/email_helper.rb +++ b/app/helpers/email_helper.rb @@ -29,11 +29,69 @@ module EmailHelper EmailStyle.new.html .sub('%{email_content}') { capture { yield } } .gsub('%{html_lang}', html_lang) + .gsub('%{dark_mode_meta_tags}', SiteSetting.dark_mode_emails_active ? dark_mode_meta_tags : "") + .gsub('%{dark_mode_styles}', SiteSetting.dark_mode_emails_active ? dark_mode_styles : "") .html_safe end protected + def dark_mode_meta_tags + " + + + " + end + + def dark_mode_styles + " + + " + end + def extract_details(topic) if SiteSetting.private_email? [topic.slugless_url, private_topic_title(topic)] diff --git a/app/views/email/default_template.html b/app/views/email/default_template.html index 53e99ab184..f660cc46fd 100644 --- a/app/views/email/default_template.html +++ b/app/views/email/default_template.html @@ -10,6 +10,7 @@ name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" /> + %{dark_mode_meta_tags} @@ -45,5 +46,6 @@                                         + %{dark_mode_styles} diff --git a/app/views/user_notifications/digest.html.erb b/app/views/user_notifications/digest.html.erb index e40d9c050f..58ed12986b 100644 --- a/app/views/user_notifications/digest.html.erb +++ b/app/views/user_notifications/digest.html.erb @@ -104,7 +104,7 @@ - +
@@ -121,7 +121,7 @@
- +
@@ -156,15 +156,17 @@
<%- end %> - +
@@ -330,11 +333,13 @@ <% end %> diff --git a/config/site_settings.yml b/config/site_settings.yml index 78ab66041c..5ccb510d6f 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -283,6 +283,9 @@ basic: type: enum enum: "ColorSchemeSetting" client: true + dark_mode_emails_active: + default: false + hidden: true relative_date_duration: client: true default: 30 diff --git a/lib/email/styles.rb b/lib/email/styles.rb index 416798e042..02e347576c 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -238,6 +238,7 @@ module Email onebox_styles plugin_styles + dark_mode_styles if SiteSetting.dark_mode_emails_active style('.post-excerpt img', "max-width: 50%; max-height: #{MAX_IMAGE_DIMENSION}px;") @@ -333,6 +334,16 @@ module Email private + def dark_mode_styles + # When we ship the email template and its styles we strip all css classes so to give our + # dark mode styles we are including in the template a selector we add a data-attr of 'dm=value' to + # the appropriate place + style(".digest-header, .digest-topic, .digest-topic-body, .digest-topic-title-wrapper, .digest-topic-stats, .popular-post-excerpt", nil, dm: "header") + style(".digest-content, .header-popular-posts, .spacer, .popular-post-spacer, .popular-post-meta, .digest-new-header, .digest-new-topic, .body", nil, dm: "body") + style(".with-accent-colors, .digest-content-header", nil, dm: "body_primary") + style(".summary-footer", nil, dm: "text-color") + end + def replace_relative_urls forum_uri = URI(Discourse.base_url) host = forum_uri.host diff --git a/public/images/emails/comment_dark.png b/public/images/emails/comment_dark.png new file mode 100644 index 0000000000..46bdeaaec0 Binary files /dev/null and b/public/images/emails/comment_dark.png differ diff --git a/public/images/emails/heart_dark.png b/public/images/emails/heart_dark.png new file mode 100644 index 0000000000..145b0ff3ba Binary files /dev/null and b/public/images/emails/heart_dark.png differ diff --git a/public/images/emails/right_triangle_dark.png b/public/images/emails/right_triangle_dark.png new file mode 100644 index 0000000000..8b4c12020f Binary files /dev/null and b/public/images/emails/right_triangle_dark.png differ diff --git a/spec/lib/email/styles_spec.rb b/spec/lib/email/styles_spec.rb index 0b82af62d8..ee00d8ba2d 100644 --- a/spec/lib/email/styles_spec.rb +++ b/spec/lib/email/styles_spec.rb @@ -156,6 +156,23 @@ describe Email::Styles do end + context "dark mode emails" do + before do + SiteSetting.dark_mode_emails_active = true + end + + it "adds dark_mode_styles when site setting active" do + frag = html_fragment('
test
') + styler = Email::Styles.new(frag) + styler.format_basic + styler.format_html + @frag = Nokogiri::HTML5.fragment(styler.to_s) + + # dark mode attribute + expect(@frag.css('[dm="body"]')).to be_present + end + end + context "strip_avatars_and_emojis" do it "works for lonesome emoji with no title" do emoji = ""
- likes + likes +  <%= t.like_count -%> - replies + replies +  <%= t.posts_count - 1 -%> @@ -245,7 +247,8 @@
- + +
- likes + likes +

<%= t.like_count -%>

- replies + replies +

<%= t.posts_count - 1 -%>