FEATURE: new twitter_summary_large_image_url setting

This commit is contained in:
Arpit Jalan 2016-09-19 17:11:12 +05:30
parent d46084d328
commit 332cc2bb95
3 changed files with 18 additions and 5 deletions

View File

@ -142,8 +142,9 @@ module ApplicationHelper
opts ||= {}
opts[:url] ||= "#{Discourse.base_url_no_prefix}#{request.fullpath}"
if opts[:image].blank? && SiteSetting.default_opengraph_image_url.present?
opts[:image] = SiteSetting.default_opengraph_image_url
if opts[:image].blank? && (SiteSetting.default_opengraph_image_url.present? || SiteSetting.twitter_summary_large_image_url.present?)
opts[:twitter_summary_large_image] = SiteSetting.twitter_summary_large_image_url if SiteSetting.twitter_summary_large_image_url.present?
opts[:image] = SiteSetting.default_opengraph_image_url.present? ? SiteSetting.default_opengraph_image_url : SiteSetting.twitter_summary_large_image_url
elsif opts[:image].blank? && SiteSetting.apple_touch_icon_url.present?
opts[:image] = SiteSetting.apple_touch_icon_url
end
@ -156,12 +157,22 @@ module ApplicationHelper
opts[:image] = "#{Discourse.base_url}#{opts[:image]}"
end
# Add opengraph tags
# Add opengraph & twitter tags
result = []
result << tag(:meta, property: 'og:site_name', content: SiteSetting.title)
result << tag(:meta, name: 'twitter:card', content: "summary")
[:url, :title, :description, :image].each do |property|
if opts[:twitter_summary_large_image].present?
result << tag(:meta, name: 'twitter:card', content: "summary_large_image")
result << tag(:meta, name: "twitter:image", content: opts[:twitter_summary_large_image])
elsif opts[:image].present?
result << tag(:meta, name: 'twitter:card', content: "summary")
result << tag(:meta, name: "twitter:image", content: opts[:image])
else
result << tag(:meta, name: 'twitter:card', content: "summary")
end
result << tag(:meta, property: "og:image", content: opts[:image]) if opts[:image].present?
[:url, :title, :description].each do |property|
if opts[property].present?
escape = (property != :image)
result << tag(:meta, { property: "og:#{property}", content: opts[property] }, nil, escape)

View File

@ -1086,6 +1086,7 @@ en:
external_system_avatars_url: "URL of the external system avatars service. Allowed substitutions are {username} {first_letter} {color} {size}"
default_opengraph_image_url: "URL of the default opengraph image."
twitter_summary_large_image_url: "URL of the default Twitter summary card image (should be at least 280px in width, and at least 150px in height)."
allow_all_attachments_for_group_messages: "Allow all email attachments for group messages."

View File

@ -56,6 +56,7 @@ required:
default: '/images/default-favicon.ico'
apple_touch_icon_url: '/images/default-apple-touch-icon.png'
default_opengraph_image_url: ''
twitter_summary_large_image_url: ''
exclude_rel_nofollow_domains:
default: ''
type: list