FEATURE: Enables support for dark mode emails (#16520)

This PR enables custom email dark mode styles by default that were added here.

There is currently poor support for dark mode queries in mail clients. The main beneficiary of these changes will be Apple Mail and Outlook.

Enjoy the darkness 🕶️
This commit is contained in:
Isaac Janzen 2022-04-20 13:00:04 -05:00 committed by GitHub
parent 196b791365
commit 692e0140e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 4 additions and 11 deletions

View File

@ -29,8 +29,8 @@ 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 : "")
.gsub('%{dark_mode_meta_tags}', dark_mode_meta_tags)
.gsub('%{dark_mode_styles}', dark_mode_styles)
.html_safe
end

View File

@ -283,9 +283,6 @@ basic:
type: enum
enum: "ColorSchemeSetting"
client: true
dark_mode_emails_active:
default: false
hidden: true
relative_date_duration:
client: true
default: 30

View File

@ -238,7 +238,7 @@ module Email
onebox_styles
plugin_styles
dark_mode_styles if SiteSetting.dark_mode_emails_active
dark_mode_styles
style('.post-excerpt img', "max-width: 50%; max-height: #{MAX_IMAGE_DIMENSION}px;")

View File

@ -72,7 +72,7 @@ describe EmailStyle do
SiteSetting.default_email_in_reply_to = true
expect(mail_html.scan('<h1 style="color: red;">FOR YOU</h1>').count).to eq(1)
matches = mail_html.match(/<div style="([^"]+)">#{post.raw}/)
matches = mail_html.match(/<div style="([^"]+)" dm=\"body\">#{post.raw}/)
expect(matches[1]).to include('color: #FAB;') # custom
expect(matches[1]).to include('padding-top:5px;') # div.body
end

View File

@ -157,10 +157,6 @@ 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('<div class="body">test</div>')
styler = Email::Styles.new(frag)