sitemap_generator 3.2.1 → 3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- sitemap_generator (3.2.1)
4
+ sitemap_generator (3.3)
5
5
  builder
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -69,6 +69,7 @@ Does your website use SitemapGenerator to generate Sitemaps? Where would you be
69
69
 
70
70
  ## Changelog
71
71
 
72
+ * v3.3: **Support creating sitemaps with no index file**. A big thank-you to [Eric Hochberger][ehoch] for generously paying for this feature.
72
73
  * v3.2.1: Fix syntax error in SitemapGenerator::S3Adapter
73
74
  * v3.2: **Support mobile tags**, **SitemapGenerator::S3Adapter** a simple S3 adapter which uses Fog and doesn't require CarrierWave; Remove Ask from the sitemap ping because the service has been shutdown; [Turn off `include_index`][include_index_change] by default; Fix the news XML namespace; Only include autoplay attribute if present
74
75
  * v3.1.1: Bugfix: Groups inherit current adapter
@@ -261,6 +262,12 @@ task :refresh_sitemaps do
261
262
  end
262
263
  ```
263
264
 
265
+ ### Sitemaps with no Index File
266
+
267
+ Sometimes you may not want the sitemap index file to be automatically created, for example when you have a small site with only one sitemap file. Or you may only want an index file created if you have more than one sitemap file. Or you may never want the index file to be created.
268
+
269
+ To handle these cases, take a look at the `create_index` option in the Sitemap Options section below.
270
+
264
271
  ### Upload Sitemaps to a Remote Host
265
272
 
266
273
  > SitemapGenerator::S3Adapter is a simple S3 adapter which was added in v3.2 which
@@ -629,6 +636,8 @@ The options passed to `group` only apply to the links and sitemaps generated in
629
636
 
630
637
  The following options are supported:
631
638
 
639
+ * `create_index` - Supported values: `true`, `false`, `:auto`. Default: `true`. Whether to create a sitemap index file. If `true` an index file is always created regardless of how many sitemap files are generated. If `false` an index file is never created. If `:auto` an index file is created only when you have more than one sitemap file (i.e. you have added more than 50,000 - `SitemapGenerator::MAX_SITEMAP_LINKS` - links).
640
+
632
641
  * `default_host` - String. Required. **Host including protocol** to use when building a link to add to your sitemap. For example `http://example.com`. Calling `add '/home'` would then generate the URL `http://example.com/home` and add that to the sitemap. You can pass a `:host` option in your call to `add` to override this value on a per-link basis. For example calling `add '/home', :host => 'https://example.com'` would generate the URL `https://example.com/home`, for that link only.
633
642
 
634
643
  * `filename` - Symbol. The **base name for the files** that will be generated. The default value is `:sitemap`. This yields sitemaps with names like `sitemap1.xml.gz`, `sitemap2.xml.gz`, `sitemap3.xml.gz` etc, and a sitemap index named `sitemap_index.xml.gz`. If we now set the value to `:geo` the sitemaps would be named `geo1.xml.gz`, `geo2.xml.gz`, `geo3.xml.gz` etc, and the sitemap index would be named `geo_index.xml.gz`.
@@ -860,6 +869,7 @@ Tested and working on:
860
869
 
861
870
  ## Thanks (in no particular order)
862
871
 
872
+ * [Eric Hochberger][ehoch]
863
873
  * [Rodrigo Flores](https://github.com/rodrigoflores) for News sitemaps
864
874
  * [Alex Soto](http://github.com/apsoto) for Video sitemaps
865
875
  * [Alexadre Bini](http://github.com/alexandrebini) for Image sitemaps
@@ -890,3 +900,4 @@ Copyright (c) 2009 Karl Varga released under the MIT license
890
900
  [news_tags]:http://www.google.com/support/news_pub/bin/answer.py?answer=74288
891
901
  [remote_hosts]:https://github.com/kjvarga/sitemap_generator/wiki/Generate-Sitemaps-on-read-only-filesystems-like-Heroku
892
902
  [include_index_change]:https://github.com/kjvarga/sitemap_generator/issues/70
903
+ [ehoch]:https://github.com/ehoch
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 3.3
@@ -74,6 +74,15 @@ module SitemapGenerator
74
74
  # sitemap_url - a SitemapUrl instance
75
75
  # sitemap, options - a Sitemap instance and options hash
76
76
  # path, options - a path for the URL and options hash
77
+ #
78
+ # KJV: We should be using the host from the Location object if no host is
79
+ # specified in the call to add(). The issue is noticeable when we add links
80
+ # to a sitemap direct as in the following example:
81
+ # ls = SitemapGenerator::LinkSet.new(:default_host => 'http://abc.com')
82
+ # ls.sitemap_index.add('/link')
83
+ # This raises a RuntimeError: Cannot generate a url without a host
84
+ # Expected: the link added to the sitemap should use the host from its
85
+ # location object if no host has been specified.
77
86
  def add(link, options={})
78
87
  raise SitemapGenerator::SitemapFinalizedError if finalized?
79
88
 
@@ -25,11 +25,11 @@ module SitemapGenerator
25
25
  @filesize = bytesize(@xml_wrapper_start) + bytesize(@xml_wrapper_end)
26
26
  end
27
27
 
28
- # Finalize sitemaps as they are added to the index
28
+ # Finalize sitemaps as they are added to the index.
29
29
  def add(link, options={})
30
30
  if file = link.is_a?(SitemapFile) && link
31
31
  @sitemaps_link_count += file.link_count
32
- file.finalize!
32
+ file.finalize! unless file.finalized?
33
33
  end
34
34
  super(SitemapGenerator::Builder::SitemapIndexUrl.new(link, options))
35
35
  end
@@ -8,7 +8,7 @@ module SitemapGenerator
8
8
  @@new_location_opts = [:filename, :sitemaps_path, :sitemaps_namer]
9
9
 
10
10
  attr_reader :default_host, :sitemaps_path, :filename
11
- attr_accessor :verbose, :yahoo_app_id, :include_root, :include_index, :sitemaps_host, :adapter, :yield_sitemap
11
+ attr_accessor :verbose, :yahoo_app_id, :include_root, :include_index, :sitemaps_host, :adapter, :yield_sitemap, :create_index
12
12
 
13
13
  # Create a new sitemap index and sitemap files. Pass a block calls to the following
14
14
  # methods:
@@ -99,6 +99,15 @@ module SitemapGenerator
99
99
  #
100
100
  # * <tt>:verbose</tt> - If +true+, output a summary line for each sitemap and sitemap
101
101
  # index that is created. Default is +false+.
102
+ #
103
+ # * <tt>:create_index</tt> - Supported values: `true`, `false`, `:auto`. Default: `true`.
104
+ # Whether to create a sitemap index file. If `true` an index file is always created,
105
+ # regardless of how many links are in your sitemap. If `false` an index file is never
106
+ # created. If `:auto` an index file is created only if your sitemap has more than
107
+ # 50,000 (or SitemapGenerator::MAX_SITEMAP_LINKS) links.
108
+ #
109
+ # KJV: When adding a new option be sure to include it in `options_for_group()` if
110
+ # the option should be inherited by groups.
102
111
  def initialize(options={})
103
112
  options = SitemapGenerator::Utilities.reverse_merge(options,
104
113
  :include_root => true,
@@ -108,7 +117,8 @@ module SitemapGenerator
108
117
  :google => "http://www.google.com/webmasters/sitemaps/ping?sitemap=%s",
109
118
  :bing => "http://www.bing.com/webmaster/ping.aspx?siteMap=%s",
110
119
  :sitemap_writer => "http://www.sitemapwriter.com/notify.php?crawler=all&url=%s"
111
- }
120
+ },
121
+ :create_index => true
112
122
  )
113
123
  options.each_pair { |k, v| instance_variable_set("@#{k}".to_sym, v) }
114
124
 
@@ -356,6 +366,9 @@ module SitemapGenerator
356
366
  opts.delete(:public_path)
357
367
 
358
368
  # Reverse merge the current settings
369
+ # KJV: This hash could be a problem because it needs to be maintained
370
+ # when new options are added, but can easily be missed. We really could
371
+ # do with a separate SitemapOptions class.
359
372
  current_settings = [
360
373
  :include_root,
361
374
  :include_index,
@@ -364,7 +377,8 @@ module SitemapGenerator
364
377
  :sitemaps_host,
365
378
  :verbose,
366
379
  :default_host,
367
- :adapter
380
+ :adapter,
381
+ :create_index
368
382
  ].inject({}) do |hash, key|
369
383
  if value = instance_variable_get(:"@#{key}")
370
384
  hash[key] = value
@@ -399,8 +413,12 @@ module SitemapGenerator
399
413
  # block passed to create() is empty the default links are still included in the
400
414
  # sitemap.
401
415
  def finalize_sitemap!
402
- add_default_links if !@added_default_links && !@created_group
403
416
  return if sitemap.finalized? || sitemap.empty? && @created_group
417
+ add_default_links if !@added_default_links && !@created_group
418
+ # This will finalize it. We add to the index even if not creating an index because
419
+ # the index keeps track of how many links are in our sitemaps and we need this info
420
+ # for the summary line. If not for that problem, I would add the sitemap to
421
+ # the index only if create_index is truthy.
404
422
  add_to_index(sitemap)
405
423
  output(sitemap.summary)
406
424
  end
@@ -408,7 +426,8 @@ module SitemapGenerator
408
426
  # Finalize a sitemap index and output a summary line. Do nothing if it has already
409
427
  # been finalized.
410
428
  def finalize_sitemap_index!
411
- return if @protect_index || sitemap_index.finalized?
429
+ return if @protect_index || !@create_index || sitemap_index.finalized?
430
+ return if @create_index == :auto && sitemap_index.link_count <= 1
412
431
  sitemap_index.finalize!
413
432
  output(sitemap_index.summary)
414
433
  end
@@ -20,12 +20,13 @@ describe SitemapGenerator::LinkSet do
20
20
  let(:ls) { SitemapGenerator::LinkSet.new }
21
21
 
22
22
  default_options = {
23
- :filename => :sitemap,
23
+ :filename => :sitemap,
24
24
  :sitemaps_path => nil,
25
- :public_path => SitemapGenerator.app.root + 'public/',
26
- :default_host => nil,
25
+ :public_path => SitemapGenerator.app.root + 'public/',
26
+ :default_host => nil,
27
27
  :include_index => false,
28
- :include_root => true
28
+ :include_root => true,
29
+ :create_index => true
29
30
  }
30
31
 
31
32
  default_options.each do |option, value|
@@ -369,6 +370,19 @@ describe SitemapGenerator::LinkSet do
369
370
  end
370
371
  end
371
372
 
373
+ describe "create_index" do
374
+ it "should inherit the value" do
375
+ ls.group.create_index.should == ls.create_index
376
+ ls.create_index = :some_value
377
+ ls.group.create_index.should == :some_value
378
+ end
379
+
380
+ it "should set the value" do
381
+ group = ls.group(:create_index => :some_value)
382
+ group.create_index.should == :some_value
383
+ end
384
+ end
385
+
372
386
  describe "should share the current sitemap" do
373
387
  it "if only default_host is passed" do
374
388
  group = ls.group(:default_host => 'http://newhost.com')
@@ -391,11 +405,6 @@ describe SitemapGenerator::LinkSet do
391
405
  end
392
406
 
393
407
  describe "finalizing" do
394
- it "should finalize the sitemaps if a block is passed" do
395
- @group = ls.group
396
- @group.sitemap.finalized?.should be_false
397
- end
398
-
399
408
  it "should only finalize the sitemaps if a block is passed" do
400
409
  @group = ls.group
401
410
  @group.sitemap.finalized?.should be_false
@@ -531,6 +540,11 @@ describe SitemapGenerator::LinkSet do
531
540
  ls.create(options)
532
541
  options.should == { :filename => 'sitemaptest', :verbose => false }
533
542
  end
543
+
544
+ it "should set create_index" do
545
+ ls.create(:create_index => :auto)
546
+ ls.create_index.should == :auto
547
+ end
534
548
  end
535
549
 
536
550
  describe "reset!" do
@@ -706,4 +720,63 @@ describe SitemapGenerator::LinkSet do
706
720
  end
707
721
  end
708
722
  end
723
+
724
+ describe "create_index" do
725
+ describe "when false" do
726
+ let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :create_index => false) }
727
+
728
+ it "should not finalize the index" do
729
+ ls.send(:finalize_sitemap_index!)
730
+ ls.sitemap_index.finalized?.should be_false
731
+ end
732
+
733
+ it "should still add finalized sitemaps to the index (but the index is never finalized)" do
734
+ ls.expects(:add_to_index).with(ls.sitemap).once
735
+ ls.send(:finalize_sitemap!)
736
+ end
737
+ end
738
+
739
+ describe "when true" do
740
+ let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :create_index => true) }
741
+
742
+ it "should always finalize the index" do
743
+ ls.send(:finalize_sitemap_index!)
744
+ ls.sitemap_index.finalized?.should be_true
745
+ end
746
+
747
+ it "should add finalized sitemaps to the index" do
748
+ ls.expects(:add_to_index).with(ls.sitemap).once
749
+ ls.send(:finalize_sitemap!)
750
+ end
751
+ end
752
+
753
+ describe "when :auto" do
754
+ let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :create_index => :auto) }
755
+
756
+ it "should not finalize the index when it is empty" do
757
+ ls.sitemap_index.empty?.should be_true
758
+ ls.send(:finalize_sitemap_index!)
759
+ ls.sitemap_index.finalized?.should be_false
760
+ end
761
+
762
+ it "should add finalized sitemaps to the index" do
763
+ ls.expects(:add_to_index).with(ls.sitemap).once
764
+ ls.send(:finalize_sitemap!)
765
+ end
766
+
767
+ it "should not finalize the index when it has only one link" do
768
+ ls.sitemap_index.add '/test', :host => default_host
769
+ ls.sitemap_index.empty?.should be_false
770
+ ls.send(:finalize_sitemap_index!)
771
+ ls.sitemap_index.finalized?.should be_false
772
+ end
773
+
774
+ it "should finalize the index when it has more than one link" do
775
+ ls.sitemap_index.add '/test1', :host => default_host
776
+ ls.sitemap_index.add '/test2', :host => default_host
777
+ ls.send(:finalize_sitemap_index!)
778
+ ls.sitemap_index.finalized?.should be_true
779
+ end
780
+ end
781
+ end
709
782
  end
@@ -202,6 +202,100 @@ describe "SitemapGenerator" do
202
202
  end
203
203
  end
204
204
 
205
+ describe "create_index" do
206
+
207
+ before :each do
208
+ clean_sitemap_files_from_rails_app
209
+ end
210
+
211
+ describe "when true" do
212
+ let(:ls) { SitemapGenerator::LinkSet.new(:include_root => false, :default_host => 'http://example.com', :create_index => true) }
213
+
214
+ it "should always create index" do
215
+ ls.create { }
216
+ file_should_exist(rails_path('public/sitemap_index.xml.gz'))
217
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
218
+ file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
219
+ end
220
+
221
+ it "should always create index" do
222
+ with_max_links(1) do
223
+ ls.create { add('/one') }
224
+ end
225
+ file_should_exist(rails_path('public/sitemap_index.xml.gz'))
226
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
227
+ file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
228
+ end
229
+
230
+ it "should always create index" do
231
+ with_max_links(1) do
232
+ ls.create { add('/one'); add('/two') }
233
+ end
234
+ file_should_exist(rails_path('public/sitemap_index.xml.gz'))
235
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
236
+ file_should_exist(rails_path('public/sitemap2.xml.gz'))
237
+ end
238
+ end
239
+
240
+ describe "when false" do
241
+ let(:ls) { SitemapGenerator::LinkSet.new(:include_root => false, :default_host => 'http://example.com', :create_index => false) }
242
+
243
+ it "should never create index" do
244
+ ls.create { }
245
+ file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
246
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
247
+ file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
248
+ end
249
+
250
+ it "should never create index" do
251
+ with_max_links(1) do
252
+ ls.create { add('/one') }
253
+ end
254
+ file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
255
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
256
+ file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
257
+ end
258
+
259
+ it "should never create index" do
260
+ with_max_links(1) do
261
+ ls.create { add('/one'); add('/two') }
262
+ end
263
+ file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
264
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
265
+ file_should_exist(rails_path('public/sitemap2.xml.gz'))
266
+ end
267
+ end
268
+
269
+ describe "when :auto" do
270
+ let(:ls) { SitemapGenerator::LinkSet.new(:include_root => false, :default_host => 'http://example.com', :create_index => :auto) }
271
+
272
+ it "should not create index if one sitemap file" do
273
+ ls.create { }
274
+ file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
275
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
276
+ file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
277
+ end
278
+
279
+ it "should not create index if one sitemap file" do
280
+ with_max_links(1) do
281
+ ls.create { add('/one') }
282
+ end
283
+ file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
284
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
285
+ file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
286
+ end
287
+
288
+ it "should create index if more than one sitemap file" do
289
+ with_max_links(1) do
290
+ ls.create { add('/one'); add('/two') }
291
+ end
292
+ file_should_exist(rails_path('public/sitemap_index.xml.gz'))
293
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
294
+ file_should_exist(rails_path('public/sitemap2.xml.gz'))
295
+ end
296
+ end
297
+ end
298
+
205
299
  protected
206
300
 
207
301
  #
@@ -229,7 +323,7 @@ describe "SitemapGenerator" do
229
323
 
230
324
  # Better would be to just invoke the environment task and use
231
325
  # the interpreter.
232
- def execute_sitemap_config
233
- SitemapGenerator::Interpreter.run
326
+ def execute_sitemap_config(opts={})
327
+ SitemapGenerator::Interpreter.run(opts)
234
328
  end
235
329
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitemap_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: '3.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-11 00:00:00.000000000Z
13
+ date: 2012-10-03 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mocha
17
- requirement: &70187786258340 !ruby/object:Gem::Requirement
17
+ requirement: &70307560374840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70187786258340
25
+ version_requirements: *70307560374840
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: nokogiri
28
- requirement: &70187786257900 !ruby/object:Gem::Requirement
28
+ requirement: &70307560374400 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70187786257900
36
+ version_requirements: *70307560374400
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70187786257480 !ruby/object:Gem::Requirement
39
+ requirement: &70307560373980 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70187786257480
47
+ version_requirements: *70307560373980
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: builder
50
- requirement: &70187786257060 !ruby/object:Gem::Requirement
50
+ requirement: &70307560373560 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70187786257060
58
+ version_requirements: *70307560373560
59
59
  description: SitemapGenerator is an XML Sitemap generator written in Ruby with automatic
60
60
  Rails integration. It supports Video, News, Image and Geo sitemaps and includes
61
61
  Rake tasks for managing your sitemaps.
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  segments:
149
149
  - 0
150
- hash: -4223635251889236113
150
+ hash: -845779486658727923
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements:
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  segments:
158
158
  - 0
159
- hash: -4223635251889236113
159
+ hash: -845779486658727923
160
160
  requirements: []
161
161
  rubyforge_project:
162
162
  rubygems_version: 1.8.10