From 16b3a729cdd0d345c191c1bd2c9b85df33f9ca4a Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Thu, 17 Jan 2013 19:40:23 -0800 Subject: [PATCH] Serve extensionless files or dotfiles with text/plain MIME type, and remove Sitemap::Resource#mime_type. --- .../lib/middleman-core/core_extensions/request.rb | 5 +++-- middleman-core/lib/middleman-core/sitemap/resource.rb | 6 ------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/middleman-core/lib/middleman-core/core_extensions/request.rb b/middleman-core/lib/middleman-core/core_extensions/request.rb index dd6c7685..a8bc3a36 100644 --- a/middleman-core/lib/middleman-core/core_extensions/request.rb +++ b/middleman-core/lib/middleman-core/core_extensions/request.rb @@ -251,7 +251,7 @@ module Middleman current_path = resource.destination_path # 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 # Write out the contents of the page @@ -280,6 +280,7 @@ module Middleman # @return [void] def mime_type(type, value=nil) 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] == ?. return ::Rack::Mime.mime_type(type, nil) unless value ::Rack::Mime::MIME_TYPES[type] = value @@ -314,7 +315,7 @@ module Middleman # @param [Hash] params # @return [void] def content_type(res, type, params={}) - return res['Content-Type'] unless type + return unless type default = params.delete :default mime_type = mime_type(type) || default throw "Unknown media type: %p" % type if mime_type.nil? diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index 87bb610e..50179b8c 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -102,12 +102,6 @@ module Middleman File.extname(path) end - # Mime type of the path - # @return [String] - def mime_type - app.mime_type ext - end - # Render this resource # @return [String] def render(opts={}, locs={}, &block)