From 2cd4e95d820e09b0cb712cbfe5cff0629fa7c0cd Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 8 Jul 2019 11:42:39 +0530 Subject: [PATCH] FIX: show category name in title for crawler view Show category name in title for crawler view despite presence of `short_site_description`. Bug reported here: https://meta.discourse.org/t/short-site-description-break-category-title-for-crawler-or-its-the-expected-behavior/122109/ --- app/controllers/list_controller.rb | 2 +- spec/requests/list_controller_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index b835366350..55c922794c 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -109,7 +109,7 @@ class ListController < ApplicationController @title = I18n.t('js.filters.with_topics', filter: filter_title) end @title << " - #{SiteSetting.title}" - elsif (filter.to_s == current_homepage) && SiteSetting.short_site_description.present? + elsif @category.blank? && (filter.to_s == current_homepage) && SiteSetting.short_site_description.present? @title = "#{SiteSetting.title} - #{SiteSetting.short_site_description}" end end diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rb index 587c6807d0..27ced58f4f 100644 --- a/spec/requests/list_controller_spec.rb +++ b/spec/requests/list_controller_spec.rb @@ -463,6 +463,23 @@ RSpec.describe ListController do expect(css_select("link[rel=canonical]").length).to eq(1) end end + + context "renders correct title" do + let!(:amazing_category) { Fabricate(:category, name: "Amazing Category") } + + it 'for category default view' do + get "/c/#{amazing_category.slug}" + + expect(response.body).to have_tag "title", text: "Amazing Category - Discourse" + end + + it 'for category latest view' do + SiteSetting.short_site_description = "Best community" + get "/c/#{amazing_category.slug}/l/latest" + + expect(response.body).to have_tag "title", text: "Amazing Category - Discourse" + end + end end end