Module: Jekyll::Filters::URLFilters

Included in:
Jekyll::Filters, Tags::Link, Tags::PostUrl
Defined in:
lib/jekyll/filters/url_filters.rb

Instance Method Summary collapse

Instance Method Details

#absolute_url(input) ⇒ Object

Produces an absolute URL based on site.url and site.baseurl.

input - the URL to make absolute.

Returns the absolute URL as a String.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jekyll/filters/url_filters.rb', line 11

def absolute_url(input)
  return if input.nil?

  cache = if input.is_a?(String)
            (@context.registers[:site].filter_cache[:absolute_url] ||= {})
          else
            (@context.registers[:cached_absolute_url] ||= {})
          end
  cache[input] ||= compute_absolute_url(input)

  # Duplicate cached string so that the cached value is never mutated by
  # a subsequent filter.
  cache[input].dup
end

#relative_url(input) ⇒ Object

Produces a URL relative to the domain root based on site.baseurl unless it is already an absolute url with an authority (host).

input - the URL to make relative to the domain root

Returns a URL relative to the domain root as a String.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jekyll/filters/url_filters.rb', line 32

def relative_url(input)
  return if input.nil?

  cache = if input.is_a?(String)
            (@context.registers[:site].filter_cache[:relative_url] ||= {})
          else
            (@context.registers[:cached_relative_url] ||= {})
          end
  cache[input] ||= compute_relative_url(input)

  # Duplicate cached string so that the cached value is never mutated by
  # a subsequent filter.
  cache[input].dup
end

#strip_index(input) ⇒ Object

Strips trailing `/index.html` from URLs to create pretty permalinks

input - the URL with a possible `/index.html`

Returns a URL with the trailing `/index.html` removed


52
53
54
55
56
# File 'lib/jekyll/filters/url_filters.rb', line 52

def strip_index(input)
  return if input.nil? || input.to_s.empty?

  input.sub(%r!/index\.html?$!, "/")
end