FIX: Use CDN for logos and icons. (#6698)
This commit is contained in:
parent
1ab91f0474
commit
2eefe6d5d6
|
@ -23,9 +23,7 @@ module UserNotificationsHelper
|
|||
logo_url = SiteSetting.site_logo_url if logo_url.blank? || logo_url =~ /\.svg$/i
|
||||
return nil if logo_url.blank? || logo_url =~ /\.svg$/i
|
||||
|
||||
uri = URI.parse(UrlHelper.absolute(upload_cdn_path(logo_url)))
|
||||
uri.scheme = SiteSetting.scheme if uri.scheme.blank?
|
||||
uri.to_s
|
||||
full_cdn_url(logo_url)
|
||||
end
|
||||
|
||||
def html_site_link(color)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
require 'site_setting_extension'
|
||||
require_dependency 'global_path'
|
||||
require_dependency 'site_settings/yaml_loader'
|
||||
|
||||
class SiteSetting < ActiveRecord::Base
|
||||
extend GlobalPath
|
||||
extend SiteSettingExtension
|
||||
|
||||
validates_presence_of :name
|
||||
|
@ -176,35 +178,43 @@ class SiteSetting < ActiveRecord::Base
|
|||
}.each { |client_setting| client_settings << client_setting }
|
||||
|
||||
def self.site_logo_url
|
||||
self.logo&.url || self.logo_url(warn: false)
|
||||
upload = self.logo
|
||||
upload ? full_cdn_url(upload.url) : self.logo_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_logo_small_url
|
||||
self.logo_small&.url || self.logo_small_url(warn: false)
|
||||
upload = self.logo_small
|
||||
upload ? full_cdn_url(upload.url) : self.logo_small_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_digest_logo_url
|
||||
self.digest_logo&.url || self.digest_logo_url(warn: false)
|
||||
upload = self.digest_logo
|
||||
upload ? full_cdn_url(upload.url) : self.digest_logo_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_mobile_logo_url
|
||||
self.mobile_logo&.url || self.mobile_logo_url(warn: false)
|
||||
upload = self.mobile_logo
|
||||
upload ? full_cdn_url(upload.url) : self.mobile_logo_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_large_icon_url
|
||||
self.large_icon&.url || self.large_icon_url(warn: false)
|
||||
upload = self.large_icon
|
||||
upload ? full_cdn_url(upload.url) : self.large_icon_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_favicon_url
|
||||
self.favicon&.url || self.favicon_url(warn: false)
|
||||
upload = self.favicon
|
||||
upload ? full_cdn_url(upload.url) : self.favicon_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_apple_touch_icon_url
|
||||
self.apple_touch_icon&.url || self.apple_touch_icon_url(warn: false)
|
||||
upload = self.apple_touch_icon
|
||||
upload ? full_cdn_url(upload.url) : self.apple_touch_icon_url(warn: false)
|
||||
end
|
||||
|
||||
def self.opengraph_image_url
|
||||
self.opengraph_image&.url || self.default_opengraph_image_url(warn: false)
|
||||
upload = self.opengraph_image
|
||||
upload ? full_cdn_url(upload.url) : self.default_opengraph_image_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_twitter_summary_large_image_url
|
||||
|
|
|
@ -22,4 +22,10 @@ module GlobalPath
|
|||
end
|
||||
end
|
||||
|
||||
def full_cdn_url(url)
|
||||
uri = URI.parse(UrlHelper.absolute(upload_cdn_path(url)))
|
||||
uri.scheme = SiteSetting.scheme if uri.scheme.blank?
|
||||
uri.to_s
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
require 'rails_helper'
|
||||
require 'wizard'
|
||||
require 'wizard/builder'
|
||||
require 'global_path'
|
||||
|
||||
class GlobalPathInstance
|
||||
extend GlobalPath
|
||||
end
|
||||
|
||||
describe Wizard::Builder do
|
||||
let(:moderator) { Fabricate.build(:moderator) }
|
||||
|
@ -49,9 +54,9 @@ describe Wizard::Builder do
|
|||
logo_small_field = fields.last
|
||||
|
||||
expect(logo_field.id).to eq('logo')
|
||||
expect(logo_field.value).to eq(upload.url)
|
||||
expect(logo_field.value).to eq(GlobalPathInstance.full_cdn_url(upload.url))
|
||||
expect(logo_small_field.id).to eq('logo_small')
|
||||
expect(logo_small_field.value).to eq(upload2.url)
|
||||
expect(logo_small_field.value).to eq(GlobalPathInstance.full_cdn_url(upload2.url))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -70,9 +75,9 @@ describe Wizard::Builder do
|
|||
apple_touch_icon_field = fields.last
|
||||
|
||||
expect(favicon_field.id).to eq('favicon')
|
||||
expect(favicon_field.value).to eq(upload.url)
|
||||
expect(favicon_field.value).to eq(GlobalPathInstance.full_cdn_url(upload.url))
|
||||
expect(apple_touch_icon_field.id).to eq('apple_touch_icon')
|
||||
expect(apple_touch_icon_field.value).to eq(upload2.url)
|
||||
expect(apple_touch_icon_field.value).to eq(GlobalPathInstance.full_cdn_url(upload2.url))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue