Skip to content

Commit

Permalink
Merge pull request #1830 from sul-dlss/1761
Browse files Browse the repository at this point in the history
Add rake task to remediate empty anchors fixes #1761
  • Loading branch information
Jessie Keck authored Mar 4, 2020
2 parents ddc0cbb + bb2521c commit 56606cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
18 changes: 8 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-02-27 21:19:26 -0800 using RuboCop version 0.80.0.
# on 2020-03-04 10:41:06 -0700 using RuboCop version 0.80.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 122

# Offense count: 12
# Offense count: 13
Metrics/AbcSize:
Max: 42

Expand Down Expand Up @@ -56,7 +49,7 @@ RSpec/ExpectInHook:
- 'spec/views/catalog/_exhibits_document_header_default.html.erb_spec.rb'
- 'spec/views/viewers/edit.html.erb_spec.rb'

# Offense count: 113
# Offense count: 114
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 6
Expand Down Expand Up @@ -96,6 +89,11 @@ Style/MixinUsage:
- 'lib/traject/dor_config.rb'
- 'spec/features/viewers_spec.rb'

# Offense count: 1
Style/MultilineBlockChain:
Exclude:
- 'lib/tasks/spotlight.rake'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
Expand Down
14 changes: 14 additions & 0 deletions lib/tasks/spotlight.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,18 @@ namespace :spotlight do
system 'bundle exec rake db:migrate'
end
end
desc 'Remove empty anchors'
task remediate_anchors: :environment do
url_regex = %r{<a href="(https?|mailto:)[\S]+">(<br>)?<\/a>}
Spotlight::Page.find_each.select do |p|
p.content.any? { |c| c.text.to_s.match? url_regex }
end.each do |p|
dup = p.content
p.content.each_with_index do |c, i|
dup[i].text = c.text.to_s.gsub(url_regex, '') if c.text.to_s.match? url_regex
end
p.content = dup
p.save
end
end
end

0 comments on commit 56606cc

Please sign in to comment.