From ccaf525e8d73dd42a75b747f5234262d7f1b5a6c Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 8 Jun 2015 12:07:35 -0400 Subject: [PATCH] FIX: Bad page title for categories view by google crawler --- app/controllers/application_controller.rb | 4 ++++ app/controllers/categories_controller.rb | 4 ++++ app/controllers/list_controller.rb | 3 +-- app/views/categories/index.html.erb | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8ec435424fe..7b3534046ae 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -212,6 +212,10 @@ class ApplicationController < ActionController::Base @guardian ||= Guardian.new(current_user) end + def current_homepage + current_user ? SiteSetting.homepage : SiteSetting.anonymous_homepage + end + def serialize_data(obj, serializer, opts=nil) # If it's an array, apply the serializer as an each_serializer to the elements serializer_opts = {scope: guardian}.merge!(opts || {}) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 0fa958c8ee5..81994721073 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -24,6 +24,10 @@ class CategoriesController < ApplicationController discourse_expires_in 1.minute + unless current_homepage == 'categories' + @title = I18n.t('js.filters.categories.title') + end + store_preloaded("categories_list", MultiJson.dump(CategoryListSerializer.new(@list, scope: guardian))) respond_to do |format| format.html { render } diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index e6e30a54c14..927519cb493 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -60,7 +60,6 @@ class ListController < ApplicationController list_opts[:no_definitions] = true end - list = TopicQuery.new(user, list_opts).public_send("list_#{filter}") list.more_topics_url = construct_url_with(:next, list_opts) list.prev_topics_url = construct_url_with(:prev, list_opts) @@ -69,7 +68,7 @@ class ListController < ApplicationController @rss = filter # Note the first is the default and we don't add a title - if idx > 0 && use_crawler_layout? + if (filter.to_s != current_homepage) && use_crawler_layout? filter_title = I18n.t("js.filters.#{filter.to_s}.title") if list_opts[:category] @title = I18n.t('js.filters.with_category', filter: filter_title, category: Category.find(list_opts[:category]).name) diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index 142bc7d0abc..f3ef3b7d6a0 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -23,4 +23,4 @@ <% end %> -<% content_for :title do %><%= I18n.t('js.filters.categories.title') %><% end %> +<% content_for :title do %><%= @title %><% end %>