Class: Webgen::SourceHandler::Sitemap

Inherits:
Object
  • Object
show all
Includes:
Base, WebsiteAccess
Defined in:
lib/webgen/sourcehandler/sitemap.rb

Overview

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

Uses Webgen::Common::Sitemap to generate the needed sitemap tree and to check if a sitemap has changed.

Instance Method Summary collapse

Methods included from Base

#node_exists?, #output_path, #page_from_path, #parent_node

Methods included from Base::OutputPathHelpers

#standard_output_path

Methods included from Loggable

#log, #puts

Methods included from WebsiteAccess

included, website

Instance Method Details

#alcns(node) ⇒ Object

Return the alcns of the sitemap node as a flat list.



39
40
41
# File 'lib/webgen/sourcehandler/sitemap.rb', line 39

def alcns(node)
  website.blackboard.invoke(:create_sitemap, node, node.lang, options_for_node(node)).to_lcn_list.flatten
end

#content(node) ⇒ Object

Return the rendered feed represented by node.



28
29
30
31
32
33
34
35
36
# File 'lib/webgen/sourcehandler/sitemap.rb', line 28

def content(node)
  if node.node_info[:sitemap].blocks.has_key?('template')
    node.node_info[:sitemap].blocks['template'].render(Webgen::Context.new(:chain => [node])).content
  else
    chain = [node.resolve("/templates/sitemap.template"), node]
    node.node_info[:used_nodes] << chain.first.alcn
    chain.first.node_info[:page].blocks['content'].render(Webgen::Context.new(:chain => chain)).content
  end
end

#create_node(path) ⇒ Object

Create an XML sitemap from path.



18
19
20
21
22
23
24
25
# File 'lib/webgen/sourcehandler/sitemap.rb', line 18

def create_node(path)
  page = page_from_path(path)
  path.ext = 'xml'
  raise "Needed information site_url missing for sitemap <#{path}>" if path.meta_info['site_url'].nil?
  super(path) do |node|
    node.node_info[:sitemap] = page
  end
end