FEATURE: Add email dark mode (#16104)

implement dark mode emails when `SiteSetting.dark_mode_emails_active` is active.
This commit is contained in:
Isaac Janzen
2022-04-11 12:27:50 -05:00
committed by GitHub
parent a0ef25f4f0
commit 6c0abe15e0
9 changed files with 104 additions and 8 deletions

View File

@@ -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
"
<meta name='color-scheme' content='light dark' />
<meta name='supported-color-schemes' content='light dark' />
"
end
def dark_mode_styles
"
<style>
@media (prefers-color-scheme: dark) {
html {
background: #151515 !important;
}
h1,
h2,
h3,
h4,
h5,
h6,
p,
span {
color: #dddddd !important;
}
[dm='light-img'] {
display: none !important;
}
[dm='dark-img'] {
display: block !important;
}
[dm='text-color'] {
color: #dddddd;
}
[dm='header'] {
background: #151515 !important;
}
[dm='body'] {
background: #222222 !important;
color: #dddddd !important;
}
[dm='body_primary'] {
background: #062e3d !important;
color: #dddddd !important;
}
}
</style>
"
end
def extract_details(topic)
if SiteSetting.private_email?
[topic.slugless_url, private_topic_title(topic)]