Skip to content

Commit

Permalink
FEATURE: new twitter_summary_large_image_url setting
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitjalan committed Sep 19, 2016
1 parent d46084d commit 332cc2b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ def crawlable_meta_data(opts=nil)
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
Expand All @@ -156,12 +157,22 @@ def crawlable_meta_data(opts=nil)
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)
Expand Down
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down
1 change: 1 addition & 0 deletions config/site_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 332cc2b

Please sign in to comment.