diff --git a/README.md b/README.md index c1746bb..d500318 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Or using latest source code: ``` rake install ``` - + ## Configuration Add gem to your Gemfile and you're ready to go: @@ -27,13 +27,13 @@ gem 'xml-sitemap' ``` ## Usage - + Simple usage: ```ruby map = XmlSitemap::Map.new('domain.com') do |m| # Adds a simple page - m.add '/page1' + m.add '/page1' # You can drop leading slash, it will be automatically added m.add 'page2' @@ -70,8 +70,8 @@ You can also create a map via shortcut: map = XmlSitemap.new('foobar.com') map = XmlSitemap.map('foobar.com') ``` - -By default XmlSitemap creates a map with link to homepage of your domain. + +By default XmlSitemap creates a map with link to homepage of your domain. Homepage priority is `1.0`. @@ -100,11 +100,11 @@ Available options: - `:home` - Disable homepage autocreation, but you still can do that manually. *(default: true)* - `:root` - Force all links to fall under the main domain. You can add full urls (not paths) if set to false. *(default: true)* - `:time` - Provide a creation time for the sitemap. (default: current time) -- `:group` - Group name for sitemap index. *(default: sitemap)* +- `:group` - Group name for sitemap index. *(default: sitemap)* ### Render Engines -XmlSitemap has a few different rendering engines. You can select one passing argument to `render` method. +XmlSitemap has a few different rendering engines. You can select one passing argument to `render` method. Available engines: @@ -123,7 +123,7 @@ Usage: ```ruby map = XmlSitemap::Map.new('domain.com') map.add 'page' - + index = XmlSitemap::Index.new # or if you want the URLs to use HTTPS diff --git a/lib/xml-sitemap.rb b/lib/xml-sitemap.rb index c364d93..9a03343 100644 --- a/lib/xml-sitemap.rb +++ b/lib/xml-sitemap.rb @@ -23,15 +23,15 @@ class << self # options - Map options # def map(domain, options={}) - XmlSitemap::Map.new(domain, options) + XmlSitemap::Map.new(domain, options) end - + alias :new :map - + # Shortcut to XmlSitemap::Index.new # # options - Index options - # + # def index(options={}) XmlSitemap::Index.new(options) end diff --git a/lib/xml-sitemap/index.rb b/lib/xml-sitemap/index.rb index 7c486a3..1d1b964 100644 --- a/lib/xml-sitemap/index.rb +++ b/lib/xml-sitemap/index.rb @@ -1,7 +1,7 @@ module XmlSitemap class Index attr_reader :maps - + # Initialize a new Index instance # # opts - Index options @@ -12,25 +12,25 @@ def initialize(opts={}) @maps = [] @offsets = Hash.new(0) @secure = opts[:secure] || false - + yield self if block_given? end - + # Add map object to index # # map - XmlSitemap::Map instance # - def add(map, use_offsets=true) + def add(map, use_offsets=true, start_offset = 0) raise ArgumentError, 'XmlSitemap::Map object required!' unless map.kind_of?(XmlSitemap::Map) raise ArgumentError, 'Map is empty!' if map.empty? - + @maps << { - :loc => use_offsets ? map.index_url(@offsets[map.group], @secure) : map.plain_index_url(@secure), + :loc => use_offsets ? map.index_url(start_offset + @offsets[map.group], @secure) : map.plain_index_url(@secure), :lastmod => map.created_at.utc.iso8601 } @offsets[map.group] += 1 end - + # Generate sitemap XML index # def render @@ -45,7 +45,7 @@ def render end }.to_s end - + # Render XML sitemap index into the file # # path - Output filename @@ -56,11 +56,11 @@ def render def render_to(path, options={}) overwrite = options[:overwrite] || true path = File.expand_path(path) - + if File.exists?(path) && !overwrite raise RuntimeError, "File already exists and not overwritable!" end - + File.open(path, 'w') { |f| f.write(self.render) } end end diff --git a/lib/xml-sitemap/item.rb b/lib/xml-sitemap/item.rb index a1387c4..3bd90c1 100644 --- a/lib/xml-sitemap/item.rb +++ b/lib/xml-sitemap/item.rb @@ -9,7 +9,7 @@ class Item :video_thumbnail_location, :video_title, :video_description, :video_content_location, :video_player_location, :video_duration, :video_expiration_date, :video_rating, :video_view_count, :video_publication_date, :video_family_friendly, :video_category, :video_restriction, :video_gallery_location, :video_price, :video_requires_subscription, :video_uploader, :video_platform, :video_live - + def initialize(target, opts={}) @target = target.to_s.strip @updated = opts[:updated] || Time.now diff --git a/xml-sitemap.gemspec b/xml-sitemap.gemspec index c287d6c..11d83b8 100644 --- a/xml-sitemap.gemspec +++ b/xml-sitemap.gemspec @@ -8,14 +8,14 @@ Gem::Specification.new do |s| s.homepage = "http://github.com/sosedoff/xml-sitemap" s.authors = ["Dan Sosedoff"] s.email = ["dan.sosedoff@gmail.com"] - + s.add_development_dependency 'rake', '~> 10.0' s.add_development_dependency 'rspec', '~> 2.13' s.add_development_dependency 'simplecov', '~> 0.7' s.add_development_dependency 'nokogiri', '~> 1.5' - + s.add_runtime_dependency 'builder', '>= 2.0' - + s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}