Class: Middleman::Extensions::DirectoryIndexes

Inherits:
Middleman::Extension show all
Defined in:
middleman-core/lib/middleman-core/extensions/directory_indexes.rb

Overview

Directory Indexes extension

Constant Summary collapse

EXTENSIONS =
Set.new %w[.htm .html .php .xhtml]

Constants included from Contracts

Contracts::ImmutableSetOf, Contracts::ImmutableSortedSetOf, Contracts::OldResourceList, Contracts::PATH_MATCHER, Contracts::ResourceList, Contracts::VectorOf

Instance Attribute Summary

Attributes inherited from Middleman::Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Middleman::Extension

activated_extension, #add_exposed_to_context, #after_build, #after_configuration, after_extension_activated, #after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, helpers, #initialize, #manipulate_resource_list, option, #ready, resources

Methods included from Contracts

#Contract

Constructor Details

This class inherits a constructor from Middleman::Extension

Instance Method Details

#manipulate_resource_list_container!(resource_list) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'middleman-core/lib/middleman-core/extensions/directory_indexes.rb', line 12

def manipulate_resource_list_container!(resource_list)
  index_file = app.config[:index_file]
  new_index_path = "/#{index_file}"

  resource_list.by_extensions(EXTENSIONS).each do |resource|
    next if resource.destination_path == index_file ||
            resource.destination_path.end_with?(new_index_path)

    # Check if file metadata (options set by "page" in config.rb or frontmatter) turns directory_index off
    next if resource.options[:directory_index] == false

    resource_list.update!(resource, :destination_path) do
      EXTENSIONS.each do |ext|
        resource.destination_path = resource.destination_path.chomp(ext)
      end

      resource.destination_path += new_index_path
    end
  end
end