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
68 def cache
69   @website.cache['misc.dummy_index.data'] ||= {}
70 end
create_dummy_indexes() click to toggle source

Create the dummy index paths at the destination.

   # File lib/webgen/misc/dummy_index.rb
24 def create_dummy_indexes
25   indexes = @website.config['misc.dummy_index.directory_indexes']
26   @website.tree.node_access[:alcn].each do |_, node|
27     next if !node.is_directory? || !directory_exists?(node) || directory_index_exists?(node, indexes)
28 
29     route = node.route_to(node)
30     route = node['proxy_path'].to_s if route == File.basename(node.dest_path)
31     index_path = node.dest_path + indexes.first
32 
33     next if route == '' || indexes.any? {|index| index == route} ||
34       (cache[node.alcn] == [indexes.first, route] && @website.ext.destination.exists?(index_path))
35 
36     @website.logger.info do
37       "[#{@website.ext.destination.exists?(index_path) ? 'update' : 'create'}] <#{index_path}> (dummy directory path pointing to #{route})"
38     end
39     cache[node.alcn] = [indexes.first, route]
40     @website.ext.destination.write(index_path, dummy_index_content(route))
41   end
42 end
directory_exists?(node) click to toggle source

Does the node directory exist at the destination?

   # File lib/webgen/misc/dummy_index.rb
46 def directory_exists?(node)
47   @website.ext.destination.exists?(node.dest_path)
48 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
58       def dummy_index_content(url)
59         <<EOF
60 <!DOCTYPE html><html><head><title>Redirect</title><meta charset="UTF-8" />
61 <meta http-equiv="Refresh" content="0; url=#{url}" />
62 </head><body></body></html>
63 EOF
64       end