1
0

theme_helper.rb 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. # frozen_string_literal: true
  2. module ThemeHelper
  3. def theme_style_tags(theme)
  4. if theme == 'system'
  5. ''.html_safe.tap do |tags|
  6. tags << stylesheet_pack_tag('mastodon-light', media: 'not all and (prefers-color-scheme: dark)', crossorigin: 'anonymous')
  7. tags << stylesheet_pack_tag('default', media: '(prefers-color-scheme: dark)', crossorigin: 'anonymous')
  8. end
  9. else
  10. stylesheet_pack_tag theme, media: 'all', crossorigin: 'anonymous'
  11. end
  12. end
  13. def theme_color_tags(theme)
  14. if theme == 'system'
  15. ''.html_safe.tap do |tags|
  16. tags << tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:dark], media: '(prefers-color-scheme: dark)')
  17. tags << tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:light], media: '(prefers-color-scheme: light)')
  18. end
  19. else
  20. tag.meta name: 'theme-color', content: theme_color_for(theme)
  21. end
  22. end
  23. private
  24. def theme_color_for(theme)
  25. theme == 'mastodon-light' ? Themes::THEME_COLORS[:light] : Themes::THEME_COLORS[:dark]
  26. end
  27. end