mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Merge pull request #3562 from riking/no-index
Add noindex directive on unlisted topics
This commit is contained in:
commit
65ac5b6475
2 changed files with 19 additions and 0 deletions
|
@ -77,6 +77,10 @@ class TopicsController < ApplicationController
|
||||||
@topic_view.draft = Draft.get(current_user, @topic_view.draft_key, @topic_view.draft_sequence)
|
@topic_view.draft = Draft.get(current_user, @topic_view.draft_key, @topic_view.draft_sequence)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless @topic_view.topic.visible
|
||||||
|
response.headers['X-Robots-Tag'] = 'noindex'
|
||||||
|
end
|
||||||
|
|
||||||
perform_show_response
|
perform_show_response
|
||||||
|
|
||||||
canonical_url UrlHelper.absolute_without_cdn("#{Discourse.base_uri}#{@topic_view.canonical_path}")
|
canonical_url UrlHelper.absolute_without_cdn("#{Discourse.base_uri}#{@topic_view.canonical_path}")
|
||||||
|
|
|
@ -1018,4 +1018,19 @@ describe TopicsController do
|
||||||
expect(json["banner_count"]).to eq(1)
|
expect(json["banner_count"]).to eq(1)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue