Skip to content

Commit

Permalink
Removes links to crawlers (#678)
Browse files Browse the repository at this point in the history
* crawlers

* testing

* added test

* Rubocop nitpicking

---------

Co-authored-by: Hector Correa <[email protected]>
  • Loading branch information
claudiawulee and hectorcorrea authored Sep 11, 2024
1 parent 7901b6f commit 6d49001
Show file tree
Hide file tree
Showing 6 changed files with 4,969 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ gem 'turbolinks', '~> 5'
gem 'twitter-typeahead-rails', '0.11.1.pre.corejavascript'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
gem 'vite_rails'
gem 'voight_kampff', require: 'voight_kampff/rails'
gem 'whenever'

group :development, :test do
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ GEM
dry-cli (>= 0.7, < 2)
rack-proxy (~> 0.6, >= 0.6.1)
zeitwerk (~> 2.2)
voight_kampff (2.0.0)
rack (>= 1.4)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1)
Expand Down Expand Up @@ -647,6 +649,7 @@ DEPENDENCIES
twitter-typeahead-rails (= 0.11.1.pre.corejavascript)
tzinfo-data
vite_rails
voight_kampff
web-console (>= 4.1.0)
webmock
whenever
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,17 @@ def retry_on_exception
:doi, :ark, :id,
:a # this is in the search parameters becuase the search bar is shown on the error page
]

# Sets up Blacklight crawler detection
config.crawler_detector = lambda { |request|
return true if request.env['HTTP_USER_AGENT'].blank?
request.bot?
}
end

def show
super()
@render_links = !agent_is_crawler?
super
if params["format"] == "json"
render json: DocumentExport.new(@document)
end
Expand Down
6 changes: 5 additions & 1 deletion app/views/catalog/_show_documents.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
<td>
<span>
<i class="bi bi-file-arrow-down"></i>
<a href="<%= file.download_url %>" class="documents-file-link" target="_blank" title="<%= file.full_path %>"><%= truncate(file.full_path, length: 60) %></a>
<% if @render_links%>
<a href="<%= file.download_url %>" class="documents-file-link" target="_blank" title="<%= file.full_path %>"><%= truncate(file.full_path, length: 60) %></a>
<% else %>
<%= truncate(file.full_path, length: 60) %>
<% end %>
</span>
</td>
<% if @document.data_source == "dataspace" %>
Expand Down
Loading

0 comments on commit 6d49001

Please sign in to comment.