From 332cc2bb95d700cba78feb0f079ff4b32d56b29d Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 19 Sep 2016 17:11:12 +0530 Subject: [PATCH] FEATURE: new twitter_summary_large_image_url setting --- app/helpers/application_helper.rb | 21 ++++++++++++++++----- config/locales/server.en.yml | 1 + config/site_settings.yml | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7a9e06c79..d0e70b6b0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 2e533645b..96c5facc9 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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." diff --git a/config/site_settings.yml b/config/site_settings.yml index bf3289b2d..25f92abde 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -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