Empty permalink now shows an error

This commit is contained in:
Pedro Euko 2015-09-28 13:58:50 -03:00
parent 9368e261cc
commit f8a63157d7
3 changed files with 26 additions and 0 deletions

View File

@ -61,6 +61,10 @@ module Jekyll
Jekyll.logger.abort_with "Fatal:", "Invalid YAML front matter in #{File.join(base, name)}"
end
unless valid_permalink?(self.data['permalink'])
Jekyll.logger.error "Error:", "Invalid permalink in #{File.join(base, name)}"
end
self.data
end
@ -266,6 +270,15 @@ module Jekyll
Jekyll::Hooks.trigger hook_owner, :post_render, self
end
# Check data permalink
#
# permalink - the data permalink
#
# Returns true if the permalink is valid, false if otherwise
def valid_permalink?(permalink)
permalink.nil? || permalink.length > 0
end
# Write the generated page file to the destination directory.
#
# dest - The String path to the destination dir.

4
test/fixtures/empty_permalink.erb vendored Normal file
View File

@ -0,0 +1,4 @@
---
permalink: ''
---
Empty Permalink

View File

@ -49,5 +49,14 @@ class TestConvertible < JekyllUnitTest
assert_match(/invalid byte sequence in UTF-8/, out)
assert_match(/#{File.join(@base, name)}/, out)
end
should "parse the front-matter but show an error if permalink is empty" do
name = 'empty_permalink.erb'
out = capture_stderr do
@convertible.read_yaml(@base, name)
end
assert_match(/Invalid permalink/, out)
assert_match(/#{File.join(@base, name)}/, out)
end
end
end