class Webgen::PathHandler::Sitemap

Path handler for creating an XML sitemap based on the specification of sitemaps.org.

Constants

MANDATORY_INFOS

The mandatory keys that need to be set in a sitemap file.

Public Instance Methods

content(node) click to toggle source

Return the rendered feed represented by node.

   # File lib/webgen/path_handler/sitemap.rb
55 def content(node)
56   context = Webgen::Context.new(@website)
57   context.render_block(:name => "sitemap", :node => 'first',
58                        :chain => [node, node.resolve("/templates/sitemap.template", node.lang, true), node].compact)
59 end
create_nodes(path, blocks) click to toggle source

Create an XML sitemap from path.

   # File lib/webgen/path_handler/sitemap.rb
33 def create_nodes(path, blocks)
34   if MANDATORY_INFOS.any? {|t| path.meta_info[t].nil?}
35     raise Webgen::NodeCreationError.new("At least one of #{MANDATORY_INFOS.join('/')} is missing",
36                                         "path_handler.sitemap", path)
37   end
38 
39   if @website.config['website.base_url'].empty?
40     raise Webgen::NodeCreationError.new("The configuration option 'website.base_url' needs to be set",
41                                         "path_handler.sitemap", path)
42   end
43 
44   path.ext = 'xml'
45   path['node_class'] = Node.to_s
46   create_node(path) do |node|
47     set_blocks(node, blocks)
48     node.node_info[:entries] = {:flatten => true, :not => {:mi => {'no_output' => true}}, :and => node['entries']}
49     @website.ext.item_tracker.add(node, :nodes, :node_finder_option_set,
50                                   {:opts => node.node_info[:entries], :ref_alcn => node.alcn}, :meta_info)
51   end
52 end