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

View file

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

View file

@ -74,7 +74,7 @@ module Middleman::CoreExtensions::Sitemap
# @param [String] url # @param [String] url
# @param [String] target # @param [String] target
# @return [void] # @return [void]
def reroute(*args) def proxy(*args)
sitemap.proxy(*args) sitemap.proxy(*args)
end end

View file

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

View file

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