sitemap_generator 7.0.1 → 7.0.2

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: b26cd553fe4ecc452da26ac6aff3262238f065dc12d9f328959eb3c1edc79f6e
4
- data.tar.gz: 877828e867880ed215df8b3e1f6acb130e4e8c5856a349e61e6af17a5c641ac9
3
+ metadata.gz: 64e5f8cba69093d945ae1e54d6c89fb8da86367ce4bb08a55e19e3652da25cc4
4
+ data.tar.gz: bc7f1dcf2f220d5ed0b8a53062df1411864fecf47fbaf5ed5de3743b099db65c
5
5
  SHA512:
6
- metadata.gz: d957d69f7a4c2fe8e98cecb84045d58fe59f9f8143764c88695a7561a63d54e9d515c80bdc2b2cf496b1704ffb2ca4610b54f5889cb246e2ed45aac88029abdd
7
- data.tar.gz: 884fc7be3809f6670cce09afdddfa64cdf6b4c5b25cdc7ad5c7c3b784d08f83bbc96bdb671a1b52de7f0f59fac8618f1bc83122c01664ee574a52c4edd791699
6
+ metadata.gz: 10a915440acdf9c713f2ba8f5acf0306f88cf2ed898c5b213b6001dadf674e78e950c62aa54d84db91d7b292ccfac8df22b393f98749ed3af4acb6e78767c32e
7
+ data.tar.gz: 1a0fa9ad0f5d374f423db19334498054b45d26e17696bb978ce42442ad7bdcf394305396e8a6252681cfe34ac543bcce92e76f1044b55206acbf565991e0015c
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 7.0.2
2
+
3
+ * Reduce string copies and improve compatibility with `frozen_string_literal`. [#456](https://github.com/kjvarga/sitemap_generator/pull/456)
4
+
1
5
  ### 7.0.1
2
6
 
3
7
  * **Breaking:** Default search engines list is empty. `rake sitemap:refresh` and `ping_search_engines` perform no HTTP pings unless you configure engine URLs on `search_engines` or pass them into `ping_search_engines` (Google’s ping endpoint is deprecated upstream). [#444](https://github.com/kjvarga/sitemap_generator/pull/444)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.0.1
1
+ 7.0.2
@@ -44,12 +44,25 @@ module SitemapGenerator
44
44
  # Call with a SitemapLocation and string data
45
45
  def write(location, raw_data)
46
46
  SitemapGenerator::FileAdapter.new.write(location, raw_data)
47
- s3_object = s3_resource.bucket(@bucket).object(location.path_in_public)
48
- s3_object.upload_file(location.path, {
49
- acl: @acl,
50
- cache_control: @cache_control,
51
- content_type: location[:compress] ? 'application/x-gzip' : 'application/xml'
52
- }.compact)
47
+
48
+ if defined?(Aws::S3::TransferManager)
49
+ client = Aws::S3::Client.new(@options)
50
+ transfer_manager = Aws::S3::TransferManager.new(client: client)
51
+ transfer_manager.upload_file(location.path,
52
+ bucket: @bucket,
53
+ key: location.path_in_public,
54
+ acl: @acl,
55
+ cache_control: @cache_control,
56
+ content_type: location[:compress] ? 'application/x-gzip' : 'application/xml'
57
+ )
58
+ else
59
+ s3_object = s3_resource.bucket(@bucket).object(location.path_in_public)
60
+ s3_object.upload_file(location.path, {
61
+ acl: @acl,
62
+ cache_control: @cache_control,
63
+ content_type: location[:compress] ? 'application/x-gzip' : 'application/xml'
64
+ }.compact)
65
+ end
53
66
  end
54
67
 
55
68
  private
@@ -26,8 +26,7 @@ module SitemapGenerator
26
26
  @location = opts.is_a?(Hash) ? SitemapGenerator::SitemapLocation.new(opts) : opts
27
27
  @link_count = 0
28
28
  @news_count = 0
29
- @xml_content = +'' # XML urlset content
30
- @xml_wrapper_start = +<<-HTML
29
+ @xml_wrapper_start = <<-HTML
31
30
  <?xml version="1.0" encoding="UTF-8"?>
32
31
  <urlset
33
32
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -45,6 +44,7 @@ module SitemapGenerator
45
44
  @xml_wrapper_start.gsub!(/\s+/, ' ').gsub!(/ *> */, '>').strip!
46
45
  @xml_wrapper_end = '</urlset>'
47
46
  @filesize = SitemapGenerator::Utilities.bytesize(@xml_wrapper_start) + SitemapGenerator::Utilities.bytesize(@xml_wrapper_end)
47
+ @xml_content = @xml_wrapper_start
48
48
  @written = false
49
49
  @reserved_name = nil # holds the name reserved from the namer
50
50
  @frozen = false # rather than actually freeze, use this boolean
@@ -141,8 +141,9 @@ module SitemapGenerator
141
141
 
142
142
  finalize! unless finalized?
143
143
  reserve_name
144
- @location.write(@xml_wrapper_start + @xml_content + @xml_wrapper_end, link_count)
145
- @xml_content = @xml_wrapper_start = @xml_wrapper_end = ''
144
+ @xml_content << @xml_wrapper_end
145
+ @location.write(@xml_content, link_count)
146
+ @xml_content = @xml_wrapper_end = ''
146
147
  @written = true
147
148
  end
148
149
 
@@ -12,7 +12,6 @@ module SitemapGenerator
12
12
  @location = opts.is_a?(Hash) ? SitemapGenerator::SitemapIndexLocation.new(opts) : opts
13
13
  @link_count = 0
14
14
  @sitemaps_link_count = 0
15
- @xml_content = +'' # XML urlset content
16
15
  @xml_wrapper_start = +<<-HTML
17
16
  <?xml version="1.0" encoding="UTF-8"?>
18
17
  <sitemapindex
@@ -25,6 +24,7 @@ module SitemapGenerator
25
24
  @xml_wrapper_start.gsub!(/\s+/, ' ').gsub!(/ *> */, '>').strip!
26
25
  @xml_wrapper_end = '</sitemapindex>'
27
26
  @filesize = SitemapGenerator::Utilities.bytesize(@xml_wrapper_start) + SitemapGenerator::Utilities.bytesize(@xml_wrapper_end)
27
+ @xml_content = @xml_wrapper_start
28
28
  @written = false
29
29
  @reserved_name = nil # holds the name reserved from the namer
30
30
  @frozen = false # rather than actually freeze, use this boolean
@@ -2,8 +2,60 @@
2
2
 
3
3
  module SitemapGenerator
4
4
  class Railtie < Rails::Railtie
5
+ # Top level options object to namespace all settings
6
+ config.sitemap = ActiveSupport::OrderedOptions.new
7
+
5
8
  rake_tasks do
6
9
  load 'tasks/sitemap_generator_tasks.rake'
7
10
  end
11
+
12
+ # Recognize existing Rails options as defaults for config.sitemap.*
13
+ initializer 'sitemap_generator.set_configs' do |app|
14
+ # routes.default_url_options takes precedence, falling back to configs
15
+ url_opts = (app.default_url_options || {})
16
+ .with_defaults(config.try(:action_controller).try(:default_url_options) || {})
17
+ .with_defaults(config.try(:action_mailer).try(:default_url_options) || {})
18
+ .with_defaults(config.try(:active_job).try(:default_url_options) || {})
19
+
20
+ config.sitemap.default_host ||= ActionDispatch::Http::URL.full_url_for(url_opts) if url_opts.key?(:host)
21
+
22
+ # Rails defaults action_controller.asset_host and action_mailer.asset_host
23
+ # to the top-level config.asset_host so we get that for free here.
24
+ config.sitemap.sitemaps_host ||= [
25
+ config.try(:action_controller).try(:asset_host),
26
+ config.try(:action_mailer).try(:asset_host)
27
+ ].grep(String).first
28
+
29
+ config.sitemap.compress = config.try(:assets).try(:gzip) if config.sitemap.compress.nil?
30
+
31
+ config.sitemap.public_path ||= app.paths['public'].first
32
+
33
+ # "Compile" config.sitemap options onto the Sitemap class.
34
+ config.after_initialize do
35
+ ActiveSupport.on_load(:sitemap_generator, yield: true) do |sitemap|
36
+ config.sitemap.except(:adapter).each { |k, v| sitemap.public_send("#{k}=", v) }
37
+ end
38
+ end
39
+ end
40
+
41
+ # Allow setting the CONFIG_FILE without relying on env var;
42
+ # (e.g in config/application or environments/*.rb)
43
+ initializer 'sitemap_generator.config_file' do
44
+ if (config_file = config.sitemap.delete(:config_file).presence) && ENV['CONFIG_FILE'].blank?
45
+ ENV['CONFIG_FILE'] = config_file
46
+ end
47
+ end
48
+
49
+ # Allow lazily setting the adapter class without forcing an autoload.
50
+ # (ie. string or symbol name; or Callable (proc/lambda/etc))
51
+ initializer 'sitemap_generator.adapter' do |app|
52
+ config.to_prepare do
53
+ ActiveSupport.on_load(:sitemap_generator) do
54
+ self.adapter = Utilities.find_adapter app.config.sitemap.adapter
55
+ end
56
+ end
57
+ end
8
58
  end
59
+
60
+ ActiveSupport.run_load_hooks(:sitemap_generator, Sitemap)
9
61
  end
@@ -10,46 +10,32 @@ namespace :sitemap do
10
10
  # Require sitemap_generator only. When installed as a plugin the require will fail, so in
11
11
  # that case, load the environment first.
12
12
  task :require do
13
- begin
14
- require 'sitemap_generator'
15
- rescue LoadError => e
16
- if defined?(Rails::VERSION)
17
- Rake::Task['sitemap:require_environment'].invoke
18
- else
19
- raise e
20
- end
21
- end
22
- end
23
-
24
- # Require sitemap_generator after loading the Rails environment. We still need the require
25
- # in case we are installed as a gem and are setup to not automatically be required.
26
- task :require_environment do
27
- if defined?(Rails::VERSION)
28
- Rake::Task['environment'].invoke
29
- end
30
13
  require 'sitemap_generator'
31
14
  end
15
+ # In a Rails app, we need to boot Rails.
16
+ # Ensure gem is required in case it wasn't automatically loaded.
17
+ Rake::Task[:require].enhance([:environment]) if defined?(Rails)
32
18
 
33
19
  desc 'Install a default config/sitemap.rb file'
34
- task install: ['sitemap:require'] do
20
+ task install: :require do
35
21
  SitemapGenerator::Utilities.install_sitemap_rb(verbose)
36
22
  end
37
23
 
38
24
  desc 'Delete all Sitemap files in public/ directory'
39
- task clean: ['sitemap:require'] do
25
+ task clean: :require do
40
26
  SitemapGenerator::Utilities.clean_files
41
27
  end
42
28
 
43
29
  desc 'Generate sitemaps and ping search engines.'
44
- task refresh: ['sitemap:create'] do
30
+ task refresh: :create do
45
31
  SitemapGenerator::Sitemap.ping_search_engines
46
32
  end
47
33
 
48
34
  desc "Generate sitemaps but don't ping search engines."
49
- task 'refresh:no_ping' => ['sitemap:create']
35
+ task 'refresh:no_ping' => :create
50
36
 
51
37
  desc "Generate sitemaps but don't ping search engines. Alias for refresh:no_ping."
52
- task create: ['sitemap:require_environment'] do
38
+ task create: :require do
53
39
  SitemapGenerator::Interpreter.run(config_file: ENV['CONFIG_FILE'], verbose: verbose)
54
40
  end
55
41
  end
@@ -142,9 +142,9 @@ module SitemapGenerator
142
142
  end
143
143
 
144
144
  def titleize(string)
145
- string = string.dup if string.frozen?
146
- string.gsub!(/_/, ' ')
147
- string.split(/(\W)/).map(&:capitalize).join
145
+ result = string.tr('_', ' ')
146
+ result.gsub!(/\b\w/) { |match| match.upcase }
147
+ result
148
148
  end
149
149
 
150
150
  def truthy?(value)
@@ -180,5 +180,29 @@ module SitemapGenerator
180
180
  def bytesize(string)
181
181
  string.respond_to?(:bytesize) ? string.bytesize : string.length
182
182
  end
183
+
184
+ # Looks up an adapter from various sources:
185
+ # 1. symbol/string names are camelized and constantized
186
+ # - :fog becomes SitemapGenerator::FogAdapter
187
+ # - 'external/adapter_class' becomes External::AdapterClass
188
+ # 2. classes are instantiated
189
+ # 3. callables (procs, lambdas, #call) are "called"
190
+ # All steps recurse, so a proc could return a string that names a class that is instantiated.
191
+ #
192
+ # This method is used by the Rails railtie and as such,
193
+ # safely depends on ActiveSupport::Inflector.
194
+ def find_adapter(candidate)
195
+ if candidate.is_a?(Symbol) || candidate.is_a?(String)
196
+ candidate.to_s.camelize.then { |name|
197
+ "SitemapGenerator::#{name}Adapter".safe_constantize || name.safe_constantize
198
+ }.then { |c| find_adapter(c) }
199
+ elsif candidate.respond_to?(:new)
200
+ find_adapter candidate.new
201
+ elsif candidate.respond_to?(:call)
202
+ find_adapter candidate.call
203
+ else
204
+ candidate
205
+ end
206
+ end
183
207
  end
184
208
  end
@@ -40,18 +40,21 @@ module SitemapGenerator
40
40
  }
41
41
 
42
42
  # Lazy-initialize the LinkSet instance
43
- Sitemap = (Class.new do
44
- def method_missing(*args, &block)
45
- (@link_set ||= reset!).send(*args, &block)
43
+ Sitemap = (Config = Class.new do
44
+ # Use a new LinkSet instance
45
+ def reset!
46
+ @link_set = LinkSet.new
46
47
  end
47
48
 
48
- def respond_to?(name, include_private = false)
49
- (@link_set ||= reset!).respond_to?(name, include_private)
49
+ private
50
+
51
+ def method_missing(name, *args, &block)
52
+ @link_set ||= reset!
53
+ @link_set.respond_to?(name, true) ? @link_set.__send__(name, *args, &block) : super
50
54
  end
51
55
 
52
- # Use a new LinkSet instance
53
- def reset!
54
- @link_set = LinkSet.new
56
+ def respond_to_missing?(name, include_private = false)
57
+ (@link_set ||= reset!).respond_to?(name, include_private) || super
55
58
  end
56
59
  end).new
57
60
  end
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.0.1
4
+ version: 7.0.2
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-04-28 00:00:00.000000000 Z
11
+ date: 2026-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -82,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: '0'
85
+ version: '2.6'
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="