Don't look for frontmatter on binary files. Fixes #728
This commit is contained in:
parent
7231f9dfe2
commit
a76b02a55b
3 changed files with 29 additions and 15 deletions
|
@ -130,23 +130,27 @@ module Middleman::CoreExtensions
|
|||
# @return [Array<Thor::CoreExt::HashWithIndifferentAccess, String>]
|
||||
def frontmatter_and_content(path)
|
||||
full_path = File.expand_path(File.join(@app.source_dir, path))
|
||||
content = File.read(full_path)
|
||||
data = {}
|
||||
content = nil
|
||||
|
||||
begin
|
||||
if content =~ /\A.*coding:/
|
||||
lines = content.split(/\n/)
|
||||
lines.shift
|
||||
content = lines.join("\n")
|
||||
end
|
||||
if !::Middleman::Util.binary?(full_path)
|
||||
content = File.read(full_path)
|
||||
|
||||
begin
|
||||
if content =~ /\A.*coding:/
|
||||
lines = content.split(/\n/)
|
||||
lines.shift
|
||||
content = lines.join("\n")
|
||||
end
|
||||
|
||||
if result = parse_yaml_front_matter(content)
|
||||
data, content = result
|
||||
elsif result = parse_json_front_matter(content)
|
||||
data, content = result
|
||||
if result = parse_yaml_front_matter(content)
|
||||
data, content = result
|
||||
elsif result = parse_json_front_matter(content)
|
||||
data, content = result
|
||||
end
|
||||
rescue => e
|
||||
# Probably a binary file, move on
|
||||
end
|
||||
rescue => e
|
||||
# Probably a binary file, move on
|
||||
end
|
||||
|
||||
[data, content]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue