Module: JekyllFileProtocol::Jekyll::Filters

Defined in:
lib/jekyll/filters/relative_path.rb

Instance Method Summary collapse

Instance Method Details

#relative_path(input) ⇒ Object



10
11
12
13
14
# File 'lib/jekyll/filters/relative_path.rb', line 10

def relative_path(input)
  return input if input.nil?

  ::JekyllFileProtocol::RelativePathRenderer.new(@context, input).render
end

#relative_tag(input) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jekyll/filters/relative_path.rb', line 16

def relative_tag(input)
  return input if input.nil?

  node   = Nokogiri::HTML.parse(input)
  tags   = nil
  
  # Stylesheet
  if tags = node.css('link').to_a
    return tags.map do |tag|
      tag['href'] = ::JekyllFileProtocol::RelativePathRenderer.new(@context, tag['href']).render
      tag
    end.map(&:to_html)
  end

  # Javascript
  if tags = node.css('script').to_a
    return tags.map do |tag|
      tag['src'] = ::JekyllFileProtocol::RelativePathRenderer.new(@context, tag['src']).render
      tag
    end.map(&:to_html)
  end

  # Image
  if tags = node.css('img').to_a
    return tags.map do |tag|
      tag['src'] = ::JekyllFileProtocol::RelativePathRenderer.new(@context, tag['src']).render
      tag
    end.map(&:to_html)
  end

  input
end