Merge pull request #3562 from riking/no-index

Add noindex directive on unlisted topics
This commit is contained in:
Sam 2015-06-23 15:50:53 +10:00
commit 65ac5b6475
2 changed files with 19 additions and 0 deletions

View File

@ -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}")

View File

@ -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