Class: Middleman::Extensions::DirectoryIndexes

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

Overview

Directory Indexes extension

Instance Attribute Summary

Attributes inherited from Middleman::Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Middleman::Extension

activate, activated_extension, after_extension_activated, clear_after_extension_callbacks, config, extension_name, helpers, #initialize, option, register

Constructor Details

This class inherits a constructor from Middleman::Extension

Instance Method Details

#manipulate_resource_list(resources) ⇒ void

This method returns an undefined value.

Update the main sitemap resource list



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/middleman-more/extensions/directory_indexes.rb', line 5

def manipulate_resource_list(resources)
  index_file = app.index_file
  new_index_path = "/#{index_file}"

  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) ||
            File.extname(index_file) != resource.ext

    # Check if frontmatter turns directory_index off
    next if resource.raw_data[:directory_index] == false

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

    resource.destination_path = resource.destination_path.chomp(File.extname(index_file)) + new_index_path
  end
end