mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Do not use SVGs for twitter:image metadata (#16973)
Twitter does not allow SVGs to be used for twitter:image metadata (see https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup) so we should fall back to the site logo if the image option provided to `crawlable_meta_data` or SiteSetting.site_twitter_summary_large_image_url is an SVG, and do not add the meta tag for twitter:image at all if the site logo is an SVG.
This commit is contained in:
@@ -289,15 +289,7 @@ module ApplicationHelper
|
||||
result << tag(:meta, property: 'og:site_name', content: SiteSetting.title)
|
||||
result << tag(:meta, property: 'og:type', content: 'website')
|
||||
|
||||
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 = generate_twitter_card_metadata(opts, result)
|
||||
result << tag(:meta, property: "og:image", content: opts[:image]) if opts[:image].present?
|
||||
|
||||
[:url, :title, :description].each do |property|
|
||||
@@ -326,6 +318,29 @@ module ApplicationHelper
|
||||
result.join("\n")
|
||||
end
|
||||
|
||||
def generate_twitter_card_metadata(opts, result)
|
||||
img_url = opts[:twitter_summary_large_image].present? ? \
|
||||
opts[:twitter_summary_large_image] :
|
||||
opts[:image]
|
||||
|
||||
# Twitter does not allow SVGs, see https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup
|
||||
if img_url.ends_with?(".svg")
|
||||
img_url = SiteSetting.site_logo_url.ends_with?(".svg") ? nil : SiteSetting.site_logo_url
|
||||
end
|
||||
|
||||
if opts[:twitter_summary_large_image].present? && img_url.present?
|
||||
result << tag(:meta, name: 'twitter:card', content: "summary_large_image")
|
||||
result << tag(:meta, name: "twitter:image", content: img_url)
|
||||
elsif opts[:image].present? && img_url.present?
|
||||
result << tag(:meta, name: 'twitter:card', content: "summary")
|
||||
result << tag(:meta, name: "twitter:image", content: img_url)
|
||||
else
|
||||
result << tag(:meta, name: 'twitter:card', content: "summary")
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def render_sitelinks_search_tag
|
||||
json = {
|
||||
'@context' => 'http://schema.org',
|
||||
|
||||
Reference in New Issue
Block a user