Sha256: 919061a2fed0eb1c44a5c1ee84ca8a0c9f27266172fd02a4b00ea68b4a1c810c
Contents?: true
Size: 1.22 KB
Versions: 7
Compression:
Stored size: 1.22 KB
Contents
require "addressable/uri" module Jekyll module Filters module URLFilters # Produces an absolute URL based on site.url and site.baseurl. # # input - the URL to make absolute. # # Returns the absolute URL as a String. def absolute_url(input) return if input.nil? site = @context.registers[:site] return relative_url(input).to_s if site.config["url"].nil? Addressable::URI.parse(site.config["url"] + relative_url(input)).normalize.to_s end # 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. def relative_url(input) return if input.nil? site = @context.registers[:site] return ensure_leading_slash(input.to_s) if site.config["baseurl"].nil? Addressable::URI.parse( ensure_leading_slash(site.config["baseurl"]) + ensure_leading_slash(input.to_s) ).normalize.to_s end private def ensure_leading_slash(input) return input if input.nil? || input.empty? || input.start_with?("/") "/#{input}" end end end end
Version data entries
7 entries across 7 versions & 1 rubygems