Don't look for frontmatter on binary files. Fixes #728
This commit is contained in:
parent
7231f9dfe2
commit
a76b02a55b
|
@ -130,23 +130,27 @@ module Middleman::CoreExtensions
|
||||||
# @return [Array<Thor::CoreExt::HashWithIndifferentAccess, String>]
|
# @return [Array<Thor::CoreExt::HashWithIndifferentAccess, String>]
|
||||||
def frontmatter_and_content(path)
|
def frontmatter_and_content(path)
|
||||||
full_path = File.expand_path(File.join(@app.source_dir, path))
|
full_path = File.expand_path(File.join(@app.source_dir, path))
|
||||||
content = File.read(full_path)
|
|
||||||
data = {}
|
data = {}
|
||||||
|
content = nil
|
||||||
|
|
||||||
begin
|
if !::Middleman::Util.binary?(full_path)
|
||||||
if content =~ /\A.*coding:/
|
content = File.read(full_path)
|
||||||
lines = content.split(/\n/)
|
|
||||||
lines.shift
|
begin
|
||||||
content = lines.join("\n")
|
if content =~ /\A.*coding:/
|
||||||
end
|
lines = content.split(/\n/)
|
||||||
|
lines.shift
|
||||||
|
content = lines.join("\n")
|
||||||
|
end
|
||||||
|
|
||||||
if result = parse_yaml_front_matter(content)
|
if result = parse_yaml_front_matter(content)
|
||||||
data, content = result
|
data, content = result
|
||||||
elsif result = parse_json_front_matter(content)
|
elsif result = parse_json_front_matter(content)
|
||||||
data, content = result
|
data, content = result
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
# Probably a binary file, move on
|
||||||
end
|
end
|
||||||
rescue => e
|
|
||||||
# Probably a binary file, move on
|
|
||||||
end
|
end
|
||||||
|
|
||||||
[data, content]
|
[data, content]
|
||||||
|
|
|
@ -151,8 +151,7 @@ module Middleman
|
||||||
#
|
#
|
||||||
# @retrun [Boolean]
|
# @retrun [Boolean]
|
||||||
def binary?
|
def binary?
|
||||||
s = (File.read(source_file, File.stat(source_file).blksize) || "").split(//)
|
::Middleman::Util.binary?(source_file)
|
||||||
((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,10 +10,21 @@ require "thor"
|
||||||
# Core Pathname library used for traversal
|
# Core Pathname library used for traversal
|
||||||
require "pathname"
|
require "pathname"
|
||||||
|
|
||||||
|
require 'win32/file' if File::ALT_SEPARATOR
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
|
|
||||||
module Util
|
module Util
|
||||||
|
|
||||||
|
# Whether the source file is binary.
|
||||||
|
#
|
||||||
|
# @param [String] filename The file to check.
|
||||||
|
# @return [Boolean]
|
||||||
|
def self.binary?(filename)
|
||||||
|
s = (File.read(filename, File.stat(filename).blksize) || "").split(//)
|
||||||
|
((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
|
||||||
|
end
|
||||||
|
|
||||||
# The logger
|
# The logger
|
||||||
#
|
#
|
||||||
# @return [Middleman::Logger] The logger
|
# @return [Middleman::Logger] The logger
|
||||||
|
|
Loading…
Reference in a new issue