Module: SitemapGenerator::Link

Extended by:
Link
Included in:
Link
Defined in:
lib/sitemap_generator/link.rb

Instance Method Summary collapse

Instance Method Details

#generate(path, options = {}) ⇒ Object

Return a Hash of options suitable to pass to a SitemapGenerator::Builder::SitemapFile instance.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sitemap_generator/link.rb', line 6

def generate(path, options = {})
  if path.is_a?(SitemapGenerator::Builder::SitemapFile)
    options.reverse_merge!(:host => path.hostname, :lastmod => path.lastmod)
    path = path.sitemap_path
  end

  options.assert_valid_keys(:priority, :changefreq, :lastmod, :host, :images, :video)
  options.reverse_merge!(:priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :host => Sitemap.default_host, :images => [])
  {
    :path => path,
    :priority => options[:priority],
    :changefreq => options[:changefreq],
    :lastmod => options[:lastmod],
    :host => options[:host],
    :loc => URI.join(options[:host], path).to_s,
    :images => prepare_images(options[:images], options[:host]),
    :video => options[:video]
  }
end

#prepare_images(images, host) ⇒ Object

Return an Array of image option Hashes suitable to be parsed by SitemapGenerator::Builder::SitemapFile



27
28
29
30
31
32
33
34
# File 'lib/sitemap_generator/link.rb', line 27

def prepare_images(images, host)
  images.delete_if { |key,value| key[:loc] == nil }
  images.each do |r|
    r.assert_valid_keys(:loc, :caption, :geo_location, :title, :license)
    r[:loc] = URI.join(host, r[:loc]).to_s
  end
  images[0..(SitemapGenerator::MAX_SITEMAP_IMAGES-1)]
end