Skip to content

Commit 1cc4cfb

Browse files
committed
robots and noindex nofollow META tags on search actions (DLC-1164)
1 parent 2cdf345 commit 1cc4cfb

9 files changed

+47
-1
lines changed

app/controllers/application_controller.rb

+16
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,20 @@ def on_page_not_found
103103
def has_search_parameters?
104104
false
105105
end
106+
107+
def meta_nofollow
108+
@meta_nofollow
109+
end
110+
111+
def meta_nofollow!
112+
@meta_nofollow = true
113+
end
114+
115+
def meta_noindex
116+
@meta_noindex
117+
end
118+
119+
def meta_noindex!
120+
@meta_noindex = true
121+
end
106122
end

app/controllers/browse_controller.rb

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class BrowseController < ApplicationController
77
controller.subsite_layout
88
}
99

10+
before_action :meta_nofollow!, only: [:list]
11+
before_action :meta_noindex!, only: [:list]
12+
1013
def initialize(*args)
1114
super(*args)
1215
# _prefixes are where view path lookups are attempted; probably unnecessary

app/controllers/repositories/catalog_controller.rb

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class CatalogController < Sites::SearchController
55

66
before_action :set_map_data_json, only: [:map_search]
77

8+
before_action :meta_nofollow!, only: [:index, :map_search]
9+
before_action :meta_noindex!, only: [:index, :map_search]
10+
811
delegate :blacklight_config, to: :@subsite
912

1013
def initialize(*args)

app/controllers/sites/search_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class SearchController < ApplicationController
1717
before_action :store_unless_user, except: [:update, :destroy, :api_info]
1818
before_action :redirect_unless_local, only: :index
1919
before_action :authorize_document, only: :show
20+
before_action :meta_nofollow!, only: [:index, :map_search]
21+
before_action :meta_noindex!, only: [:index, :map_search]
2022

2123
delegate :blacklight_config, to: :@subsite
2224

app/controllers/subsites_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class SubsitesController < ApplicationController
1616
before_action :default_search_mode_cookie, only: :index
1717
before_action :load_subsite, except: [:home, :page]
1818
before_action :load_page, only: [:home, :index, :page]
19+
before_action :meta_nofollow!, only: [:index, :map_search]
20+
before_action :meta_noindex!, only: [:index, :map_search]
1921
protect_from_forgery :except => [:update, :destroy, :api_info] # No CSRF token required for publishing actions
2022

2123
helper_method :extract_map_data_from_document_list

app/views/shared/_head_includes.html.erb

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
<meta name="viewport" content="width=device-width,initial-scale=1.0">
66

77
<% # Do not index search result pages %>
8-
<% if query_has_constraints? || (params[:q] && params[:search_field]) %>
8+
<% if controller.meta_noindex %>
99
<meta name="robots" content="noindex" />
1010
<% end %>
11+
<% if controller.meta_nofollow %>
12+
<meta name="robots" content="nofollow" />
13+
<% end %>
1114
1215
<!--
1316
DLC VERSION: <%= IO.read(Rails.root.to_s+'/VERSION') %> -->

spec/controllers/browse_controller_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
expect(response.status).to eq(200)
5353
expect(response.body).to include("#{format_link} (#{test_format_count})")
5454
end
55+
it "has robots meta flag attributes" do
56+
get :list, params: { list_id: 'formats' }
57+
expect(controller.instance_variable_get(:@meta_noindex)).to be true
58+
expect(controller.instance_variable_get(:@meta_nofollow)).to be true
59+
end
5560
end
5661
end
5762

spec/controllers/repositories/catalog_controller_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@
2828
expect(response.status).to eq(200)
2929
expect(controller.load_subsite.palette).to eql 'monochrome'
3030
end
31+
it "has robots meta flag attributes" do
32+
get :index, params: { repository_id: 'NNC-RB' }
33+
expect(controller.instance_variable_get(:@meta_nofollow)).to be true
34+
expect(controller.instance_variable_get(:@meta_noindex)).to be true
35+
end
3136
end
3237
end

spec/features/catalog_controller_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
expect(page).to have_text('Perform a search')
1111
end
1212

13+
it "has robots meta tags" do
14+
# <meta name="robots" content="nofollow">
15+
# <meta name="robots" content="noindex">
16+
expect(page).to have_xpath("/descendant::meta[@name='robots' and @content='nofollow']")
17+
expect(page).to have_xpath("/descendant::meta[@name='robots' and @content='noindex']")
18+
end
19+
1320
it "shows concepts when performing a search with a relevant query" do
1421
find(:xpath, '//nav[@id="site-banner"]//input[@id="q"]').set('Internal')
1522
find(:xpath, '//nav[@id="site-banner"]//button[@type="submit"]').click

0 commit comments

Comments
 (0)