Module: URLFilters

Defined in:
lib/scribo/liquid/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.



9
10
11
12
# File 'lib/scribo/liquid/filters/url_filters.rb', line 9

def absolute_url(input)
  cache = (@context.registers[:cached_absolute_urls] ||= {})
  cache[input] ||= compute_absolute_url(input)
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.



20
21
22
23
# File 'lib/scribo/liquid/filters/url_filters.rb', line 20

def relative_url(input)
  cache = (@context.registers[:cached_relative_urls] ||= {})
  cache[input] ||= compute_relative_url(input)
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



30
31
32
33
34
# File 'lib/scribo/liquid/filters/url_filters.rb', line 30

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

  input.sub(%r[/index\.html?$], '/')
end