logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

premailer_webpack_strategy.rb (630B)


  1. # frozen_string_literal: true
  2. module PremailerWebpackStrategy
  3. def load(url)
  4. asset_host = ENV['CDN_HOST'] || ENV['WEB_DOMAIN'] || ENV['LOCAL_DOMAIN']
  5. if Webpacker.dev_server.running?
  6. asset_host = "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}"
  7. url = File.join(asset_host, url)
  8. end
  9. css = if url.start_with?('http')
  10. HTTP.get(url).to_s
  11. else
  12. url = url[1..-1] if url.start_with?('/')
  13. File.read(Rails.root.join('public', url))
  14. end
  15. css.gsub(/url\(\//, "url(#{asset_host}/")
  16. end
  17. module_function :load
  18. end