Permalink
Browse files

support arbitrary sitemap "types"

  • Loading branch information...
mislav committed Apr 6, 2009
1 parent 110c5df commit 7d9aaf2957484d9ce1e884d3d519d2120c66e752
Showing with 10 additions and 6 deletions.
  1. +1 −2 lib/big_sitemap.rb
  2. +9 −4 lib/big_sitemap/builder.rb
View
@@ -73,7 +73,6 @@ def generate
private
def with_sitemap(name, options = {})
- options[:index] = name == 'index'
options[:filename] = "#{@root}/sitemap_#{name}"
options[:max_urls] = @options[:max_per_sitemap]
@@ -92,7 +91,7 @@ def with_sitemap(name, options = {})
end
def generate_sitemap_index
- with_sitemap 'index' do |sitemap|
+ with_sitemap 'index', :type => 'index' do |sitemap|
for path in @sitemap_files
sitemap.add_url!(url_for_sitemap(path), File.stat(path).mtime)
end
View
@@ -3,13 +3,12 @@
class BigSitemap
class Builder < Builder::XmlMarkup
- NAMESPACE = 'http://www.sitemaps.org/schemas/sitemap/0.9'
MAX_URLS = 50000
def initialize(options)
@gzip = options.delete(:gzip)
@max_urls = options.delete(:max_urls) || MAX_URLS
- @index = options.delete(:index)
+ @type = options.delete(:type)
@paths = []
@parts = 0
@@ -23,10 +22,14 @@ def initialize(options)
_init_document
end
+ def index?
+ @type == 'index'
+ end
+
def add_url!(url, time = nil, frequency = nil, priority = nil)
_rotate if @max_urls == @urls
- tag!(@index ? 'sitemap' : 'url') do
+ tag!(index?? 'sitemap' : 'url') do
loc url
lastmod(time.to_s(:sitemap)) unless time.nil?
changefreq(frequency) unless frequency.nil?
@@ -67,7 +70,9 @@ def _open_writer(filename)
def _init_document
@urls = 0
instruct!
- _open_tag(@index ? 'sitemapindex' : 'urlset', :xmlns => NAMESPACE)
+ # define root element and namespaces
+ attrs = {'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'}
+ _open_tag(index?? 'sitemapindex' : 'urlset', attrs)
end
def _rotate

0 comments on commit 7d9aaf2

Please sign in to comment.