alexrabarts-big_sitemap 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +12 -12
- data/VERSION.yml +1 -1
- data/lib/big_sitemap/builder.rb +124 -0
- data/lib/big_sitemap.rb +60 -79
- data/test/big_sitemap_test.rb +34 -35
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -26,7 +26,7 @@ The code above will create a minimum of three files:
|
|
26
26
|
2. public/sitemaps/sitemap_products.xml.gz
|
27
27
|
3. public/sitemaps/sitemap_posts.xml.gz
|
28
28
|
|
29
|
-
If your sitemaps grow beyond 50,000 URLs (this limit can be overridden with the <code>:max_per_sitemap</code> option), the sitemap files will be partitioned into multiple files (<code>sitemap_products_1.xml.gz</code>, <code>sitemap_products_2.xml.gz</code>,
|
29
|
+
If your sitemaps grow beyond 50,000 URLs (this limit can be overridden with the <code>:max_per_sitemap</code> option), the sitemap files will be partitioned into multiple files (<code>sitemap_products_1.xml.gz</code>, <code>sitemap_products_2.xml.gz</code>, ...).
|
30
30
|
|
31
31
|
If you're using Rails then the URLs for each database record are generated with the <code>polymorphic_url</code> helper. That means that the URL for a record will be exactly what you would expect: generated with respect to the routing setup of your app. In other contexts where this helper isn't available, the URLs are generated in the form:
|
32
32
|
|
@@ -44,17 +44,17 @@ Via gem:
|
|
44
44
|
|
45
45
|
=== Options
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
47
|
+
* <code>:url_options</code> -- hash with <code>:host</code>, optionally <code>:port</code> and <code>:protocol</code>
|
48
|
+
* <code>:base_url</code> -- string alternative to <code>:url_options</code>, e.g. "https://example.com:8080/"
|
49
|
+
* <code>:document_root</code> -- string defaults to <code>Rails.root</code> or <code>Merb.root</code> if available
|
50
|
+
* <code>:path</code> -- string defaults to 'sitemaps', which places sitemap files under the <code>/sitemaps</code> directory
|
51
|
+
* <code>:max_per_sitemap</code> -- <code>50000</code>, which is the limit dictated by Google but can be less
|
52
|
+
* <code>:batch_size</code> -- <code>1001</code> (not <code>1000</code> due to a bug in DataMapper)
|
53
|
+
* <code>:gzip</code> -- <code>true</code>
|
54
|
+
* <code>:ping_google</code> -- <code>true</code>
|
55
|
+
* <code>:ping_yahoo</code> -- <code>false</code>, needs <code>:yahoo_app_id</code>
|
56
|
+
* <code>:ping_msn</code> -- <code>false</code>
|
57
|
+
* <code>:pink_ask</code> -- <code>false</code>
|
58
58
|
|
59
59
|
=== Chaining
|
60
60
|
|
data/VERSION.yml
CHANGED
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'zlib'
|
3
|
+
|
4
|
+
class BigSitemap
|
5
|
+
class Builder < Builder::XmlMarkup
|
6
|
+
NAMESPACE = 'http://www.sitemaps.org/schemas/sitemap/0.9'
|
7
|
+
MAX_URLS = 50000
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@gzip = options.delete(:gzip)
|
11
|
+
@max_urls = options.delete(:max_urls) || MAX_URLS
|
12
|
+
@index = options.delete(:index)
|
13
|
+
@paths = []
|
14
|
+
@parts = 0
|
15
|
+
|
16
|
+
if @filename = options.delete(:filename)
|
17
|
+
options[:target] = _get_writer
|
18
|
+
end
|
19
|
+
|
20
|
+
super(options)
|
21
|
+
|
22
|
+
@opened_tags = []
|
23
|
+
_init_document
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_url!(url, time = nil, frequency = nil, priority = nil)
|
27
|
+
_rotate if @max_urls == @urls
|
28
|
+
|
29
|
+
tag!(@index ? 'sitemap' : 'url') do
|
30
|
+
loc url
|
31
|
+
# W3C format is the subset of ISO 8601
|
32
|
+
lastmod(time.utc.strftime('%Y-%m-%dT%H:%M:%S+00:00')) unless time.nil?
|
33
|
+
changefreq(frequency) unless frequency.nil?
|
34
|
+
priority(priority) unless priority.nil?
|
35
|
+
end
|
36
|
+
@urls += 1
|
37
|
+
end
|
38
|
+
|
39
|
+
def close!
|
40
|
+
_close_document
|
41
|
+
target!.close if target!.respond_to?(:close)
|
42
|
+
end
|
43
|
+
|
44
|
+
def paths!
|
45
|
+
@paths
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def _get_writer
|
51
|
+
if @filename
|
52
|
+
filename = @filename.dup
|
53
|
+
filename << "_#{@parts}" if @parts > 0
|
54
|
+
filename << '.xml'
|
55
|
+
filename << '.gz' if @gzip
|
56
|
+
_open_writer(filename)
|
57
|
+
else
|
58
|
+
target!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def _open_writer(filename)
|
63
|
+
file = File.open(filename, 'w+')
|
64
|
+
@paths << filename
|
65
|
+
@gzip ? Zlib::GzipWriter.new(file) : file
|
66
|
+
end
|
67
|
+
|
68
|
+
def _init_document
|
69
|
+
@urls = 0
|
70
|
+
instruct!
|
71
|
+
_open_tag(@index ? 'sitemapindex' : 'urlset', :xmlns => NAMESPACE)
|
72
|
+
end
|
73
|
+
|
74
|
+
def _rotate
|
75
|
+
# write out the current document and start writing into a new file
|
76
|
+
close!
|
77
|
+
@parts += 1
|
78
|
+
@target = _get_writer
|
79
|
+
_init_document
|
80
|
+
end
|
81
|
+
|
82
|
+
# add support for:
|
83
|
+
# xml.open_foo!(attrs)
|
84
|
+
# xml.close_foo!
|
85
|
+
def method_missing(method, *args, &block)
|
86
|
+
if method.to_s =~ /^(open|close)_(.+)!$/
|
87
|
+
operation, name = $1, $2
|
88
|
+
name = "#{name}:#{args.shift}" if Symbol === args.first
|
89
|
+
|
90
|
+
if 'open' == operation
|
91
|
+
_open_tag(name, args.first)
|
92
|
+
else
|
93
|
+
_close_tag(name)
|
94
|
+
end
|
95
|
+
else
|
96
|
+
super
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# opens a tag, bumps up level but doesn't require a block
|
101
|
+
def _open_tag(name, attrs)
|
102
|
+
_indent
|
103
|
+
_start_tag(name, attrs)
|
104
|
+
_newline
|
105
|
+
@level += 1
|
106
|
+
@opened_tags << name
|
107
|
+
end
|
108
|
+
|
109
|
+
# closes a tag block by decreasing the level and inserting a close tag
|
110
|
+
def _close_tag(name)
|
111
|
+
@opened_tags.pop
|
112
|
+
@level -= 1
|
113
|
+
_indent
|
114
|
+
_end_tag(name)
|
115
|
+
_newline
|
116
|
+
end
|
117
|
+
|
118
|
+
def _close_document
|
119
|
+
for name in @opened_tags.reverse
|
120
|
+
_close_tag(name)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/lib/big_sitemap.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require '
|
3
|
-
require 'builder'
|
2
|
+
require 'big_sitemap/builder'
|
4
3
|
require 'extlib'
|
5
4
|
|
6
5
|
class BigSitemap
|
7
6
|
DEFAULTS = {
|
8
|
-
:max_per_sitemap =>
|
7
|
+
:max_per_sitemap => Builder::MAX_URLS,
|
9
8
|
:batch_size => 1001,
|
10
9
|
:path => 'sitemaps',
|
11
10
|
:gzip => true,
|
@@ -30,6 +29,10 @@ class BigSitemap
|
|
30
29
|
# Use Rails' default_url_options if available
|
31
30
|
@default_url_options = defined?(Rails) ? default_url_options : {}
|
32
31
|
|
32
|
+
if @options[:max_per_sitemap] <= 1
|
33
|
+
raise ArgumentError, '":max_per_sitemap" must be greater than 1'
|
34
|
+
end
|
35
|
+
|
33
36
|
if @options[:url_options]
|
34
37
|
@default_url_options.update @options[:url_options]
|
35
38
|
elsif @options[:base_url]
|
@@ -79,71 +82,55 @@ class BigSitemap
|
|
79
82
|
|
80
83
|
def generate
|
81
84
|
for model, options in @sources
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
find_options = options.dup
|
98
|
-
|
99
|
-
for sitemap_num in 1..num_sitemaps
|
100
|
-
# Work out the start and end batch numbers for this sitemap
|
101
|
-
batch_num_start = sitemap_num == 1 ? 1 : ((sitemap_num * batches_per_sitemap).ceil - batches_per_sitemap + 1).to_i
|
102
|
-
batch_num_end = (batch_num_start + [batches_per_sitemap, num_batches].min).floor - 1
|
85
|
+
with_sitemap(Extlib::Inflection::tableize(model.to_s)) do |sitemap|
|
86
|
+
count_method = pick_method(model, COUNT_METHODS)
|
87
|
+
find_method = pick_method(model, FIND_METHODS)
|
88
|
+
raise ArgumentError, "#{model} must provide a count_for_sitemap class method" if count_method.nil?
|
89
|
+
raise ArgumentError, "#{model} must provide a find_for_sitemap class method" if find_method.nil?
|
90
|
+
|
91
|
+
count = model.send(count_method)
|
92
|
+
num_sitemaps = 1
|
93
|
+
num_batches = 1
|
94
|
+
|
95
|
+
if count > @options[:batch_size]
|
96
|
+
num_batches = (count.to_f / @options[:batch_size].to_f).ceil
|
97
|
+
num_sitemaps = (count.to_f / @options[:max_per_sitemap].to_f).ceil
|
98
|
+
end
|
99
|
+
batches_per_sitemap = num_batches.to_f / num_sitemaps.to_f
|
103
100
|
|
104
|
-
|
105
|
-
filename = "sitemap_#{Extlib::Inflection::tableize(model.to_s)}"
|
106
|
-
filename << "_#{sitemap_num}" if num_sitemaps > 1
|
101
|
+
find_options = options.dup
|
107
102
|
|
108
|
-
|
103
|
+
for sitemap_num in 1..num_sitemaps
|
104
|
+
# Work out the start and end batch numbers for this sitemap
|
105
|
+
batch_num_start = sitemap_num == 1 ? 1 : ((sitemap_num * batches_per_sitemap).ceil - batches_per_sitemap + 1).to_i
|
106
|
+
batch_num_end = (batch_num_start + [batches_per_sitemap, num_batches].min).floor - 1
|
109
107
|
|
110
|
-
xml = Builder::XmlMarkup.new(:target => f)
|
111
|
-
xml.instruct!
|
112
|
-
xml.urlset(:xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9') do
|
113
108
|
for batch_num in batch_num_start..batch_num_end
|
114
109
|
offset = ((batch_num - 1) * @options[:batch_size])
|
115
110
|
limit = (count - offset) < @options[:batch_size] ? (count - offset - 1) : @options[:batch_size]
|
116
111
|
find_options.update(:limit => limit, :offset => offset) if num_batches > 1
|
117
112
|
|
118
|
-
model.send(find_method, find_options).each do |
|
119
|
-
last_mod_method = pick_method(
|
120
|
-
last_mod = last_mod_method.nil? ? Time.now :
|
113
|
+
model.send(find_method, find_options).each do |record|
|
114
|
+
last_mod_method = pick_method(record, TIMESTAMP_METHODS)
|
115
|
+
last_mod = last_mod_method.nil? ? Time.now : record.send(last_mod_method)
|
121
116
|
|
122
|
-
param_method = pick_method(
|
117
|
+
param_method = pick_method(record, PARAM_METHODS)
|
123
118
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
"#{root_url}/#{strip_leading_slash(options[:path])}/#{r.send(param_method)}"
|
128
|
-
xml.loc(location)
|
119
|
+
location = defined?(Rails) ?
|
120
|
+
polymorphic_url(record) :
|
121
|
+
"#{root_url}/#{strip_leading_slash(options[:path])}/#{record.send(param_method)}"
|
129
122
|
|
130
|
-
|
123
|
+
change_frequency = options[:change_frequency] || 'weekly'
|
124
|
+
freq = change_frequency.is_a?(Proc) ? change_frequency.call(record) : change_frequency
|
131
125
|
|
132
|
-
|
133
|
-
|
126
|
+
priority = options[:priority]
|
127
|
+
pri = priority.is_a?(Proc) ? priority.call(record) : priority
|
134
128
|
|
135
|
-
|
136
|
-
unless priority.nil?
|
137
|
-
xml.priority(priority.is_a?(Proc) ? priority.call(r) : priority)
|
138
|
-
end
|
139
|
-
end
|
129
|
+
sitemap.add_url!(location, last_mod, freq, pri)
|
140
130
|
end
|
141
131
|
end
|
142
132
|
end
|
143
|
-
|
144
|
-
f.close
|
145
133
|
end
|
146
|
-
|
147
134
|
end
|
148
135
|
|
149
136
|
generate_sitemap_index
|
@@ -193,6 +180,25 @@ class BigSitemap
|
|
193
180
|
|
194
181
|
private
|
195
182
|
|
183
|
+
def with_sitemap(name, options={})
|
184
|
+
options[:index] = name == 'index'
|
185
|
+
options[:filename] = "#{@file_path}/sitemap_#{name}"
|
186
|
+
options[:max_urls] = @options[:max_per_sitemap]
|
187
|
+
|
188
|
+
unless options[:gzip] = @options[:gzip]
|
189
|
+
options[:indent] = 2
|
190
|
+
end
|
191
|
+
|
192
|
+
sitemap = Builder.new(options)
|
193
|
+
|
194
|
+
begin
|
195
|
+
yield sitemap
|
196
|
+
ensure
|
197
|
+
sitemap.close!
|
198
|
+
@sitemap_files.concat sitemap.paths!
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
196
202
|
def strip_leading_slash(str)
|
197
203
|
str.sub(/^\//, '')
|
198
204
|
end
|
@@ -208,40 +214,15 @@ class BigSitemap
|
|
208
214
|
method
|
209
215
|
end
|
210
216
|
|
211
|
-
def xml_open(filename)
|
212
|
-
filename << '.xml'
|
213
|
-
filename << '.gz' if @options[:gzip]
|
214
|
-
|
215
|
-
file = File.open("#{@file_path}/#{filename}", 'w+')
|
216
|
-
|
217
|
-
@sitemap_files << file.path
|
218
|
-
|
219
|
-
writer = @options[:gzip] ? Zlib::GzipWriter.new(file) : file
|
220
|
-
|
221
|
-
if block_given?
|
222
|
-
yield writer
|
223
|
-
writer.close
|
224
|
-
end
|
225
|
-
|
226
|
-
writer
|
227
|
-
end
|
228
|
-
|
229
217
|
def url_for_sitemap(path)
|
230
218
|
"#{root_url}/#{File.basename(path)}"
|
231
219
|
end
|
232
220
|
|
233
221
|
# Create a sitemap index document
|
234
222
|
def generate_sitemap_index
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
xml.sitemapindex(:xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9') do
|
239
|
-
for path in @sitemap_files[0..-2]
|
240
|
-
xml.sitemap do
|
241
|
-
xml.loc(url_for_sitemap(path))
|
242
|
-
xml.lastmod(Time.now.strftime('%Y-%m-%d'))
|
243
|
-
end
|
244
|
-
end
|
223
|
+
with_sitemap 'index' do |sitemap|
|
224
|
+
for path in @sitemap_files
|
225
|
+
sitemap.add_url!(url_for_sitemap(path), File.stat(path).mtime)
|
245
226
|
end
|
246
227
|
end
|
247
228
|
end
|
data/test/big_sitemap_test.rb
CHANGED
@@ -32,14 +32,13 @@ class BigSitemapTest < Test::Unit::TestCase
|
|
32
32
|
create_sitemap
|
33
33
|
add_model
|
34
34
|
@sitemap.generate
|
35
|
-
assert File.exists?(
|
35
|
+
assert File.exists?(first_sitemaps_model_file), "#{first_sitemaps_model_file} exists"
|
36
36
|
end
|
37
37
|
|
38
38
|
should 'generate two sitemap model files' do
|
39
39
|
generate_two_model_sitemap_files
|
40
40
|
assert File.exists?(first_sitemaps_model_file), "#{first_sitemaps_model_file} exists"
|
41
41
|
assert File.exists?(second_sitemaps_model_file), "#{second_sitemaps_model_file} exists"
|
42
|
-
third_sitemaps_model_file = "#{sitemaps_dir}/sitemap_test_model_3.xml.gz"
|
43
42
|
assert !File.exists?(third_sitemaps_model_file), "#{third_sitemaps_model_file} does not exist"
|
44
43
|
end
|
45
44
|
|
@@ -83,90 +82,90 @@ class BigSitemapTest < Test::Unit::TestCase
|
|
83
82
|
context 'Sitemap model file' do
|
84
83
|
should 'contain one urlset element' do
|
85
84
|
generate_one_sitemap_model_file
|
86
|
-
assert_equal 1, num_elements(
|
85
|
+
assert_equal 1, num_elements(first_sitemaps_model_file, 'urlset')
|
87
86
|
end
|
88
87
|
|
89
88
|
should 'contain several loc elements' do
|
90
89
|
generate_one_sitemap_model_file
|
91
|
-
assert_equal default_num_items, num_elements(
|
90
|
+
assert_equal default_num_items, num_elements(first_sitemaps_model_file, 'loc')
|
92
91
|
end
|
93
92
|
|
94
93
|
should 'contain several lastmod elements' do
|
95
94
|
generate_one_sitemap_model_file
|
96
|
-
assert_equal default_num_items, num_elements(
|
95
|
+
assert_equal default_num_items, num_elements(first_sitemaps_model_file, 'lastmod')
|
97
96
|
end
|
98
97
|
|
99
98
|
should 'contain several changefreq elements' do
|
100
99
|
generate_one_sitemap_model_file
|
101
|
-
assert_equal default_num_items, num_elements(
|
100
|
+
assert_equal default_num_items, num_elements(first_sitemaps_model_file, 'changefreq')
|
102
101
|
end
|
103
102
|
|
104
103
|
should 'contain several priority elements' do
|
105
104
|
generate_one_sitemap_model_file(:priority => 0.2)
|
106
|
-
assert_equal default_num_items, num_elements(
|
105
|
+
assert_equal default_num_items, num_elements(first_sitemaps_model_file, 'priority')
|
107
106
|
end
|
108
107
|
|
109
108
|
should 'have a change frequency of weekly by default' do
|
110
109
|
generate_one_sitemap_model_file
|
111
|
-
assert_equal 'weekly', elements(
|
110
|
+
assert_equal 'weekly', elements(first_sitemaps_model_file, 'changefreq').first.text
|
112
111
|
end
|
113
112
|
|
114
113
|
should 'have a change frequency of daily' do
|
115
114
|
generate_one_sitemap_model_file(:change_frequency => 'daily')
|
116
|
-
assert_equal 'daily', elements(
|
115
|
+
assert_equal 'daily', elements(first_sitemaps_model_file, 'changefreq').first.text
|
117
116
|
end
|
118
117
|
|
119
118
|
should 'be able to use a lambda to specify change frequency' do
|
120
119
|
generate_one_sitemap_model_file(:change_frequency => lambda {|m| m.change_frequency})
|
121
|
-
assert_equal TestModel.new.change_frequency, elements(
|
120
|
+
assert_equal TestModel.new.change_frequency, elements(first_sitemaps_model_file, 'changefreq').first.text
|
122
121
|
end
|
123
122
|
|
124
123
|
should 'have a priority of 0.2' do
|
125
124
|
generate_one_sitemap_model_file(:priority => 0.2)
|
126
|
-
assert_equal '0.2', elements(
|
125
|
+
assert_equal '0.2', elements(first_sitemaps_model_file, 'priority').first.text
|
127
126
|
end
|
128
127
|
|
129
128
|
should 'be able to use a lambda to specify priority' do
|
130
129
|
generate_one_sitemap_model_file(:priority => lambda {|m| m.priority})
|
131
|
-
assert_equal TestModel.new.priority.to_s, elements(
|
130
|
+
assert_equal TestModel.new.priority.to_s, elements(first_sitemaps_model_file, 'priority').first.text
|
132
131
|
end
|
133
132
|
|
134
|
-
should 'contain
|
133
|
+
should 'contain two loc element' do
|
135
134
|
generate_two_model_sitemap_files
|
136
|
-
assert_equal
|
137
|
-
assert_equal
|
135
|
+
assert_equal 2, num_elements(first_sitemaps_model_file, 'loc')
|
136
|
+
assert_equal 2, num_elements(second_sitemaps_model_file, 'loc')
|
138
137
|
end
|
139
138
|
|
140
|
-
should 'contain
|
139
|
+
should 'contain two lastmod element' do
|
141
140
|
generate_two_model_sitemap_files
|
142
|
-
assert_equal
|
143
|
-
assert_equal
|
141
|
+
assert_equal 2, num_elements(first_sitemaps_model_file, 'lastmod')
|
142
|
+
assert_equal 2, num_elements(second_sitemaps_model_file, 'lastmod')
|
144
143
|
end
|
145
144
|
|
146
|
-
should 'contain
|
145
|
+
should 'contain two changefreq elements' do
|
147
146
|
generate_two_model_sitemap_files
|
148
|
-
assert_equal
|
149
|
-
assert_equal
|
147
|
+
assert_equal 2, num_elements(first_sitemaps_model_file, 'changefreq')
|
148
|
+
assert_equal 2, num_elements(second_sitemaps_model_file, 'changefreq')
|
150
149
|
end
|
151
150
|
|
152
|
-
should 'contain
|
151
|
+
should 'contain two priority element' do
|
153
152
|
generate_two_model_sitemap_files(:priority => 0.2)
|
154
|
-
assert_equal
|
155
|
-
assert_equal
|
153
|
+
assert_equal 2, num_elements(first_sitemaps_model_file, 'priority')
|
154
|
+
assert_equal 2, num_elements(second_sitemaps_model_file, 'priority')
|
156
155
|
end
|
157
156
|
|
158
157
|
should 'strip leading slashes from controller paths' do
|
159
158
|
create_sitemap
|
160
159
|
@sitemap.add(TestModel, :path => '/test_controller').generate
|
161
160
|
assert(
|
162
|
-
!elements(
|
161
|
+
!elements(first_sitemaps_model_file, 'loc').first.text.match(/\/\/test_controller\//),
|
163
162
|
'URL does not contain a double-slash before the controller path'
|
164
163
|
)
|
165
164
|
end
|
166
165
|
|
167
166
|
should 'not be gzipped' do
|
168
167
|
generate_one_sitemap_model_file(:gzip => false)
|
169
|
-
assert File.exists?(
|
168
|
+
assert File.exists?(unzipped_first_sitemaps_model_file)
|
170
169
|
end
|
171
170
|
end
|
172
171
|
|
@@ -228,8 +227,8 @@ class BigSitemapTest < Test::Unit::TestCase
|
|
228
227
|
def generate_two_model_sitemap_files(options={})
|
229
228
|
change_frequency = options.delete(:change_frequency)
|
230
229
|
priority = options.delete(:priority)
|
231
|
-
create_sitemap(options.merge(:max_per_sitemap =>
|
232
|
-
add_model(:num_items =>
|
230
|
+
create_sitemap(options.merge(:max_per_sitemap => 2, :batch_size => 1))
|
231
|
+
add_model(:num_items => 4, :change_frequency => change_frequency, :priority => priority)
|
233
232
|
@sitemap.generate
|
234
233
|
end
|
235
234
|
|
@@ -251,20 +250,20 @@ class BigSitemapTest < Test::Unit::TestCase
|
|
251
250
|
"#{sitemaps_dir}/sitemap_index.xml"
|
252
251
|
end
|
253
252
|
|
254
|
-
def
|
255
|
-
"#{unzipped_single_sitemaps_model_file}.gz"
|
256
|
-
end
|
257
|
-
|
258
|
-
def unzipped_single_sitemaps_model_file
|
253
|
+
def unzipped_first_sitemaps_model_file
|
259
254
|
"#{sitemaps_dir}/sitemap_test_models.xml"
|
260
255
|
end
|
261
256
|
|
262
257
|
def first_sitemaps_model_file
|
263
|
-
"#{sitemaps_dir}/
|
258
|
+
"#{sitemaps_dir}/sitemap_test_models.xml.gz"
|
264
259
|
end
|
265
260
|
|
266
261
|
def second_sitemaps_model_file
|
267
|
-
"#{sitemaps_dir}/
|
262
|
+
"#{sitemaps_dir}/sitemap_test_models_1.xml.gz"
|
263
|
+
end
|
264
|
+
|
265
|
+
def third_sitemaps_model_file
|
266
|
+
"#{sitemaps_dir}/sitemap_test_model_2.xml.gz"
|
268
267
|
end
|
269
268
|
|
270
269
|
def sitemaps_dir
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexrabarts-big_sitemap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Rabarts
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-18 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -45,6 +45,8 @@ files:
|
|
45
45
|
- History.txt
|
46
46
|
- README.rdoc
|
47
47
|
- VERSION.yml
|
48
|
+
- lib/big_sitemap
|
49
|
+
- lib/big_sitemap/builder.rb
|
48
50
|
- lib/big_sitemap.rb
|
49
51
|
- test/big_sitemap_test.rb
|
50
52
|
- test/fixtures
|