middleman/middleman-core/lib/middleman-core/extensions/directory_indexes.rb

33 lines
1.2 KiB
Ruby
Raw Normal View History

# Directory Indexes extension
class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension
# This should run after most other sitemap manipulators so that it
# gets a chance to modify any new resources that get added.
self.resource_list_manipulator_priority = 100
# Update the main sitemap resource list
2014-07-03 04:04:34 +02:00
# @return Array<Middleman::Sitemap::Resource>
Contract ResourceList => ResourceList
def manipulate_resource_list(resources)
2014-01-01 03:21:30 +01:00
index_file = app.config[:index_file]
new_index_path = "/#{index_file}"
extensions = %w(.htm .html .php .xhtml)
2016-03-02 21:00:39 +01:00
resources.each do |resource|
# Check if it would be pointless to reroute
next if resource.destination_path == index_file ||
resource.destination_path.end_with?(new_index_path) ||
2016-03-02 21:00:39 +01:00
!extensions.include?(resource.ext)
2014-04-28 08:21:12 +02:00
# Check if file metadata (options set by "page" in config.rb or frontmatter) turns directory_index off
next if resource.options[:directory_index] == false
2016-03-02 21:00:39 +01:00
extensions.each do |ext|
resource.destination_path = resource.destination_path.chomp(ext)
end
resource.destination_path += new_index_path
end
end
end