Skip to content

Instantly share code, notes, and snippets.

@brandonweiss
Created March 31, 2010 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonweiss/351097 to your computer and use it in GitHub Desktop.
Save brandonweiss/351097 to your computer and use it in GitHub Desktop.
# Use Hpricot to add rel="nofollow" to anchor links before output
require 'hpricot'
def add_nofollow(body)
body = Hpricot(body)
a_elements = body.search('a')
unless a_elements.blank?
a_elements.each do |a|
a.attributes['rel'] = 'nofollow'
end
end
body.to_html
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment