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

Methods included from Base::OutputPathHelpers

#standard_output_path

Methods included from Loggable

#log, #puts

Methods included from WebsiteAccess

included, website

Instance Method Details

#content(node) ⇒ Object

Return the rendered feed represented by node.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/webgen/sourcehandler/sitemap.rb', line 26

def content(node)
  require 'builder'
  list = website.blackboard.invoke(:create_sitemap, node, node.lang, options_for_node(node)).to_lcn_list.flatten
  sitemap = ::Builder::XmlMarkup.new(:indent => 2)
  sitemap.instruct!(:xml, :version => '1.0', :encoding => 'UTF-8')
  sitemap.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9") do
    list.each do |alcn|
      item = node.tree[alcn]
      sitemap.url do |url|
        sitemap.loc(URI.escape(File.join(node['site_url'], item.path)))
        sitemap.lastmod(item['modified_at'].iso8601)
        changefreq = item['change_freq'] || node['default_change_freq']
        sitemap.changefreq(changefreq) if changefreq
        priority = item['priority'] || node['default_priority']
        sitemap.priority(priority) if priority
      end
    end
  end
  sitemap.target!
end

#create_node(parent, path) ⇒ Object

Create an XML sitemap from parent and path.



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

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