Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Or using latest source code:
```
rake install
```

## Configuration

Add gem to your Gemfile and you're ready to go:
Expand All @@ -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'
Expand Down Expand Up @@ -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`.

Expand Down Expand Up @@ -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:

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/xml-sitemap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions lib/xml-sitemap/index.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module XmlSitemap
class Index
attr_reader :maps

# Initialize a new Index instance
#
# opts - Index options
Expand All @@ -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
Expand All @@ -45,7 +45,7 @@ def render
end
}.to_s
end

# Render XML sitemap index into the file
#
# path - Output filename
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/xml-sitemap/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions xml-sitemap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down