Directory indexes work completely now, in preview and with dotfiles.

This commit is contained in:
Ben Hollis 2012-02-03 00:14:49 -08:00
parent ca1f3ddf83
commit e27e0cdd44
4 changed files with 26 additions and 28 deletions

View file

@ -494,4 +494,4 @@ protected
end
res['Content-Type'] = mime_type
end
end
end

View file

@ -101,13 +101,14 @@ module Middleman::Cli
# @return [void]
def tilt_template(page)
build_dir = self.class.shared_instance.build_dir
output_file = File.join(self.class.shared_instance.build_dir, page.output_file_path)
output_file = File.join(self.class.shared_instance.build_dir, page.destination_path)
begin
response = self.class.shared_rack.get(page.request_path.gsub(/\s/, "%20"))
create_file(output_file, response.body, { :force => true })
rescue
say_status :error, destination, :red
say_status :error, output_file, :red
puts $!
abort
end
end
@ -201,6 +202,8 @@ module Middleman::Cli
# Sort paths to be built by the above order. This is primarily so Compass can
# find files in the build folder when it needs to generate sprites for the
# css files
# TODO: deal with pages, not paths
paths = @app.sitemap.all_paths.sort do |a, b|
a_ext = File.extname(a)
b_ext = File.extname(b)
@ -213,28 +216,15 @@ module Middleman::Cli
# Loop over all the paths and build them.
paths.each do |path|
puts "SOURCE: #{path}"
page = @app.sitemap.page(path)
file_source = path
# TODO: OMG use pathnames?
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
file_destination.gsub!('/./', '/')
if @app.sitemap.proxied?(file_source)
file_source = @app.sitemap.page(file_source).proxied_to
elsif @app.sitemap.page(file_source).ignored?
next
end
page = @app.sitemap.page(file_source)
puts "DEST: #{page.destination_path}"
next if @config[:glob] && !File.fnmatch(@config[:glob], file_source)
next if page.ignored?
next if @config[:glob] && !File.fnmatch(@config[:glob], path)
base.tilt_template(page)
@cleaning_queue.delete(Pathname.new(page.destination_path).realpath) if cleaning?
output_path = File.join(@destination, page.destination_path)
@cleaning_queue.delete(Pathname.new(output_path).realpath) if cleaning?
end
end
end

View file

@ -12,14 +12,15 @@ module Middleman::Extensions
# Include methods
app.send :include, InstanceMethods
# TODO: unify these
# TODO: unify these by replacing the "before" thing with a
# lookup by destination_path
# Before requests
app.before do
prefix = @original_path.sub(/\/$/, "")
indexed_path = prefix + "/" + index_file
extensioned_path = prefix + File.extname(index_file)
is_ignored = false
fm_ignored = false
@ -36,13 +37,15 @@ module Middleman::Extensions
end
else
# Otherwise check this extension for list of ignored indexes
is_ignored = ignored_directory_indexes.include?(extensioned_path)
if sitemap.exists?(extensioned_path)
is_ignored = ignored_directory_indexes.include?(sitemap.page(extensioned_path))
end
end
# If we're going to remap to a directory index
if !sitemap.exists?(indexed_path) && !is_ignored && !fm_ignored
parts = @original_path.split("/")
last_part = parts.last
last_part = parts.last || ''
last_part_ext = File.extname(last_part)
# Change the request
@ -65,16 +68,19 @@ module Middleman::Extensions
frontmatter_ignore = d.has_key?("directory_index") && d["directory_index"] == false
end
index_ext = File.extname(index_file)
# Only reroute if not ignored
request_path = page.request_path
if ignored_directory_indexes.include? page
destination
elsif request_path.end_with? new_index_path
elsif request_path == index_file || request_path.end_with?(new_index_path)
destination
elsif frontmatter_ignore
destination
elsif index_ext != File.extname(request_path)
destination
else
index_ext = File.extname(index_file)
destination.chomp(File.extname(index_file)) + new_index_path
end
end

View file

@ -103,7 +103,9 @@ module Middleman::Sitemap
return true if @ignored_globs.any? { |g| File.fnmatch(g, path_clean) }
return true if @ignored_regexes.any? { |r| r.match(path_clean) }
return true if @ignored_callbacks.any? { |b| b.call(path_clean) }
# TODO: We should also check ignored_sitemap_matchers here
false
end