guard against invalid or missing URLs

This commit is contained in:
Ben Balter 2017-04-26 12:48:08 -04:00
parent d00191c1e3
commit 13bc107b3f
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
1 changed files with 7 additions and 1 deletions

View File

@ -162,6 +162,7 @@ module Jekyll
image = { "path" => image } if image.is_a?(String)
image["path"] ||= image["facebook"] || image["twitter"]
return @image = nil unless image["path"]
unless absolute_url? image["path"]
image["path"] = filters.absolute_url image["path"]
@ -177,7 +178,9 @@ module Jekyll
end
def canonical_url
@canonical_url ||= filters.absolute_url(page["url"]).gsub(%r!/index\.html$!, "/")
@canonical_url ||= begin
filters.absolute_url(page["url"]).to_s.gsub(%r!/index\.html$!, "/")
end
end
private
@ -205,7 +208,10 @@ module Jekyll
end
def absolute_url?(string)
return unless string
Addressable::URI.parse(string).absolute?
rescue Addressable::URI::InvalidURIError
nil
end
def format_string(string)