Class: Content::Pipeline::Filters::Links

Inherits:
Content::Pipeline::Filter show all
Defined in:
lib/content/pipeline/filters/links.rb

Constant Summary collapse

HttpRegexp =
/\A(\/\/|http:\/\/)/

Instance Method Summary collapse

Methods inherited from Content::Pipeline::Filter

add_filter, #initialize, #run

Constructor Details

This class inherits a constructor from Content::Pipeline::Filter

Instance Method Details

#external(val) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/content/pipeline/filters/links.rb', line 16

def external(val)
  unless !@opts[:host] || val[:href] =~ \
      %r!https?://#{Regexp.escape(@opts[:host])}(?:\Z|/)!
    val[:target] = "_blank"
  end
val
end

#https(val) ⇒ Object



24
25
26
27
28
29
# File 'lib/content/pipeline/filters/links.rb', line 24

def https(val)
  val[:href] = val[:href].gsub(
    HttpRegexp, "https://"
  )
val
end

#wrapperObject



7
8
9
10
11
12
13
14
# File 'lib/content/pipeline/filters/links.rb', line 7

def wrapper
  @str = @str.to_nokogiri_fragment
  @str.xpath(".//a").each do |v|
    external(https(
      v
    ))
  end
end