The discussion revolves around styling anchors in email digests in Discourse. joebuhlig initiated the conversation, looking for a way to change the anchor text styling in email digests to match their site’s branding. simon suggested using a plugin to add styles to emails, providing an example code snippet that makes links red and bold. However, this approach has limitations.
simon proposed that Discourse’s code could be modified to pass site color scheme values to Email::Styles as options, making it easier to customize email styling. joebuhlig agreed that a plugin or PR could be a good solution. Before starting work on this, joebuhlig asked if this was on the roadmap or if there was a desired method for customizing email styling.
joebuhlig eventually created a PR to address this issue, which simon confirmed has been implemented, allowing anchor text in email digests to use the site’s color theme.
I did a lot of searching and came up lacking. Is there a way to alter the styling of the email digests? The only thing I’m interested in changing is the anchor text. I’d like it to match the rest of my site’s branding. I couldn’t find a way to do it through the Customize feature, but I may not be thinking about it right. Thanks.
There might be better ways, but you can add styles to emails in a plugin by calling Email::Styles.register_plugin_style and passing it a block that acts on the email (the email is a Nokogiri document at this point).
This will make the links red and bold. The problem is that it will make all the links red and bold. To target just the ones you want will take a bit of fiddling around.
# name: email-styles
# version: 0.1
after_initialize do
require_dependency 'email/styles'
Email::Styles.register_plugin_style do |doc|
doc.css('a').each do |element|
element['style'] = "color:red; font-weight:bold;"
end
end
end
Yes it does. Maybe things could be changed in the Discourse code so that values from the site’s color scheme are passed to Email::Styles as options.
For example adding: cta_color: ColorScheme.hex_for_name('tertiary') to email_opts in user_notifications.rb makes it possible to set the call-to-action button background color to @opts[:cta_color]
Before I start looking for time to do this, does anyone know if this is on the roadmap or if there’s a desired method for how this is done in the future?