FIX: static page title should be consistent on client side and server side

FIX: static page title should be consistent on client side and server side

From bdb1268528eec66a450b6e52184a5854ccd6c804 Mon Sep 17 00:00:00 2001
From: Arpit Jalan <arpit@techapj.com>
Date: Tue, 27 Nov 2018 21:49:59 +0530
Subject: [PATCH] FIX: static page title should be consistent on client side
 and server side


diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb
index a95cedf..3408239 100644
--- a/app/controllers/about_controller.rb
+++ b/app/controllers/about_controller.rb
@@ -10,6 +10,7 @@ class AboutController < ApplicationController
     return redirect_to path('/login') if SiteSetting.login_required? && current_user.nil?
 
     @about = About.new
+    @title = "#{I18n.t("js.about.simple_title")} - #{SiteSetting.title}"
     respond_to do |format|
       format.html do
         render :index
diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb
index c6252df..43b4a85 100644
--- a/app/controllers/static_controller.rb
+++ b/app/controllers/static_controller.rb
@@ -39,7 +39,12 @@ class StaticController < ApplicationController
     if map.has_key?(@page)
       @topic = Topic.find_by_id(SiteSetting.send(map[@page][:topic_id]))
       raise Discourse::NotFound unless @topic
-      @title = "#{@topic.title} - #{SiteSetting.title}"
+      title_prefix = if I18n.exists?("js.#{@page}")
+        I18n.t("js.#{@page}")
+      else
+        @topic.title
+      end
+      @title = "#{title_prefix} - #{SiteSetting.title}"
       @body = @topic.posts.first.cooked
       @faq_overriden = !SiteSetting.faq_url.blank?
       render :show, layout: !request.xhr?, formats: [:html]
diff --git a/app/views/about/index.html.erb b/app/views/about/index.html.erb
index 563a960..e27fb7e 100644
--- a/app/views/about/index.html.erb
+++ b/app/views/about/index.html.erb
@@ -105,6 +105,13 @@
 
 <% end %>
 
-<% content_for :head do %>
-  <%= raw crawlable_meta_data(title: SiteSetting.title, description: SiteSetting.site_description) %>
+<% 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 %>

GitHub

1 Like

@techAPJ

Look at the meta in the Google User Agent. Double repeat title. About - Discourse Meta

I am not seeing this on latest Chrome on Windows 10.

@Toxu-ru which browser (version) and OS you are on?

Watch from User-Agent: Google. In normal mode, everything is fine, but any search engine will see 2 title.

1 Like

We should add a test case for this.

Thanks for detailed feedback @Toxu-ru.

Fixed in (with spec): FIX: title was repeating on about page · discourse/discourse@654d799 · GitHub

2 Likes