mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
Merge pull request #4361 from jekyll/pheuko-empty-permalink
Merge pull request 4361
This commit is contained in:
@@ -42,6 +42,8 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing.
|
||||
def read_yaml(base, name, opts = {})
|
||||
filename = File.join(base, name)
|
||||
|
||||
begin
|
||||
self.content = File.read(site.in_source_dir(base, name),
|
||||
merged_file_read_opts(opts))
|
||||
@@ -50,20 +52,31 @@ module Jekyll
|
||||
self.data = SafeYAML.load(Regexp.last_match(1))
|
||||
end
|
||||
rescue SyntaxError => e
|
||||
Jekyll.logger.warn "YAML Exception reading #{File.join(base, name)}: #{e.message}"
|
||||
Jekyll.logger.warn "YAML Exception reading #{filename}: #{e.message}"
|
||||
rescue Exception => e
|
||||
Jekyll.logger.warn "Error reading file #{File.join(base, name)}: #{e.message}"
|
||||
Jekyll.logger.warn "Error reading file #{filename}: #{e.message}"
|
||||
end
|
||||
|
||||
self.data ||= {}
|
||||
|
||||
unless self.data.is_a?(Hash)
|
||||
Jekyll.logger.abort_with "Fatal:", "Invalid YAML front matter in #{File.join(base, name)}"
|
||||
end
|
||||
validate_data! filename
|
||||
validate_permalink! filename
|
||||
|
||||
self.data
|
||||
end
|
||||
|
||||
def validate_data!(filename)
|
||||
unless self.data.is_a?(Hash)
|
||||
raise Errors::InvalidYAMLFrontMatterError, "Invalid YAML front matter in #{filename}"
|
||||
end
|
||||
end
|
||||
|
||||
def validate_permalink!(filename)
|
||||
if self.data['permalink'] && self.data['permalink'].size == 0
|
||||
raise Errors::InvalidPermalinkError, "Invalid permalink in #{filename}"
|
||||
end
|
||||
end
|
||||
|
||||
# Transform the contents based on the content type.
|
||||
#
|
||||
# Returns the transformed contents.
|
||||
|
||||
@@ -2,7 +2,9 @@ module Jekyll
|
||||
module Errors
|
||||
FatalException = Class.new(::RuntimeError)
|
||||
|
||||
MissingDependencyException = Class.new(FatalException)
|
||||
DropMutationException = Class.new(FatalException)
|
||||
DropMutationException = Class.new(FatalException)
|
||||
InvalidPermalinkError = Class.new(FatalException)
|
||||
InvalidYAMLFrontMatterError = Class.new(FatalException)
|
||||
MissingDependencyException = Class.new(FatalException)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user