Directory indexes now work during build, with the exception of .htaccess files.

This commit is contained in:
Ben Hollis 2012-02-02 21:47:54 -08:00
parent 4ce6913baf
commit ca1f3ddf83
5 changed files with 34 additions and 31 deletions

View file

@ -101,10 +101,10 @@ 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)
begin
response = self.class.shared_rack.get(page.request_path.gsub(/\s/, "%20"))
output_file = File.join(self.class.shared_instance.build_dir, page.destination_path)
create_file(output_file, response.body, { :force => true })
rescue
say_status :error, destination, :red
@ -228,6 +228,8 @@ module Middleman::Cli
page = @app.sitemap.page(file_source)
puts "DEST: #{page.destination_path}"
next if @config[:glob] && !File.fnmatch(@config[:glob], file_source)
base.tilt_template(page)

View file

@ -64,7 +64,7 @@ module Middleman::CoreExtensions::Routing
# Setup proxy
if opts.has_key?(:proxy)
reroute(url, opts[:proxy])
proxy(url, opts[:proxy])
if opts.has_key?(:ignore) && opts[:ignore]
ignore(opts[:proxy])
@ -89,4 +89,4 @@ module Middleman::CoreExtensions::Routing
end
end
end
end
end

View file

@ -74,10 +74,10 @@ module Middleman::CoreExtensions::Sitemap
# @param [String] url
# @param [String] target
# @return [void]
def reroute(*args)
def proxy(*args)
sitemap.proxy(*args)
end
# Register a handler to provide metadata on a file path
# @param [Regexp] matcher
# @return [Array<Array<Proc, Regexp>>]
@ -96,4 +96,4 @@ module Middleman::CoreExtensions::Sitemap
@_provides_metadata_for_path
end
end
end
end

View file

@ -12,6 +12,8 @@ module Middleman::Extensions
# Include methods
app.send :include, InstanceMethods
# TODO: unify these
# Before requests
app.before do
prefix = @original_path.sub(/\/$/, "")
@ -51,41 +53,40 @@ module Middleman::Extensions
end
end
# Basically does the same as above, but in build mode
app.build_reroute do |destination, request_path|
index_ext = File.extname(index_file)
new_index_path = "/#{index_file}"
frontmatter_ignore = false
app.after_configuration do
# Basically does the same as above, but in build mode
sitemap.reroute do |destination, page|
new_index_path = "/#{index_file}"
frontmatter_ignore = false
# Check for file and frontmatter
if sitemap.exists?(request_path)
p = sitemap.page(request_path)
d = p.data
if !d.nil?
# Check for file and frontmatter
d = page.data
if !page.data.nil?
frontmatter_ignore = d.has_key?("directory_index") && d["directory_index"] == false
end
end
# Only reroute if not ignored
if ignored_directory_indexes.include?(request_path)
false
elsif request_path =~ /#{new_index_path}$/
false
elsif frontmatter_ignore
false
else
destination.sub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
# 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
destination
elsif frontmatter_ignore
destination
else
index_ext = File.extname(index_file)
destination.chomp(File.extname(index_file)) + new_index_path
end
end
end
end
alias :included :registered
end
# Directory indexes instance methods
module InstanceMethods
# A list of pages which will not use directory indexes
# @return [Array<String>]
# @return [Array<Middleman::Sitemap::Page>]
def ignored_directory_indexes
@_ignored_directory_indexes ||= []
end
@ -97,7 +98,7 @@ module Middleman::Extensions
# @return [void]
def page(url, options={}, &block)
if options.has_key?(:directory_index) && !options["directory_index"]
ignored_directory_indexes << url
ignored_directory_indexes << sitemap.page(url)
else
super
end

View file

@ -193,7 +193,7 @@ module Middleman::Sitemap
# @return [String]
def destination_path
store.reroute_callbacks.inject(self.path) do |destination, callback|
callback.call(destination)
callback.call(destination, self)
end
end