From a39929d12e62fbcdf9fa41f30aba2c7f29c44301 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 19 Aug 2016 17:04:43 +0530 Subject: [PATCH] FEATURE: add opengraph and twitter meta tags on every page --- app/helpers/application_helper.rb | 2 ++ app/views/about/index.html.erb | 4 ++++ app/views/categories/index.html.erb | 4 ++++ app/views/list/list.erb | 4 ++++ app/views/static/show.html.erb | 7 +++++++ lib/topic_view.rb | 2 +- 6 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ec98366fb..59d6d91e8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -148,6 +148,8 @@ module ApplicationHelper opts[:image] = "#{uri.scheme}:#{opts[:image]}" elsif opts[:image].present? && opts[:image].start_with?("/uploads/") opts[:image] = "#{Discourse.base_url}#{opts[:image]}" + elsif SiteSetting.default_opengraph_image_url.present? + opts[:image] = SiteSetting.default_opengraph_image_url end # Add opengraph tags diff --git a/app/views/about/index.html.erb b/app/views/about/index.html.erb index 5f8bb079b..e669e1559 100644 --- a/app/views/about/index.html.erb +++ b/app/views/about/index.html.erb @@ -104,3 +104,7 @@
<% end %> + +<% content_for :head do %> + <%= raw crawlable_meta_data(title: SiteSetting.title, description: SiteSetting.site_description) %> +<% end %> diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index 2d2b32d3e..f30438dd2 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -12,3 +12,7 @@ <% content_for :title do %><%= @title %><% end %> + +<% content_for :head do %> + <%= raw crawlable_meta_data(title: SiteSetting.title, description: SiteSetting.site_description) %> +<% end %> diff --git a/app/views/list/list.erb b/app/views/list/list.erb index a88fb4997..9b1513915 100644 --- a/app/views/list/list.erb +++ b/app/views/list/list.erb @@ -65,6 +65,10 @@ <%= auto_discovery_link_tag(:rss, { action: :category_feed }, title: t('rss_topics_in_category', category: @category.name)) %> <%= raw crawlable_meta_data(title: @category.name, description: @category.description) %> <% end %> +<% else %> + <% content_for :head do %> + <%= raw crawlable_meta_data(title: SiteSetting.title, description: SiteSetting.site_description) %> + <% end %> <% end %> <% if @title %> diff --git a/app/views/static/show.html.erb b/app/views/static/show.html.erb index 0f84dbcaa..7716a6964 100644 --- a/app/views/static/show.html.erb +++ b/app/views/static/show.html.erb @@ -23,4 +23,11 @@ <% if @title %> <% content_for :title do %><%= @title %><% end %> + <% content_for :head do %> + <%= raw crawlable_meta_data(title: @title, description: SiteSetting.site_description) %> + <% end %> +<% else %> + <% content_for :head do %> + <%= raw crawlable_meta_data(title: SiteSetting.title, description: SiteSetting.site_description) %> + <% end %> <% end %> diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 74637fa3e..f69d3e471 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -174,7 +174,7 @@ class TopicView # show poster avatar @desired_post.user.avatar_template_url.gsub("{size}", "100") if @desired_post.user else - @topic.image_url || SiteSetting.default_opengraph_image_url + @topic.image_url end end