Module: SitemapGenerator::Link
Instance Method Summary collapse
-
#generate(path, options = {}) ⇒ Object
Return a Hash of options suitable to pass to a SitemapGenerator::Builder::SitemapFile instance.
-
#prepare_images(images, host) ⇒ Object
Return an Array of image option Hashes suitable to be parsed by SitemapGenerator::Builder::SitemapFile.
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 |
# File 'lib/sitemap_generator/link.rb', line 6 def generate(path, = {}) if path.is_a?(SitemapGenerator::Builder::SitemapFile) .reverse_merge!(:host => path.hostname, :lastmod => path.lastmod) path = path.sitemap_path end .assert_valid_keys(:priority, :changefreq, :lastmod, :host, :images) .reverse_merge!(:priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :host => Sitemap.default_host, :images => []) { :path => path, :priority => [:priority], :changefreq => [:changefreq], :lastmod => [:lastmod], :host => [:host], :loc => URI.join([:host], path).to_s, :images => prepare_images([:images], [:host]) } end |
#prepare_images(images, host) ⇒ Object
Return an Array of image option Hashes suitable to be parsed by SitemapGenerator::Builder::SitemapFile
26 27 28 29 30 31 32 33 |
# File 'lib/sitemap_generator/link.rb', line 26 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 |