From 2f0bd6294c2866889f5d7f741d19009efa64f7ff Mon Sep 17 00:00:00 2001 From: Kane York Date: Mon, 22 Jun 2015 11:00:39 -0700 Subject: [PATCH 1/2] Add noindex directive on unlisted topics --- app/controllers/topics_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 5e42759e723..495d535fd8f 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -77,6 +77,10 @@ class TopicsController < ApplicationController @topic_view.draft = Draft.get(current_user, @topic_view.draft_key, @topic_view.draft_sequence) end + unless @topic_view.topic.visible + response.headers['X-Robots-Tag'] = 'noindex' + end + perform_show_response canonical_url UrlHelper.absolute_without_cdn("#{Discourse.base_uri}#{@topic_view.canonical_path}") From 470d9418fdedeb566c49ee99d8bba9673fe96f13 Mon Sep 17 00:00:00 2001 From: Kane York Date: Mon, 22 Jun 2015 16:02:45 -0700 Subject: [PATCH 2/2] Add tests for X-Robots-Tag --- spec/controllers/topics_controller_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 19281aebe58..72ae0e2ebc2 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -1018,4 +1018,19 @@ describe TopicsController do expect(json["banner_count"]).to eq(1) end end + + describe "x-robots-tag" do + it "is included for unlisted topics" do + topic = Fabricate(:topic, visible: false) + get :show, topic_id: topic.id, slug: topic.slug + + expect(response.headers['X-Robots-Tag']).to eq('noindex') + end + it "is not included for normal topics" do + topic = Fabricate(:topic, visible: true) + get :show, topic_id: topic.id, slug: topic.slug + + expect(response.headers['X-Robots-Tag']).to eq(nil) + end + end end