Created
February 25, 2014 09:05
-
-
Save milushov/9205417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_nofollow_links | |
domains = %w(inmyroom kitchenmag) | |
if content.present? | |
json_content = begin | |
JSON.parse content | |
rescue | |
[] | |
end | |
json_content.each do |plugin| | |
if plugin['name'] == 'text_area' | |
html_with_links = auto_link(plugin['data'], html: {target: '_blank'}) | |
html_with_links.scan(/(\<a href=["'].*?["']\>.*?\<\/a\>)/).flatten.each do |link| | |
node = Nokogiri::HTML::DocumentFragment.parse(link).children.first | |
next if node[:href].match /(#{ domains.join('|') })\.(ru|dev|dev:3000)/ | |
html_with_links.gsub! link, "<a href='#{ node[:href] }' rel='nofollow' target='#{ node[:target] }'>#{ node.content }</a>" | |
end | |
plugin['data'] = html_with_links | |
end | |
end | |
json_content.to_json | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment