mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 18:24:52 -06:00
FIX: use absolute URL for twitter:image tag
This commit is contained in:
parent
ef72a9a1fe
commit
9919f16041
@ -210,17 +210,10 @@ module ApplicationHelper
|
||||
opts[:image] = SiteSetting.site_apple_touch_icon_url
|
||||
end
|
||||
|
||||
# Use the correct scheme for open graph image
|
||||
if opts[:image].present?
|
||||
if opts[:image].start_with?("//")
|
||||
uri = URI(Discourse.base_url)
|
||||
opts[:image] = "#{uri.scheme}:#{opts[:image]}"
|
||||
elsif opts[:image].start_with?("/uploads/")
|
||||
opts[:image] = "#{Discourse.base_url}#{opts[:image]}"
|
||||
elsif GlobalSetting.relative_url_root && opts[:image].start_with?(GlobalSetting.relative_url_root)
|
||||
opts[:image] = "#{Discourse.base_url_no_prefix}#{opts[:image]}"
|
||||
end
|
||||
end
|
||||
# Use the correct scheme for opengraph/twitter image
|
||||
opts[:image] = get_absolute_image_url(opts[:image]) if opts[:image].present?
|
||||
opts[:twitter_summary_large_image] =
|
||||
get_absolute_image_url(opts[:twitter_summary_large_image]) if opts[:twitter_summary_large_image].present?
|
||||
|
||||
# Add opengraph & twitter tags
|
||||
result = []
|
||||
@ -452,4 +445,17 @@ module ApplicationHelper
|
||||
|
||||
setup_data
|
||||
end
|
||||
|
||||
def get_absolute_image_url(link)
|
||||
absolute_url = link
|
||||
if link.start_with?("//")
|
||||
uri = URI(Discourse.base_url)
|
||||
absolute_url = "#{uri.scheme}:#{link}"
|
||||
elsif link.start_with?("/uploads/")
|
||||
absolute_url = "#{Discourse.base_url}#{link}"
|
||||
elsif GlobalSetting.relative_url_root && link.start_with?(GlobalSetting.relative_url_root)
|
||||
absolute_url = "#{Discourse.base_url_no_prefix}#{link}"
|
||||
end
|
||||
absolute_url
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user