Sha256: 3e36f22e81408eced353092d99ec710a017e4b4d436f8db2c830afb4fefdf12f

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

module SitemapGenerator
  module Link
    extend self

    # Return a Hash of options suitable to pass to a SitemapGenerator::Builder::SitemapFile instance.
    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)
      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])
      }
    end

    # Return an Array of image option Hashes suitable to be parsed by SitemapGenerator::Builder::SitemapFile
    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
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
airblade-sitemap_generator-0.3.5 lib/sitemap_generator/link.rb
sitemap_generator-1.0.1 lib/sitemap_generator/link.rb
sitemap_generator-1.0.0 lib/sitemap_generator/link.rb
airblade-sitemap_generator-0.3.4 lib/sitemap_generator/link.rb
sitemap_generator-0.3.3 lib/sitemap_generator/link.rb
sitemap_generator-0.3.2 lib/sitemap_generator/link.rb
sitemap_generator-0.3.1 lib/sitemap_generator/link.rb
sitemap_generator-0.3.0 lib/sitemap_generator/link.rb