check for the urldrop key first
This commit is contained in:
parent
2d35364c02
commit
e92dd2055d
|
|
@ -78,6 +78,11 @@ module Jekyll
|
||||||
def y_day
|
def y_day
|
||||||
@obj.date.strftime("%j")
|
@obj.date.strftime("%j")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def fallback_data
|
||||||
|
{}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -86,15 +86,14 @@ module Jekyll
|
||||||
|
|
||||||
def generate_url_from_drop(template)
|
def generate_url_from_drop(template)
|
||||||
template.gsub(%r!:([a-z_]+)!) do |match|
|
template.gsub(%r!:([a-z_]+)!) do |match|
|
||||||
begin
|
key = match.sub(":".freeze, "".freeze)
|
||||||
replacement = @placeholders.public_send(match.sub(":".freeze, "".freeze))
|
unless @placeholders.key?(key)
|
||||||
rescue NoMethodError
|
raise NoMethodError, "The URL template key #{key} doesn't exist!"
|
||||||
Jekyll.logger.warn "", "#{match} is not defined!"
|
|
||||||
end
|
end
|
||||||
if replacement.nil?
|
if @placeholders[key].nil?
|
||||||
"".freeze
|
"".freeze
|
||||||
else
|
else
|
||||||
self.class.escape_path(replacement)
|
self.class.escape_path(@placeholders[key])
|
||||||
end
|
end
|
||||||
end.gsub(%r!//!, "/".freeze)
|
end.gsub(%r!//!, "/".freeze)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -93,11 +93,12 @@ class TestURL < JekyllUnitTest
|
||||||
matching_doc = site.collections["methods"].docs.find do |doc|
|
matching_doc = site.collections["methods"].docs.find do |doc|
|
||||||
doc.relative_path == "_methods/escape-+ #%20[].md"
|
doc.relative_path == "_methods/escape-+ #%20[].md"
|
||||||
end
|
end
|
||||||
|
assert_raises NoMethodError do
|
||||||
URL.new(
|
URL.new(
|
||||||
:template => "/methods/:title/:headline",
|
:template => "/methods/:headline",
|
||||||
:placeholders => matching_doc.url_placeholders
|
:placeholders => matching_doc.url_placeholders
|
||||||
).to_s
|
).to_s
|
||||||
pass
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue