Builder and DirectoryIndexes now check frontmatter options.

This commit is contained in:
Thomas Reynolds 2012-01-07 17:27:26 -08:00
parent c473181167
commit 7282475350
2 changed files with 30 additions and 8 deletions

View file

@ -23,6 +23,7 @@
* activating extensions can now take an options hash * activating extensions can now take an options hash
* Don't re-minify files with ".min" in their name * Don't re-minify files with ".min" in their name
* Serve purely static folders directly (without source/ and config.rb) * Serve purely static folders directly (without source/ and config.rb)
* Set ignored files and disable directory_indexes from YAML frontmatter
2.0.14 2.0.14
==== ====

View file

@ -4,15 +4,25 @@ module Middleman::Extensions
def registered(app) def registered(app)
app.send :include, InstanceMethods app.send :include, InstanceMethods
app.before do app.before do
next if sitemap.exists?(@original_path) prefix = @original_path.sub(/\/$/, "")
indexed_path = prefix + "/" + index_file
prefix = @original_path.sub(/\/$/, "")
indexed_path = prefix + "/" + index_file
extensioned_path = prefix + File.extname(index_file) extensioned_path = prefix + File.extname(index_file)
is_ignored = ignored_directory_indexes.include?(extensioned_path)
is_ignored = false
if !sitemap.exists?(indexed_path) && !is_ignored fm_ignored = false
if sitemap.exists?(@original_path)
d = sitemap.page(@original_path).data
if !d.nil? && d.has_key?("directory_index") && d["directory_index"] == false
fm_ignored = true
else
next
end
else
is_ignored = ignored_directory_indexes.include?(extensioned_path)
end
if !sitemap.exists?(indexed_path) && !is_ignored && !fm_ignored
parts = @original_path.split("/") parts = @original_path.split("/")
last_part = parts.last last_part = parts.last
last_part_ext = File.extname(last_part) last_part_ext = File.extname(last_part)
@ -27,11 +37,22 @@ module Middleman::Extensions
app.build_reroute do |destination, request_path| app.build_reroute do |destination, request_path|
index_ext = File.extname(index_file) index_ext = File.extname(index_file)
new_index_path = "/#{index_file}" new_index_path = "/#{index_file}"
frontmatter_ignore = false
if sitemap.exists?(request_path)
p = sitemap.page(request_path)
d = p.data
if !d.nil?
frontmatter_ignore = d.has_key?("directory_index") && d["directory_index"] == false
end
end
if ignored_directory_indexes.include?(request_path) if ignored_directory_indexes.include?(request_path)
false false
elsif request_path =~ /#{new_index_path}$/ elsif request_path =~ /#{new_index_path}$/
false false
elsif frontmatter_ignore
false
else else
[ [
destination.sub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path), destination.sub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),