Method: SitemapGenerator::Builder::SitemapUrl#initialize
- Defined in:
- lib/sitemap_generator/builder/sitemap_url.rb
#initialize(path, options = {}) ⇒ SitemapUrl
Return a new instance with options configured on it.
Arguments
-
sitemap - a Sitemap instance, or
-
path, options - a path string and options hash
Options
Requires a host to be set. If passing a sitemap, the sitemap must have a default_host
configured. If calling with a path and options, you must include the :host
option.
-
host
-
priority
-
changefreq
-
lastmod
-
images
-
video
/videos
-
geo
-
news
-
mobile
-
alternate
/alternates
-
pagemap
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sitemap_generator/builder/sitemap_url.rb', line 33 def initialize(path, ={}) = .dup if sitemap = path.is_a?(SitemapGenerator::Builder::SitemapFile) && path SitemapGenerator::Utilities.reverse_merge!(, :host => sitemap.location.host, :lastmod => sitemap.lastmod) path = sitemap.location.path_in_public end SitemapGenerator::Utilities.assert_valid_keys(, :priority, :changefreq, :lastmod, :expires, :host, :images, :video, :geo, :news, :videos, :mobile, :alternate, :alternates, :pagemap) SitemapGenerator::Utilities.reverse_merge!(, :priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :images => [], :news => {}, :videos => [], :mobile => false, :alternates => []) raise "Cannot generate a url without a host" unless SitemapGenerator::Utilities.present?([:host]) if video = .delete(:video) [:videos] = video.is_a?(Array) ? [:videos].concat(video) : [:videos] << video end if alternate = .delete(:alternate) [:alternates] = alternate.is_a?(Array) ? [:alternates].concat(alternate) : [:alternates] << alternate end path = path.to_s.sub(/^\//, '') loc = path.empty? ? [:host] : ([:host].to_s.sub(/\/$/, '') + '/' + path) self.merge!( :priority => [:priority], :changefreq => [:changefreq], :lastmod => [:lastmod], :expires => [:expires], :host => [:host], :loc => loc, :images => prepare_images([:images], [:host]), :news => prepare_news([:news]), :videos => [:videos], :geo => [:geo], :mobile => [:mobile], :alternates => [:alternates], :pagemap => [:pagemap] ) end |