class Webgen::Misc::DummyIndex

This extension creates dummy directory index paths for directories where the proxy_path meta information does not point to a node whose lcn matches a directory index path name.

Protected Instance Methods

cache() click to toggle source

Return the cache used by this extension.

# File lib/webgen/misc/dummy_index.rb, line 68
def cache
  @website.cache['misc.dummy_index.data'] ||= {}
end
create_dummy_indexes() click to toggle source

Create the dummy index paths at the destination.

# File lib/webgen/misc/dummy_index.rb, line 24
def create_dummy_indexes
  indexes = @website.config['misc.dummy_index.directory_indexes']
  @website.tree.node_access[:alcn].each do |_, node|
    next if !node.is_directory? || !directory_exists?(node) || directory_index_exists?(node, indexes)

    route = node.route_to(node)
    route = node['proxy_path'].to_s if route == File.basename(node.dest_path)
    index_path = node.dest_path + indexes.first

    next if route == '' || indexes.any? {|index| index == route} ||
      (cache[node.alcn] == [indexes.first, route] && @website.ext.destination.exists?(index_path))

    @website.logger.info do
      "[#{@website.ext.destination.exists?(index_path) ? 'update' : 'create'}] <#{index_path}> (dummy directory path pointing to #{route})"
    end
    cache[node.alcn] = [indexes.first, route]
    @website.ext.destination.write(index_path, dummy_index_content(route))
  end
end
directory_exists?(node) click to toggle source

Does the node directory exist at the destination?

# File lib/webgen/misc/dummy_index.rb, line 46
def directory_exists?(node)
  @website.ext.destination.exists?(node.dest_path)
end
dummy_index_content(url) click to toggle source

Return the dummy index path content for redirecting to url.

# File lib/webgen/misc/dummy_index.rb, line 58
      def dummy_index_content(url)
        <<EOF
<!DOCTYPE html><html><head><title>Redirect</title><meta charset="UTF-8" />
<meta http-equiv="Refresh" content="0; url=#{url}" />
</head><body></body></html>
EOF
      end