filter relative_url should keep absolute urls with scheme/authority (#6490)

Merge pull request 6490
This commit is contained in:
Johannes Müller
2017-11-05 16:17:51 +01:00
committed by jekyllbot
parent beed5513e4
commit a66c4780cc
2 changed files with 19 additions and 1 deletions

View File

@@ -20,13 +20,16 @@ module Jekyll
).normalize.to_s
end
# Produces a URL relative to the domain root based on site.baseurl.
# 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.
def relative_url(input)
return if input.nil?
return input if Addressable::URI.parse(input.to_s).absolute?
parts = [sanitized_baseurl, input]
Addressable::URI.parse(
parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join