1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

Serve extensionless files or dotfiles with text/plain MIME type, and remove Sitemap::Resource#mime_type.

This commit is contained in:
Ben Hollis 2013-01-17 19:40:23 -08:00
parent cad7f8a0a4
commit 16b3a729cd
2 changed files with 3 additions and 8 deletions

View file

@ -251,7 +251,7 @@ module Middleman
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
content_type(res, resource.mime_type) content_type(res, mime_type(resource.ext))
begin begin
# Write out the contents of the page # Write out the contents of the page
@ -280,6 +280,7 @@ module Middleman
# @return [void] # @return [void]
def mime_type(type, value=nil) def mime_type(type, value=nil)
return type if type.nil? || type.to_s.include?('/') return type if type.nil? || type.to_s.include?('/')
return ::Rack::Mime.mime_type('.txt') if type.empty?
type = ".#{type}" unless type.to_s[0] == ?. type = ".#{type}" unless type.to_s[0] == ?.
return ::Rack::Mime.mime_type(type, nil) unless value return ::Rack::Mime.mime_type(type, nil) unless value
::Rack::Mime::MIME_TYPES[type] = value ::Rack::Mime::MIME_TYPES[type] = value
@ -314,7 +315,7 @@ module Middleman
# @param [Hash] params # @param [Hash] params
# @return [void] # @return [void]
def content_type(res, type, params={}) def content_type(res, type, params={})
return res['Content-Type'] unless type return unless type
default = params.delete :default default = params.delete :default
mime_type = mime_type(type) || default mime_type = mime_type(type) || default
throw "Unknown media type: %p" % type if mime_type.nil? throw "Unknown media type: %p" % type if mime_type.nil?

View file

@ -102,12 +102,6 @@ module Middleman
File.extname(path) File.extname(path)
end end
# Mime type of the path
# @return [String]
def mime_type
app.mime_type ext
end
# Render this resource # Render this resource
# @return [String] # @return [String]
def render(opts={}, locs={}, &block) def render(opts={}, locs={}, &block)