Module: Kitchen::Directions::BakeLinks
- Defined in:
- lib/kitchen/directions/bake_links.rb
Overview
Add attributes to links
Class Method Summary collapse
Class Method Details
.v1(book:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/kitchen/directions/bake_links.rb', line 8 def self.v1(book:) book.search('a').each do |anchor| # Add attributes to links that start with https://, http://, or // # For Rex if anchor&.[](:href)&.match(/^https:\/\/|^http:\/\/|^\/\//) anchor[:target] = '_blank' anchor[:rel] = 'noopener nofollow' elsif anchor&.[](:href)&.match(/^\.\.\//) anchor[:target] = '_blank' anchor.remove_attribute('rel') end end end |