Directory indexes now work during build, with the exception of .htaccess files.
This commit is contained in:
parent
4ce6913baf
commit
ca1f3ddf83
|
@ -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)
|
||||||
|
|
|
@ -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])
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
# Basically does the same as above, but in build mode
|
app.after_configuration do
|
||||||
app.build_reroute do |destination, request_path|
|
# Basically does the same as above, but in build mode
|
||||||
index_ext = File.extname(index_file)
|
sitemap.reroute do |destination, page|
|
||||||
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
|
||||||
elsif frontmatter_ignore
|
destination
|
||||||
false
|
elsif frontmatter_ignore
|
||||||
else
|
destination
|
||||||
destination.sub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
|
else
|
||||||
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue