Module: Jekyll::Filters::URLFilters
- Included in:
- Jekyll::Filters
- Defined in:
- lib/jekyll/filters/url_filters.rb
Instance Method Summary collapse
-
#absolute_url(input) ⇒ Object
Produces an absolute URL based on site.url and site.baseurl.
-
#relative_url(input) ⇒ Object
Produces a URL relative to the domain root based on site.baseurl.
-
#strip_index(input) ⇒ Object
Strips trailing ‘/index.html` from URLs to create pretty permalinks.
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.
13 14 15 16 17 18 19 20 21 |
# File 'lib/jekyll/filters/url_filters.rb', line 13 def absolute_url(input) return if input.nil? return input if Addressable::URI.parse(input.to_s).absolute? site = @context.registers[:site] return relative_url(input) if site.config["url"].nil? Addressable::URI.parse( site.config["url"].to_s + relative_url(input) ).normalize.to_s end |
#relative_url(input) ⇒ Object
Produces a URL relative to the domain root based on site.baseurl.
input - the URL to make relative to the domain root
Returns a URL relative to the domain root as a String.
28 29 30 31 32 33 34 |
# File 'lib/jekyll/filters/url_filters.rb', line 28 def relative_url(input) return if input.nil? parts = [sanitized_baseurl, input] Addressable::URI.parse( parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join ).normalize.to_s 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
41 42 43 44 |
# File 'lib/jekyll/filters/url_filters.rb', line 41 def strip_index(input) return if input.nil? || input.to_s.empty? input.sub(%r!/index\.html?$!, "/") end |