sitemap_generator 7.1.0 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b18ba1ba719a39678730f1b1e4c76f9162725c3cf0b355510738a5586e566eff
4
- data.tar.gz: 67dc99385dee6022f06a66945c75b24497bea9f9fc573c1ab866fcb583dc5c0e
3
+ metadata.gz: 6c259fa0f3a68d9e8595e387643000a6c7cde213ed6fcc8c66963428c945cefd
4
+ data.tar.gz: 8dc85d783b0018d2c13c9d0146fe59920160ebcca120d8693ef03c6d9958ddf0
5
5
  SHA512:
6
- metadata.gz: 97fb528cf9d949463a89f3ded008df4516766aa978462954184aca1aae83fa6aa590d6efc9e81fb2f7d6a3f8f82b7fcbe0c07a5a855539c23ba86bd1ec7ae552
7
- data.tar.gz: cba27e4d71b77be16ce19e6cd0dae400d2a86570e8e0d637b102c83c841440cf86d9e0aa5a6e7365a3a3885ef622fd26e5c581d68d25f437eff6f78a5aacdd2f
6
+ metadata.gz: b4fa4c6e8e0b2ef87e8d2af947719e7d902d74021e16f4a6c6bc51e5a9b8e16410858b06b0327ed7df514c270af032e3ec32342022ff252b2cf1d6da352200f3
7
+ data.tar.gz: d3dbfeed32002542b17695efbaebff375bdf28fb9b847910c16b033b4ed30478cbbec5f31e4f341be2416aaa3e33af16b0aef202631c22ac550538a48801cbe2
data/CHANGES.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.1.1
4
+
5
+ * Fix: `rake sitemap:clean` (`clean_files`) now respects the configured `sitemaps_path`/`public_path` and also removes uncompressed `.xml` sitemaps, instead of only deleting hardcoded `public/sitemap*.xml.gz` files. [#474](https://github.com/kjvarga/sitemap_generator/issues/474) [#502](https://github.com/kjvarga/sitemap_generator/pull/502)
6
+ * Fix: `SitemapGenerator::Interpreter` now respects `ActionController::Base.default_url_options`, so Rails URL helpers honor globally configured defaults (e.g. `:protocol`, `:port`) instead of ignoring them. [#355](https://github.com/kjvarga/sitemap_generator/issues/355) [#507](https://github.com/kjvarga/sitemap_generator/pull/507)
7
+ * Fix: Non-ASCII characters in URL paths are now percent-encoded in the `<loc>` element, so generated sitemaps conform to the sitemap protocol. [#346](https://github.com/kjvarga/sitemap_generator/issues/346) [#506](https://github.com/kjvarga/sitemap_generator/pull/506)
8
+ * Fix: Relative alternate hreflang hrefs (starting with `/`) are now expanded to absolute URLs using the configured host, producing valid sitemap XML instead of broken relative links. [#343](https://github.com/kjvarga/sitemap_generator/issues/343) [#504](https://github.com/kjvarga/sitemap_generator/pull/504)
9
+ * Fix: `SitemapGenerator.verbose = false` is now respected by `rake sitemap:refresh` and other rake tasks, silencing output as configured. [#332](https://github.com/kjvarga/sitemap_generator/issues/332) [#503](https://github.com/kjvarga/sitemap_generator/pull/503)
10
+ * Fix: Sitemap file `lastmod` is now captured at write time rather than read back via `File.mtime`, fixing incorrect timestamps and improving compatibility with time-freezing test helpers. [#508](https://github.com/kjvarga/sitemap_generator/pull/508)
11
+ * Fix: URL `lastmod` now defaults to `Time.zone.now` under Rails (falling back to `Time.now` otherwise), so the configured Rails timezone and time-freezing helpers like `travel_to` are respected instead of always using system local time. [#422](https://github.com/kjvarga/sitemap_generator/issues/422) [#505](https://github.com/kjvarga/sitemap_generator/pull/505)
12
+ * Internal: Enable RuboCop on the spec suite (previously fully excluded), fix real bugs the linting surfaced along the way (always-passing tests with no assertions, a latent `NameError`, broken path comparisons), and resolve all temporary RuboCop spec-suite exclusions. [#510](https://github.com/kjvarga/sitemap_generator/pull/510) [#511](https://github.com/kjvarga/sitemap_generator/pull/511) [#512](https://github.com/kjvarga/sitemap_generator/pull/512) [#513](https://github.com/kjvarga/sitemap_generator/pull/513) [#514](https://github.com/kjvarga/sitemap_generator/pull/514)
13
+
3
14
  ## 7.1.0
4
15
 
5
16
  * **Breaking:** `SitemapGenerator::FileAdapter#plain` has been removed. It was an internal helper inlined into `#write` to fix a file descriptor leak; any code calling it directly should call `#write` instead. [#492](https://github.com/kjvarga/sitemap_generator/pull/492)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.1.0
1
+ 7.1.1
@@ -56,14 +56,11 @@ module SitemapGenerator
56
56
  @frozen = false # rather than actually freeze, use this boolean
57
57
  end
58
58
 
59
- # If a name has been reserved, use the last modified time from the file.
60
- # Otherwise return nil. We don't want to prematurely assign a name
61
- # for this sitemap if one has not yet been reserved, because we may
62
- # mess up the name-assignment sequence.
59
+ # Return the time the sitemap was written, or nil if it has not been written yet.
60
+ # Returning nil before write prevents prematurely reserving a name in the
61
+ # namer sequence.
63
62
  def lastmod
64
- File.mtime(location.path) if location.reserved_name?
65
- rescue StandardError
66
- nil
63
+ @lastmod if location.reserved_name?
67
64
  end
68
65
 
69
66
  def empty?
@@ -149,6 +146,7 @@ module SitemapGenerator
149
146
  reserve_name
150
147
  @xml_content << @xml_wrapper_end
151
148
  @location.write(@xml_content, link_count)
149
+ @lastmod = SitemapGenerator::Utilities.current_time
152
150
  @xml_content = @xml_wrapper_end = ''
153
151
  @written = true
154
152
  end
@@ -8,7 +8,7 @@ module SitemapGenerator
8
8
  class SitemapIndexUrl < SitemapUrl
9
9
  def initialize(path, options = {})
10
10
  if (index = path.is_a?(SitemapGenerator::Builder::SitemapIndexFile) && path)
11
- options = SitemapGenerator::Utilities.reverse_merge(options, host: index.location.host, lastmod: Time.now,
11
+ options = SitemapGenerator::Utilities.reverse_merge(options, host: index.location.host, lastmod: SitemapGenerator::Utilities.current_time,
12
12
  priority: 1.0)
13
13
  path = index.location.path_in_public
14
14
  end
@@ -52,7 +52,7 @@ module SitemapGenerator
52
52
  options,
53
53
  priority: 0.5,
54
54
  changefreq: 'weekly',
55
- lastmod: Time.now,
55
+ lastmod: SitemapGenerator::Utilities.current_time,
56
56
  images: [],
57
57
  news: {},
58
58
  videos: [],
@@ -69,7 +69,7 @@ module SitemapGenerator
69
69
  alternate.is_a?(Array) ? options[:alternates].concat(alternate) : options[:alternates] << alternate
70
70
  end
71
71
 
72
- path = path.to_s.sub(%r{^/}, '')
72
+ path = encode_non_ascii(path.to_s.sub(%r{^/}, ''))
73
73
  loc = path.empty? ? options[:host] : "#{options[:host].to_s.sub(%r{/$}, '')}/#{path}"
74
74
  merge!(
75
75
  priority: options[:priority],
@@ -82,7 +82,7 @@ module SitemapGenerator
82
82
  news: prepare_news(options[:news]),
83
83
  videos: options[:videos],
84
84
  mobile: options[:mobile],
85
- alternates: options[:alternates],
85
+ alternates: prepare_alternates(options[:alternates], options[:host]),
86
86
  pagemap: options[:pagemap]
87
87
  )
88
88
  end
@@ -221,6 +221,20 @@ module SitemapGenerator
221
221
  news
222
222
  end
223
223
 
224
+ # Return an Array of alternate option Hashes with relative hrefs expanded to absolute URLs.
225
+ def prepare_alternates(alternates, host)
226
+ alternates.map do |alt|
227
+ next alt unless alt.is_a?(Hash)
228
+
229
+ href = alt[:href].to_s
230
+ if href.start_with?('/')
231
+ alt.merge(href: URI.join(host, href).to_s)
232
+ else
233
+ alt
234
+ end
235
+ end
236
+ end
237
+
224
238
  # Return an Array of image option Hashes suitable to be parsed by SitemapGenerator::Builder::SitemapFile
225
239
  def prepare_images(images, host)
226
240
  images.delete_if { |key, _value| key[:loc].nil? }
@@ -282,6 +296,14 @@ module SitemapGenerator
282
296
  def format_float(value)
283
297
  value.is_a?(String) ? value : format('%0.1f', value)
284
298
  end
299
+
300
+ private
301
+
302
+ # Percent-encode non-ASCII bytes in a path segment, leaving already-encoded %XX sequences untouched.
303
+ # Applied to paths only — not the host — IDN hostnames require punycode, not percent-encoding.
304
+ def encode_non_ascii(str)
305
+ str.gsub(/[^\x00-\x7F]/) { |c| c.bytes.map { |b| format('%%%02X', b) }.join }
306
+ end
285
307
  end
286
308
  end
287
309
  end
@@ -27,6 +27,12 @@ module SitemapGenerator
27
27
  eval(&block) if block_given? # rubocop:disable Security/Eval
28
28
  end
29
29
 
30
+ def default_url_options
31
+ return {} unless defined?(ActionController::Base)
32
+
33
+ ActionController::Base.default_url_options || {}
34
+ end
35
+
30
36
  def add(*args)
31
37
  @linkset.add(*args)
32
38
  end
@@ -433,7 +433,7 @@ module SitemapGenerator
433
433
  # in an instance variable.
434
434
  def add_default_links
435
435
  @added_default_links = true
436
- link_options = { lastmod: Time.now, priority: 1.0 }
436
+ link_options = { priority: 1.0, lastmod: SitemapGenerator::Utilities.current_time }
437
437
  add('/', link_options) if include_root?
438
438
  return unless include_index?
439
439
 
@@ -18,6 +18,8 @@ namespace :sitemap do
18
18
 
19
19
  desc 'Install a default config/sitemap.rb file'
20
20
  task install: :require do
21
+ # Uses Rake's verbose flag intentionally — this is a file installation utility
22
+ # where Rake's -v/--verbose flag is the appropriate control mechanism.
21
23
  SitemapGenerator::Utilities.install_sitemap_rb(verbose)
22
24
  end
23
25
 
@@ -36,6 +38,6 @@ namespace :sitemap do
36
38
 
37
39
  desc "Generate sitemaps but don't ping search engines. Alias for refresh:no_ping."
38
40
  task create: :require do
39
- SitemapGenerator::Interpreter.run(config_file: ENV.fetch('CONFIG_FILE', nil), verbose: verbose)
41
+ SitemapGenerator::Interpreter.run(config_file: ENV.fetch('CONFIG_FILE', nil))
40
42
  end
41
43
  end
@@ -28,7 +28,12 @@ module SitemapGenerator
28
28
 
29
29
  # Clean sitemap files in output directory.
30
30
  def clean_files
31
- FileUtils.rm(Dir[SitemapGenerator.app.root + 'public/sitemap*.xml.gz']) # rubocop:disable Style/StringConcatenation
31
+ location = SitemapGenerator::Sitemap.sitemap_location
32
+ dir = location.directory
33
+ base = SitemapGenerator::Sitemap.filename.to_s
34
+ return if base.empty?
35
+
36
+ FileUtils.rm(Dir[File.join(dir, "#{base}*.xml.gz"), File.join(dir, "#{base}*.xml")])
32
37
  end
33
38
 
34
39
  # Validate all keys in a hash match *valid keys, raising ArgumentError on a
@@ -184,6 +189,12 @@ module SitemapGenerator
184
189
  end
185
190
  end
186
191
 
192
+ # Return the current time, using Time.zone if available (Rails), otherwise Time.now.
193
+ def current_time
194
+ zone = defined?(Time.zone) && Time.zone
195
+ zone ? zone.now : Time.now
196
+ end
197
+
187
198
  # Return the bytesize length of the string. Ruby 1.8.6 compatible.
188
199
  def bytesize(string)
189
200
  string.respond_to?(:bytesize) ? string.bytesize : string.length
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitemap_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 7.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Varga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-07-03 00:00:00.000000000 Z
11
+ date: 2026-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder