This commit is contained in:
parent
6253c91610
commit
fbb2a355d7
|
@ -1,6 +1,8 @@
|
||||||
Master
|
Master
|
||||||
===
|
===
|
||||||
|
|
||||||
|
* Directly send binary files in preview and copy them in build, avoiding reading large binary files into memory for rendering. #643 #699
|
||||||
|
|
||||||
3.0.7
|
3.0.7
|
||||||
====
|
====
|
||||||
* Turn html5 boilerplate into a layout
|
* Turn html5 boilerplate into a layout
|
||||||
|
|
|
@ -117,6 +117,9 @@ module Middleman::Cli
|
||||||
build_dir = self.class.shared_instance.config[:build_dir]
|
build_dir = self.class.shared_instance.config[:build_dir]
|
||||||
output_file = File.join(build_dir, resource.destination_path)
|
output_file = File.join(build_dir, resource.destination_path)
|
||||||
|
|
||||||
|
if resource.binary?
|
||||||
|
copy_file(resource.source_file, output_file)
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
response = self.class.shared_rack.get(URI.escape(resource.destination_path))
|
response = self.class.shared_rack.get(URI.escape(resource.destination_path))
|
||||||
|
|
||||||
|
@ -128,6 +131,7 @@ module Middleman::Cli
|
||||||
rescue => e
|
rescue => e
|
||||||
handle_error(output_file, "#{e}\n#{e.backtrace.join("\n")}", e)
|
handle_error(output_file, "#{e}\n#{e.backtrace.join("\n")}", e)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
output_file
|
output_file
|
||||||
end
|
end
|
||||||
|
|
|
@ -245,6 +245,9 @@ module Middleman
|
||||||
# Return 404 if not in sitemap
|
# Return 404 if not in sitemap
|
||||||
return not_found(res, request_path) unless resource && !resource.ignored?
|
return not_found(res, request_path) unless resource && !resource.ignored?
|
||||||
|
|
||||||
|
# If this path is a binary file, send it immediately
|
||||||
|
return send_file(resource.source_file, env, res) if resource.binary?
|
||||||
|
|
||||||
current_path = resource.destination_path
|
current_path = resource.destination_path
|
||||||
|
|
||||||
# Set a HTTP content type based on the request's extensions
|
# Set a HTTP content type based on the request's extensions
|
||||||
|
|
|
@ -146,6 +146,14 @@ module Middleman
|
||||||
end
|
end
|
||||||
File.join(app.respond_to?(:http_prefix) ? app.http_prefix : '/', url_path)
|
File.join(app.respond_to?(:http_prefix) ? app.http_prefix : '/', url_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Whether the source file is binary.
|
||||||
|
#
|
||||||
|
# @retrun [Boolean]
|
||||||
|
def binary?
|
||||||
|
s = (File.read(source_file, File.stat(source_file).blksize) || "").split(//)
|
||||||
|
((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue