indexmap 0.7.1 → 0.8.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: 64a9d1c671519fea6ba6a46b7f67daed2784ad5aaccf2594dc3aa0a374f55854
4
- data.tar.gz: 50f6bc13a8097194dec9736b96c8cc6baf0f76429edf0175372aee97991c63f0
3
+ metadata.gz: 2f78184d7ab33df85d653a915d6b9e42f7c5409fe0e01bb81991b358616cf4f5
4
+ data.tar.gz: 739a22b6445ca41a090d296c7c30ea3e96fd08c120fce59dbca41ca76c5c57b5
5
5
  SHA512:
6
- metadata.gz: 2ce92a1da076303265c03ff833585b069215c8417b134407850770c64ae04b3ab93fcf894484874e710e304c6b3c94f19247d70073aaa6ba5e170f70212e4992
7
- data.tar.gz: 991f39cd9db707dd79e7a404e636aaea8c8a1db07ce5b59d2daf9d73c33a55d39c252d6edef2adf8fc98ea22e153f8619aee4f67f9fd11c3fccf56b473bb1ffa
6
+ metadata.gz: a78824d383358e1bbc36ebccc37e5cda6d2311a1d37cfd5941f09c7f3a39d30a8023b94dfffdb812b37dd95e754ef908e6a73a3368a861bb761c960b192e19ef
7
+ data.tar.gz: 89b5cca3351e953d92a7d0b712b56a7856c47564168e759dcd6dbb5e672e7d714ef62e864f1172bc4b4cbedb129801da9bae68fd1542d8d773f77a13314cfc63
data/CHANGELOG.md CHANGED
@@ -5,6 +5,31 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.8.1] - 2026-07-21
9
+
10
+
11
+ ### Added
12
+
13
+ - add lazy install generator ([#17](https://github.com/ethos-link/indexmap/pull/17))
14
+
15
+
16
+
17
+ ## [0.8.0] - 2026-07-21
18
+
19
+
20
+ ### Added
21
+
22
+ - harden git commit ([#15](https://github.com/ethos-link/indexmap/pull/15))
23
+
24
+
25
+
26
+
27
+ ### Changed
28
+
29
+ - lazy load search console dependencies ([#16](https://github.com/ethos-link/indexmap/pull/16))
30
+
31
+
32
+
8
33
  ## [0.7.1] - 2026-05-31
9
34
 
10
35
 
data/README.md CHANGED
@@ -19,9 +19,13 @@ By default, `indexmap` writes a sitemap index plus one or more child sitemap fil
19
19
  Add this line to your application's Gemfile:
20
20
 
21
21
  ```ruby
22
- gem "indexmap"
22
+ gem "indexmap", require: false
23
23
  ```
24
24
 
25
+ `require: false` keeps sitemap generation and search-engine clients out of web
26
+ process boot. Require `indexmap` at the application boundary that generates a
27
+ sitemap, or use the task setup below.
28
+
25
29
  And then execute:
26
30
 
27
31
  ```bash
@@ -68,7 +72,18 @@ Indexmap::Writer.new(
68
72
 
69
73
  ## Rails Usage
70
74
 
71
- In an initializer:
75
+ Run the install generator after adding the gem:
76
+
77
+ ```bash
78
+ bin/rails generate indexmap:install
79
+ ```
80
+
81
+ The generator creates `config/initializers/indexmap.rb` with an idempotent
82
+ `IndexmapConfiguration.apply` loader and adds conditional `indexmap/tasks`
83
+ loading to the application's `Rakefile`. This preserves `bin/rails --tasks` and
84
+ the `indexmap:*` tasks without loading Indexmap during normal Rails boot.
85
+
86
+ Customize the `Indexmap.configure` block inside the generated initializer:
72
87
 
73
88
  ```ruby
74
89
  Indexmap.configure do |config|
@@ -92,6 +107,17 @@ Indexmap.configure do |config|
92
107
  end
93
108
  ```
94
109
 
110
+ Runtime callers and jobs must apply the generated configuration before using
111
+ Indexmap:
112
+
113
+ ```ruby
114
+ IndexmapConfiguration.apply
115
+ Indexmap.create
116
+ ```
117
+
118
+ Rake tasks apply it automatically because `indexmap/tasks` loads the gem before
119
+ Rails evaluates the initializer.
120
+
95
121
  Then run:
96
122
 
97
123
  ```bash
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module Indexmap
6
+ module Generators
7
+ class InstallGenerator < Rails::Generators::Base
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ desc "Create a lazy-safe Indexmap initializer and task loader"
11
+
12
+ def create_initializer
13
+ template "initializer.rb.tt", "config/initializers/indexmap.rb"
14
+ end
15
+
16
+ def configure_rakefile
17
+ rakefile = File.join(destination_root, "Rakefile")
18
+ return unless File.exist?(rakefile)
19
+ return if File.read(rakefile).include?('require "indexmap/tasks"')
20
+
21
+ inject_into_file "Rakefile", rakefile_setup, before: /^require_relative ["']config\/application["']/
22
+ end
23
+
24
+ private
25
+
26
+ def rakefile_setup
27
+ <<~RUBY
28
+ indexmap_tasks_requested = Rake.application.options.show_tasks ||
29
+ ARGV.any? { |argument| ["-T", "--tasks"].include?(argument) }
30
+ require "indexmap/tasks" if indexmap_tasks_requested ||
31
+ ARGV.any? { |argument| argument.start_with?("indexmap:") }
32
+
33
+ RUBY
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IndexmapConfiguration
4
+ MUTEX = Mutex.new
5
+
6
+ def self.apply
7
+ return if @applied
8
+
9
+ MUTEX.synchronize do
10
+ return if @applied
11
+
12
+ require "indexmap"
13
+
14
+ Indexmap.configure do |config|
15
+ config.base_url = -> { ENV.fetch("INDEXMAP_BASE_URL", "http://localhost:3000") }
16
+ config.storage = lambda {
17
+ Indexmap::Storage::Filesystem.new(
18
+ path: Rails.public_path,
19
+ public_url: config.base_url
20
+ )
21
+ }
22
+
23
+ # Configure the sitemap data owned by your application:
24
+ # config.sections = -> { Sitemap.sections }
25
+ end
26
+
27
+ @applied = true
28
+ end
29
+ end
30
+ end
31
+
32
+ IndexmapConfiguration.apply if defined?(Indexmap)
@@ -4,7 +4,7 @@ require "nokogiri"
4
4
 
5
5
  module Indexmap
6
6
  class Creator
7
- ValidationConfiguration = Struct.new(:base_url, :index_filename, :storage, keyword_init: true)
7
+ ValidationConfiguration = Struct.new(:base_url, :index_filename, :storage)
8
8
 
9
9
  def initialize(output:)
10
10
  @output = output
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Indexmap
4
- Entry = Struct.new(:loc, :lastmod, keyword_init: true)
4
+ Entry = Struct.new(:loc, :lastmod)
5
5
  end
@@ -6,7 +6,7 @@ require "uri"
6
6
 
7
7
  module Indexmap
8
8
  class Parser
9
- Entry = Struct.new(:loc, :lastmod, :source_sitemap, keyword_init: true)
9
+ Entry = Struct.new(:loc, :lastmod, :source_sitemap)
10
10
 
11
11
  def initialize(source: nil, rebase_remote_children: false, index_filename: Indexmap.configuration.index_filename, storage: Indexmap.configuration.storage)
12
12
  @source = (source || index_filename).to_s
@@ -3,7 +3,7 @@
3
3
  module Indexmap
4
4
  class Railtie < Rails::Railtie
5
5
  rake_tasks do
6
- load File.expand_path("../tasks/indexmap_tasks.rake", __dir__)
6
+ require "indexmap/tasks"
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Indexmap
4
- Section = Struct.new(:filename, :entries, keyword_init: true)
4
+ Section = Struct.new(:filename, :entries)
5
5
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Indexmap
4
4
  module Storage
5
- File = Struct.new(:filename, :body, :content_type, keyword_init: true) do
5
+ File = Struct.new(:filename, :body, :content_type) do
6
6
  def basename
7
7
  ::File.basename(filename)
8
8
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "indexmap"
4
+ require "rake"
5
+
6
+ unless Rake::Task.task_defined?("indexmap:sitemap:create")
7
+ load File.expand_path("../tasks/indexmap_tasks.rake", __dir__)
8
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Indexmap
4
- VERSION = "0.7.1"
4
+ VERSION = "0.8.1"
5
5
  end
data/lib/indexmap.rb CHANGED
@@ -18,14 +18,17 @@ require_relative "indexmap/entry"
18
18
  require_relative "indexmap/output"
19
19
  require_relative "indexmap/parser"
20
20
  require_relative "indexmap/pinger/base"
21
- require_relative "indexmap/pinger/google"
22
- require_relative "indexmap/pinger/index_now"
23
21
  require_relative "indexmap/section"
24
22
  require_relative "indexmap/task_runner"
25
23
  require_relative "indexmap/validator"
26
24
  require_relative "indexmap/writer"
27
25
 
28
26
  module Indexmap
27
+ module Pinger
28
+ autoload :Google, File.expand_path("indexmap/pinger/google", __dir__)
29
+ autoload :IndexNow, File.expand_path("indexmap/pinger/index_now", __dir__)
30
+ end
31
+
29
32
  class Error < StandardError; end
30
33
 
31
34
  class ConfigurationError < Error; end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "generators/indexmap/install_generator"
5
+ require "open3"
6
+ require "rbconfig"
7
+
8
+ class IndexmapInstallGeneratorTest < Minitest::Test
9
+ def test_generates_lazy_initializer_and_task_loader
10
+ Dir.mktmpdir do |destination|
11
+ File.write(File.join(destination, "Rakefile"), <<~RUBY)
12
+ require_relative "config/application"
13
+ Rails.application.load_tasks
14
+ RUBY
15
+
16
+ Indexmap::Generators::InstallGenerator.start([], destination_root: destination)
17
+
18
+ initializer = File.join(destination, "config/initializers/indexmap.rb")
19
+ rakefile = File.read(File.join(destination, "Rakefile"))
20
+
21
+ assert File.exist?(initializer)
22
+ assert_includes File.read(initializer), "module IndexmapConfiguration"
23
+ assert_includes File.read(initializer), "IndexmapConfiguration.apply if defined?(Indexmap)"
24
+ assert_includes rakefile, 'require "indexmap/tasks"'
25
+ assert_operator rakefile.index('require "indexmap/tasks"'), :<, rakefile.index('require_relative "config/application"')
26
+
27
+ _stdout, stderr, status = Open3.capture3(RbConfig.ruby, initializer)
28
+ assert status.success?, stderr
29
+
30
+ script = <<~RUBY
31
+ require "pathname"
32
+
33
+ module Rails
34
+ def self.public_path
35
+ Pathname.new("public")
36
+ end
37
+ end
38
+
39
+ require "indexmap"
40
+ load ARGV.fetch(0)
41
+
42
+ configuration = Indexmap.configuration
43
+ IndexmapConfiguration.apply
44
+ abort "configuration replaced" unless Indexmap.configuration.equal?(configuration)
45
+ abort "base URL missing" unless configuration.base_url == "http://localhost:3000"
46
+ RUBY
47
+ _stdout, stderr, status = Open3.capture3(
48
+ RbConfig.ruby,
49
+ "-I#{File.expand_path("../../lib", __dir__)}",
50
+ "-e",
51
+ script,
52
+ initializer
53
+ )
54
+ assert status.success?, stderr
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "open3"
5
+ require "rbconfig"
6
+
7
+ class IndexmapLazyLoadingTest < Minitest::Test
8
+ def test_entrypoint_does_not_load_search_console_dependencies
9
+ script = <<~RUBY
10
+ require "indexmap"
11
+
12
+ loaded = $LOADED_FEATURES.grep(%r{/(?:google/apis|googleauth)(?:/|\\.rb)})
13
+ abort loaded.join("\\n") unless loaded.empty?
14
+ RUBY
15
+
16
+ _stdout, stderr, status = Open3.capture3(
17
+ RbConfig.ruby,
18
+ "-I#{File.expand_path("../../lib", __dir__)}",
19
+ "-e",
20
+ script
21
+ )
22
+
23
+ assert status.success?, stderr
24
+ end
25
+
26
+ def test_task_entrypoint_registers_tasks
27
+ script = <<~RUBY
28
+ require "indexmap/tasks"
29
+
30
+ abort "task missing" unless Rake::Task.task_defined?("indexmap:sitemap:create")
31
+ RUBY
32
+
33
+ _stdout, stderr, status = Open3.capture3(
34
+ RbConfig.ruby,
35
+ "-I#{File.expand_path("../../lib", __dir__)}",
36
+ "-e",
37
+ script
38
+ )
39
+
40
+ assert status.success?, stderr
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indexmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Fidalgo
@@ -175,6 +175,8 @@ files:
175
175
  - CHANGELOG.md
176
176
  - LICENSE.txt
177
177
  - README.md
178
+ - lib/generators/indexmap/install_generator.rb
179
+ - lib/generators/indexmap/templates/initializer.rb.tt
178
180
  - lib/indexmap.rb
179
181
  - lib/indexmap/configuration.rb
180
182
  - lib/indexmap/creator.rb
@@ -193,11 +195,14 @@ files:
193
195
  - lib/indexmap/storage/filesystem.rb
194
196
  - lib/indexmap/storage/memory.rb
195
197
  - lib/indexmap/task_runner.rb
198
+ - lib/indexmap/tasks.rb
196
199
  - lib/indexmap/validator.rb
197
200
  - lib/indexmap/version.rb
198
201
  - lib/indexmap/writer.rb
199
202
  - lib/tasks/indexmap_tasks.rake
200
203
  - test/indexmap/configuration_test.rb
204
+ - test/indexmap/install_generator_test.rb
205
+ - test/indexmap/lazy_loading_test.rb
201
206
  - test/indexmap/parser_test.rb
202
207
  - test/indexmap/pinger/google_test.rb
203
208
  - test/indexmap/pinger/index_now_test.rb
@@ -234,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
239
  - !ruby/object:Gem::Version
235
240
  version: '0'
236
241
  requirements: []
237
- rubygems_version: 4.0.10
242
+ rubygems_version: 4.0.16
238
243
  specification_version: 4
239
244
  summary: Generate sitemap indexes and child sitemaps with plain Ruby
240
245
  test_files: []