FIX: add 'noindex' header to rss feed responses.
This commit is contained in:
parent
45b37a8bd1
commit
b6765aac4b
|
@ -44,6 +44,7 @@ class ApplicationController < ActionController::Base
|
||||||
after_action :perform_refresh_session
|
after_action :perform_refresh_session
|
||||||
after_action :dont_cache_page
|
after_action :dont_cache_page
|
||||||
after_action :conditionally_allow_site_embedding
|
after_action :conditionally_allow_site_embedding
|
||||||
|
after_action :add_noindex_header, if: -> { is_feed_request? }
|
||||||
|
|
||||||
layout :set_layout
|
layout :set_layout
|
||||||
|
|
||||||
|
@ -801,6 +802,14 @@ class ApplicationController < ActionController::Base
|
||||||
request.env['DISCOURSE_IS_ASSET_PATH'] = 1
|
request.env['DISCOURSE_IS_ASSET_PATH'] = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_feed_request?
|
||||||
|
request.format.atom? || request.format.rss?
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_noindex_header
|
||||||
|
response.headers['X-Robots-Tag'] = 'noindex'
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def render_post_json(post, add_raw: true)
|
def render_post_json(post, add_raw: true)
|
||||||
|
|
|
@ -47,6 +47,8 @@ class UsersController < ApplicationController
|
||||||
:admin_login,
|
:admin_login,
|
||||||
:confirm_admin]
|
:confirm_admin]
|
||||||
|
|
||||||
|
after_action :add_noindex_header, only: [:show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -73,8 +75,6 @@ class UsersController < ApplicationController
|
||||||
track_visit_to_user_profile
|
track_visit_to_user_profile
|
||||||
end
|
end
|
||||||
|
|
||||||
response.headers['X-Robots-Tag'] = 'noindex'
|
|
||||||
|
|
||||||
# This is a hack to get around a Rails issue where values with periods aren't handled correctly
|
# This is a hack to get around a Rails issue where values with periods aren't handled correctly
|
||||||
# when used as part of a route.
|
# when used as part of a route.
|
||||||
if params[:external_id] && params[:external_id].ends_with?('.json')
|
if params[:external_id] && params[:external_id].ends_with?('.json')
|
||||||
|
|
|
@ -300,6 +300,7 @@ RSpec.describe ListController do
|
||||||
get "/latest.rss"
|
get "/latest.rss"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.media_type).to eq('application/rss+xml')
|
expect(response.media_type).to eq('application/rss+xml')
|
||||||
|
expect(response.headers['X-Robots-Tag']).to eq('noindex')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders links correctly with subfolder' do
|
it 'renders links correctly with subfolder' do
|
||||||
|
|
Loading…
Reference in New Issue