Class: HTML::Pipeline::ExternalLinkFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/html/pipeline/external_link/filter.rb

Instance Method Summary collapse

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/html/pipeline/external_link/filter.rb', line 8

def call
  doc.search("a").each do |anchor|
    next unless anchor["href"]
    href = anchor["href"].strip
    href_host = host_of(href)
    next unless href_host
    if href_host != hostname
      anchor["rel"] = "nofollow noopener"
      anchor["target"] = "_blank"
    end
  end

  doc
end

#validateObject



23
24
25
# File 'lib/html/pipeline/external_link/filter.rb', line 23

def validate
  needs :hostname
end