indexmap 0.10.1 → 0.11.0
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 +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +33 -34
- data/UPGRADE.md +56 -1
- data/docs/deployment.md +6 -6
- data/docs/domain-terms.md +7 -7
- data/docs/dynamic-sitemaps.md +12 -8
- data/lib/generators/indexmap/install_generator.rb +2 -13
- data/lib/generators/indexmap/templates/initializer.rb.tt +12 -28
- data/lib/indexmap/validator.rb +3 -0
- data/lib/indexmap/version.rb +1 -1
- data/lib/indexmap/writer.rb +7 -1
- data/lib/indexmap.rb +3 -0
- data/test/indexmap/install_generator_test.rb +35 -41
- data/test/indexmap/validator_test.rb +12 -0
- data/test/indexmap/writer_test.rb +44 -0
- data/test/integration/queue_checks.rb +16 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ccc3c85e74b227729c23c98343802e7b7ab2be886aeb329315176309f17dc41
|
|
4
|
+
data.tar.gz: 667474b22b41298892ab0916df1d40f8afc3aa0ab42fe53144e593f8686be5cf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8c855e46ebd9904d47d67297c19198256bbc5151d7b0f2705b6c942f87fdf834f6625b2906c31cb721cbe174b0a36f1a5cf397c45ee4d65a9384efa8329348a
|
|
7
|
+
data.tar.gz: ef366333d205bdda0c8d64f26d97824f8ef186d27e101f70a3b57cf620f74a52e142903be5b96009b4f90bd6e4d95def9bb9f207a08a89e890d6f32b8a0e3f22
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,30 @@ 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.11.0] - 2026-11-06
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- keep checks local and adopt Gemkit 0.3.1
|
|
14
|
+
|
|
15
|
+
- keep checks local and adopt Gemkit 0.3.1 ([#32](https://github.com/ethos-link/indexmap/pull/32))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- enforce UTF-8 encoding before partitioning
|
|
23
|
+
|
|
24
|
+
- enforce UTF-8 encoding before partitioning ([#33](https://github.com/ethos-link/indexmap/pull/33))
|
|
25
|
+
|
|
26
|
+
- defer sitemap configuration through native load hooks
|
|
27
|
+
|
|
28
|
+
- simplify lazy sitemap configuration ([#34](https://github.com/ethos-link/indexmap/pull/34))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
8
32
|
## [0.10.1] - 2026-11-05
|
|
9
33
|
|
|
10
34
|
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Indexmap
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/indexmap)
|
|
4
|
-
[](https://github.com/ethos-link/indexmap/actions/workflows/commitlint.yml)
|
|
5
5
|
|
|
6
6
|
`indexmap` is a small Ruby gem for generating XML sitemaps from explicit Ruby data.
|
|
7
7
|
|
|
@@ -94,43 +94,43 @@ Run the install generator after adding the gem:
|
|
|
94
94
|
bin/rails generate indexmap:install
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
The generator creates `config/initializers/indexmap.rb`
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
The generator creates `config/initializers/indexmap.rb` using Rails' native
|
|
98
|
+
load hook and adds `require "indexmap/tasks"` to the application's `Rakefile`.
|
|
99
|
+
Normal web and worker boot does not load Indexmap. Rakefiles run only for tasks,
|
|
100
|
+
so task discovery needs no argument parsing.
|
|
101
101
|
|
|
102
|
-
Customize the
|
|
102
|
+
Customize the generated initializer:
|
|
103
103
|
|
|
104
104
|
```ruby
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
config.sections = -> do
|
|
112
|
-
[
|
|
113
|
-
Indexmap::Section.new(
|
|
114
|
-
filename: "sitemap-marketing.xml",
|
|
115
|
-
entries: [
|
|
116
|
-
Indexmap::Entry.new(loc: "https://example.com/")
|
|
117
|
-
]
|
|
105
|
+
ActiveSupport.on_load(:indexmap) do
|
|
106
|
+
Indexmap.configure do |config|
|
|
107
|
+
config.base_url = -> { ENV.fetch("INDEXMAP_BASE_URL", "https://example.com") }
|
|
108
|
+
config.storage = -> do
|
|
109
|
+
Indexmap::Storage::Filesystem.new(
|
|
110
|
+
path: Rails.public_path, public_url: config.base_url
|
|
118
111
|
)
|
|
119
|
-
|
|
112
|
+
end
|
|
113
|
+
config.sections = -> { Sitemap.sections }
|
|
120
114
|
end
|
|
121
115
|
end
|
|
122
116
|
```
|
|
123
117
|
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
Keep storage, route helpers and source queries inside their callables. Passing
|
|
119
|
+
`public_url: config.base_url` while constructing an adapter outside a callable
|
|
120
|
+
resolves the origin immediately, before routes or later initializers may exist.
|
|
121
|
+
Moving that eager expression to `after_initialize` does not make route helpers
|
|
122
|
+
available reliably. The storage callable resolves once per operation.
|
|
123
|
+
|
|
124
|
+
Runtime callers only require the gem and invoke the operation:
|
|
126
125
|
|
|
127
126
|
```ruby
|
|
128
|
-
|
|
129
|
-
Indexmap.create
|
|
127
|
+
require "indexmap"
|
|
128
|
+
Indexmap::TaskRunner.new.create
|
|
130
129
|
```
|
|
131
130
|
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
The load hook applies configuration whether the gem loads before or after the
|
|
132
|
+
initializer. No host module, mutex, explicit apply call, or custom task loader
|
|
133
|
+
is needed. Existing manually configured Ruby callers remain supported.
|
|
134
134
|
|
|
135
135
|
Then run:
|
|
136
136
|
|
|
@@ -151,8 +151,8 @@ revision-checked root activation. See [dynamic sitemaps](docs/dynamic-sitemaps.m
|
|
|
151
151
|
### Background Generation
|
|
152
152
|
|
|
153
153
|
Keep the refresh job and its scheduling in the host application. Indexmap does
|
|
154
|
-
not select a queue adapter, run workers, or deduplicate jobs.
|
|
155
|
-
|
|
154
|
+
not select a queue adapter, run workers, or deduplicate jobs. Require the gem
|
|
155
|
+
inside the job. Use `Indexmap::TaskRunner.new.create` for the
|
|
156
156
|
rake task's complete lifecycle, including `after_create` callbacks and IndexNow
|
|
157
157
|
key-file handling; `Indexmap.create` only generates the selected output.
|
|
158
158
|
|
|
@@ -177,7 +177,7 @@ class SitemapRefreshJob < ApplicationJob
|
|
|
177
177
|
)
|
|
178
178
|
|
|
179
179
|
def perform(_version)
|
|
180
|
-
|
|
180
|
+
require "indexmap"
|
|
181
181
|
Indexmap::TaskRunner.new.create
|
|
182
182
|
end
|
|
183
183
|
end
|
|
@@ -201,7 +201,7 @@ class SitemapRefreshJob < ApplicationJob
|
|
|
201
201
|
duration: 30.minutes, on_conflict: :block
|
|
202
202
|
|
|
203
203
|
def perform(_version)
|
|
204
|
-
|
|
204
|
+
require "indexmap"
|
|
205
205
|
Indexmap::TaskRunner.new.create
|
|
206
206
|
end
|
|
207
207
|
end
|
|
@@ -304,15 +304,14 @@ In the application's `config/routes.rb`, load and mount the endpoint explicitly:
|
|
|
304
304
|
|
|
305
305
|
```ruby
|
|
306
306
|
require "indexmap/robots_controller"
|
|
307
|
-
Indexmap::HostConfiguration.apply
|
|
308
307
|
|
|
309
308
|
Rails.application.routes.draw do
|
|
310
309
|
get "/robots.txt", to: Indexmap::RobotsController.action(:show)
|
|
311
310
|
end
|
|
312
311
|
```
|
|
313
312
|
|
|
314
|
-
|
|
315
|
-
|
|
313
|
+
Keep the load hook in an initializer. Remove `public/robots.txt` so it cannot
|
|
314
|
+
shadow the route.
|
|
316
315
|
The controller supports GET, HEAD, and conditional requests, uses a one-hour
|
|
317
316
|
public cache, and does not inherit application authentication or browser gates.
|
|
318
317
|
Set `PUBLIC_INDEXING` only for the intended public deployment; production-mode
|
|
@@ -490,7 +489,7 @@ Then the job can stay small:
|
|
|
490
489
|
```ruby
|
|
491
490
|
class Insights::SitemapRefreshJob < ApplicationJob
|
|
492
491
|
def perform
|
|
493
|
-
|
|
492
|
+
require "indexmap"
|
|
494
493
|
Indexmap.create(:insights_data)
|
|
495
494
|
end
|
|
496
495
|
end
|
data/UPGRADE.md
CHANGED
|
@@ -3,11 +3,66 @@
|
|
|
3
3
|
Use this guide when upgrading an application that already generates, validates,
|
|
4
4
|
or pings sitemaps with `indexmap`.
|
|
5
5
|
|
|
6
|
+
Run `bundle exec rake verify` locally before pushing or preparing a release.
|
|
7
|
+
GitHub Actions runs commitlint and release packaging/publication only.
|
|
8
|
+
|
|
9
|
+
## Next
|
|
10
|
+
|
|
11
|
+
### Rails configuration without a host loader
|
|
12
|
+
|
|
13
|
+
The installer now generates `ActiveSupport.on_load(:indexmap)` around the existing
|
|
14
|
+
`Indexmap.configure` block. It works when tasks load the gem before initializers
|
|
15
|
+
and when jobs first require it after boot. Plain Ruby `Indexmap.configure` is
|
|
16
|
+
unchanged. Existing host loaders continue working until migrated.
|
|
17
|
+
|
|
18
|
+
For an existing app:
|
|
19
|
+
|
|
20
|
+
1. Keep the app's configure block in `config/initializers/indexmap.rb`, wrapped in
|
|
21
|
+
`ActiveSupport.on_load(:indexmap) do ... end`. Remove the surrounding host module,
|
|
22
|
+
mutex, `@applied` guard, and bottom-of-file apply call. Do not keep both owners.
|
|
23
|
+
2. Keep `base_url`, storage construction, route calls and source queries lazy.
|
|
24
|
+
Use `config.storage = -> { Indexmap::Storage::Filesystem.new(path: ...,
|
|
25
|
+
public_url: config.base_url) }`. The previous template evaluated the origin at
|
|
26
|
+
boot, which fails when it needs unloaded routes or later initializer settings.
|
|
27
|
+
An `after_initialize` wrapper is not a substitute for deferring evaluation.
|
|
28
|
+
3. Replace host-loader calls in models, jobs, routes and scripts with `require "indexmap"`
|
|
29
|
+
before the gem operation. Remove any separate configuration-file loads.
|
|
30
|
+
4. Use one `require "indexmap/tasks"` in the Rakefile before application loading.
|
|
31
|
+
Rakefiles are not web/worker boot paths; argument-sensitive loaders and duplicate
|
|
32
|
+
task files are unnecessary. The installer preserves existing loaders and
|
|
33
|
+
authored initializer content; migrate those manually rather than overwriting.
|
|
34
|
+
5. Verify web/worker boot, Rails task listing, create/validate via Rails and Rake,
|
|
35
|
+
a real refresh job, and HTTP delivery against the same configuration.
|
|
36
|
+
|
|
37
|
+
### Adopt the publication pipeline
|
|
38
|
+
|
|
39
|
+
Use built-in storage instead of copying file writes and promotion into the host.
|
|
40
|
+
`TaskRunner#create` stages, partitions and validates before publishing. Remove
|
|
41
|
+
outer staging directories, repeated validation, manual URL-count partitions,
|
|
42
|
+
and whole-inventory arrays where the host can supply lazy entries. Keep domain
|
|
43
|
+
eligibility, canonical paths, grouping and meaningful `lastmod` in the app.
|
|
44
|
+
|
|
45
|
+
For mutable indexes, use atomic publication to avoid mixed generations. Adopt
|
|
46
|
+
`config.atomic = true` together with persistent shared storage, routes and cache
|
|
47
|
+
policy for generated children, bounded retries for superseded builds, and a
|
|
48
|
+
separate prune schedule. Remove filename-based cleanup and retention callbacks;
|
|
49
|
+
they can delete immutable children referenced by cached roots. Single-file build
|
|
50
|
+
outputs can keep their existing delivery. See [deployment](docs/deployment.md)
|
|
51
|
+
and [dynamic sitemaps](docs/dynamic-sitemaps.md) for the complete contracts.
|
|
52
|
+
|
|
53
|
+
### UTF-8 output
|
|
54
|
+
|
|
55
|
+
Sitemap text is converted to UTF-8 before XML escaping and byte partitioning.
|
|
56
|
+
Invalid or unconvertible strings raise `Indexmap::ValidationError`. The validator
|
|
57
|
+
also rejects XML documents that declare another encoding, even when their XML is
|
|
58
|
+
otherwise valid. Regenerate older non-UTF-8 files before validating or submitting
|
|
59
|
+
them. Existing UTF-8 output and partition names are unchanged.
|
|
60
|
+
|
|
6
61
|
## 0.10.0
|
|
7
62
|
|
|
8
63
|
### Shared development and release tooling
|
|
9
64
|
|
|
10
|
-
Use Ruby 4 and published Gemkit 0.3.
|
|
65
|
+
Use Ruby 4 and published Gemkit 0.3.1. Install the bundle and hooks, then run the
|
|
11
66
|
project's verification command from the README. Prepare releases from clean,
|
|
12
67
|
current main; merging the generated release PR publishes through Actions.
|
|
13
68
|
See the [Gemkit upgrade guide](https://github.com/ethos-link/ethos-gemkit/blob/main/UPGRADE.md)
|
data/docs/deployment.md
CHANGED
|
@@ -18,14 +18,14 @@ See the [pipeline diagram](architecture.md) for the generation/publication bound
|
|
|
18
18
|
|
|
19
19
|
Follow the [Rails installation](../README.md#rails-usage), including
|
|
20
20
|
`require: false` and `bin/rails generate indexmap:install`. Edit the configure
|
|
21
|
-
block inside `
|
|
22
|
-
|
|
21
|
+
block inside `ActiveSupport.on_load(:indexmap)`. Keep storage construction lazy
|
|
22
|
+
when it uses the configured origin:
|
|
23
23
|
|
|
24
24
|
```ruby
|
|
25
|
-
config.base_url = ENV.fetch("INDEXMAP_BASE_URL", "http://localhost:3000")
|
|
26
|
-
config.storage =
|
|
27
|
-
path: Rails.public_path, public_url: config.base_url
|
|
28
|
-
|
|
25
|
+
config.base_url = -> { ENV.fetch("INDEXMAP_BASE_URL", "http://localhost:3000") }
|
|
26
|
+
config.storage = -> do
|
|
27
|
+
Indexmap::Storage::Filesystem.new(path: Rails.public_path, public_url: config.base_url)
|
|
28
|
+
end
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
Always set `INDEXMAP_BASE_URL` to the actual public origin in deployment. For
|
data/docs/domain-terms.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
| Term | Meaning |
|
|
4
4
|
| --- | --- |
|
|
5
5
|
| Configuration | `Indexmap::Configuration` holds gem settings, sources, outputs, callbacks, and robots policy. |
|
|
6
|
-
|
|
|
6
|
+
| Load hook | `ActiveSupport.on_load(:indexmap)` registers host configuration without loading the gem during Rails boot. It runs when Indexmap loads, or immediately if already loaded. |
|
|
7
7
|
| Output | One independently generated target with a stable root filename. Named outputs share storage and are not automatically linked into the default output. |
|
|
8
8
|
| Section | A host-defined filename and enumerable of page entries, used in index mode. |
|
|
9
9
|
| Page entry | `Indexmap::Entry`: the host's `loc` and optional meaningful content `lastmod`. |
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
| Format | `:index` or `:single_file` selects XML shape. The separate `format` task changes whitespace in legacy artifacts. |
|
|
20
20
|
| Robots policy | Crawl instructions served as `/robots.txt`. It is independent of sitemap storage and refresh scheduling. |
|
|
21
21
|
|
|
22
|
-
Use these terms in host manifests and operational instructions.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
filesystem class.
|
|
26
|
-
|
|
27
|
-
[UPGRADE.md](../UPGRADE.md
|
|
22
|
+
Use these terms in host manifests and operational instructions.
|
|
23
|
+
`Indexmap::Configuration` owns settings; the native load hook registers host
|
|
24
|
+
configuration. `Indexmap::Artifact` is rendered data and `::File` is Ruby's
|
|
25
|
+
filesystem class. Former host loaders `IndexmapConfiguration` and
|
|
26
|
+
`Indexmap::HostConfiguration` are superseded by the load hook. See
|
|
27
|
+
[UPGRADE.md](../UPGRADE.md) for migration.
|
data/docs/dynamic-sitemaps.md
CHANGED
|
@@ -11,9 +11,11 @@ Run `bin/rails generate indexmap:install`, then edit the generated configure blo
|
|
|
11
11
|
|
|
12
12
|
```ruby
|
|
13
13
|
config.base_url = -> { ENV.fetch("PUBLIC_ORIGIN") }
|
|
14
|
-
config.storage =
|
|
15
|
-
|
|
16
|
-
)
|
|
14
|
+
config.storage = -> do
|
|
15
|
+
Indexmap::Storage::Filesystem.new(
|
|
16
|
+
path: Rails.root.join("storage/sitemaps"), public_url: config.base_url
|
|
17
|
+
)
|
|
18
|
+
end
|
|
17
19
|
config.atomic = true
|
|
18
20
|
config.max_urls = 45_000
|
|
19
21
|
config.sections = -> { Sitemap.sections }
|
|
@@ -27,6 +29,10 @@ a job, reuse an exhausted source across refreshes, or use refresh time as the
|
|
|
27
29
|
content's `lastmod`. Time-dependent eligibility needs recurring refreshes even
|
|
28
30
|
when no record is updated. A batch scan is not a point-in-time database snapshot.
|
|
29
31
|
|
|
32
|
+
The host must select public, canonical, indexable URLs. XML validation cannot
|
|
33
|
+
infer authentication, redirects, publication state, or a page's `noindex` policy.
|
|
34
|
+
Keep those eligibility checks in the manifest rather than adding a crawler.
|
|
35
|
+
|
|
30
36
|
Generation stages XML on local temporary disk, validates the complete graph, then
|
|
31
37
|
publishes. Entry sources are consumed once. Index mode splits a section before
|
|
32
38
|
`max_urls` (default 50,000) or `max_bytes` (default 52,428,800) is exceeded. Limits
|
|
@@ -144,15 +150,14 @@ class SitemapRefreshJob < ApplicationJob
|
|
|
144
150
|
retry_on Indexmap::SupersededPublication, wait: :polynomially_longer, attempts: 3
|
|
145
151
|
|
|
146
152
|
def perform(_version = nil)
|
|
147
|
-
Indexmap::HostConfiguration.apply
|
|
148
153
|
Indexmap::TaskRunner.new.create
|
|
149
154
|
end
|
|
150
155
|
end
|
|
151
156
|
```
|
|
152
157
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
158
|
+
Keep configuration in the initializer load hook. The explicit require above
|
|
159
|
+
makes the exception class available when a job is eager-loaded; it does not
|
|
160
|
+
evaluate section sources. The host's `ApplicationJob` context,
|
|
156
161
|
authorization, and transaction hooks remain authoritative. Pass scalar output or
|
|
157
162
|
release identifiers and enqueue after source transactions commit and database
|
|
158
163
|
preparation completes. A separate queue database is not transactionally coupled
|
|
@@ -186,7 +191,6 @@ This example assumes root-level storage keys and `index_filename = "sitemap.xml"
|
|
|
186
191
|
|
|
187
192
|
```ruby
|
|
188
193
|
require "indexmap/sitemaps_controller"
|
|
189
|
-
Indexmap::HostConfiguration.apply
|
|
190
194
|
|
|
191
195
|
Rails.application.routes.draw do
|
|
192
196
|
get "/sitemap.xml", to: Indexmap::SitemapsController.action(:show),
|
|
@@ -18,19 +18,8 @@ module Indexmap
|
|
|
18
18
|
return unless File.exist?(rakefile)
|
|
19
19
|
return if File.read(rakefile).include?('require "indexmap/tasks"')
|
|
20
20
|
|
|
21
|
-
inject_into_file "Rakefile",
|
|
22
|
-
|
|
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
|
-
(Rake.application.top_level_tasks + ARGV).any? { |argument| argument.start_with?("indexmap:") }
|
|
32
|
-
|
|
33
|
-
RUBY
|
|
21
|
+
inject_into_file "Rakefile", "require \"indexmap/tasks\"\n\n",
|
|
22
|
+
before: /^require_relative ["']config\/application["']/
|
|
34
23
|
end
|
|
35
24
|
end
|
|
36
25
|
end
|
|
@@ -1,33 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return if @applied
|
|
12
|
-
|
|
13
|
-
require "indexmap"
|
|
14
|
-
|
|
15
|
-
Indexmap.configure do |config|
|
|
16
|
-
config.base_url = -> { ENV.fetch("INDEXMAP_BASE_URL", "http://localhost:3000") }
|
|
17
|
-
config.storage = Indexmap::Storage::Filesystem.new(
|
|
18
|
-
path: Rails.public_path,
|
|
19
|
-
public_url: config.base_url
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
# Search-engine pings start from config.index_filename (default: "sitemap.xml").
|
|
23
|
-
# Configure the sitemap data owned by your application:
|
|
24
|
-
# config.sections = -> { Sitemap.sections }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
@applied = true
|
|
28
|
-
end
|
|
3
|
+
ActiveSupport.on_load(:indexmap) do
|
|
4
|
+
Indexmap.configure do |config|
|
|
5
|
+
config.base_url = -> { ENV.fetch("INDEXMAP_BASE_URL", "http://localhost:3000") }
|
|
6
|
+
config.storage = -> do
|
|
7
|
+
Indexmap::Storage::Filesystem.new(
|
|
8
|
+
path: Rails.public_path,
|
|
9
|
+
public_url: config.base_url
|
|
10
|
+
)
|
|
29
11
|
end
|
|
12
|
+
|
|
13
|
+
# Search-engine pings start from config.index_filename (default: "sitemap.xml").
|
|
14
|
+
# Configure the sitemap data owned by your application:
|
|
15
|
+
# config.sections = -> { Sitemap.sections }
|
|
30
16
|
end
|
|
31
17
|
end
|
|
32
|
-
|
|
33
|
-
Indexmap::HostConfiguration.apply if defined?(Indexmap::Configuration)
|
data/lib/indexmap/validator.rb
CHANGED
|
@@ -103,6 +103,9 @@ module Indexmap
|
|
|
103
103
|
next unless node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
|
|
104
104
|
|
|
105
105
|
if node.depth == 0
|
|
106
|
+
unless Encoding.find(reader.encoding || "UTF-8") == Encoding::UTF_8
|
|
107
|
+
raise ValidationError, "Sitemap must use UTF-8 encoding: #{filename}"
|
|
108
|
+
end
|
|
106
109
|
root = node.local_name
|
|
107
110
|
unless %w[urlset sitemapindex].include?(root)
|
|
108
111
|
raise ValidationError, "Invalid sitemap root element in #{filename}: #{root}"
|
data/lib/indexmap/version.rb
CHANGED
data/lib/indexmap/writer.rb
CHANGED
|
@@ -189,7 +189,13 @@ module Indexmap
|
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
def escape(value)
|
|
192
|
-
|
|
192
|
+
string = value.to_s
|
|
193
|
+
string = string.encode(Encoding::UTF_8) unless string.encoding == Encoding::UTF_8
|
|
194
|
+
raise ValidationError, "Sitemap text must be valid UTF-8" unless string.valid_encoding?
|
|
195
|
+
|
|
196
|
+
CGI.escapeHTML(string)
|
|
197
|
+
rescue EncodingError => error
|
|
198
|
+
raise ValidationError, "Sitemap text cannot be encoded as UTF-8: #{error.message}"
|
|
193
199
|
end
|
|
194
200
|
end
|
|
195
201
|
end
|
data/lib/indexmap.rb
CHANGED
|
@@ -4,6 +4,7 @@ require "cgi"
|
|
|
4
4
|
require "date"
|
|
5
5
|
require "fileutils"
|
|
6
6
|
require "time"
|
|
7
|
+
require "active_support/lazy_load_hooks"
|
|
7
8
|
|
|
8
9
|
require_relative "indexmap/version"
|
|
9
10
|
require_relative "indexmap/google_configuration"
|
|
@@ -67,3 +68,5 @@ module Indexmap
|
|
|
67
68
|
end
|
|
68
69
|
|
|
69
70
|
require_relative "indexmap/railtie" if defined?(Rails::Railtie)
|
|
71
|
+
|
|
72
|
+
ActiveSupport.run_load_hooks(:indexmap, Indexmap)
|
|
@@ -6,56 +6,50 @@ require "open3"
|
|
|
6
6
|
require "rbconfig"
|
|
7
7
|
|
|
8
8
|
class IndexmapInstallGeneratorTest < Minitest::Test
|
|
9
|
-
def
|
|
9
|
+
def test_generated_initializer_defers_origin_and_entries_in_both_load_orders
|
|
10
10
|
Dir.mktmpdir do |destination|
|
|
11
11
|
File.write(File.join(destination, "Rakefile"), <<~RUBY)
|
|
12
12
|
require_relative "config/application"
|
|
13
13
|
Rails.application.load_tasks
|
|
14
14
|
RUBY
|
|
15
|
-
|
|
16
15
|
Indexmap::Generators::InstallGenerator.start([], destination_root: destination)
|
|
17
|
-
|
|
18
16
|
initializer = File.join(destination, "config/initializers/indexmap.rb")
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
assert_includes rakefile, 'require "indexmap/tasks"'
|
|
26
|
-
assert_operator rakefile.index('require "indexmap/tasks"'), :<, rakefile.index('require_relative "config/application"')
|
|
27
|
-
|
|
28
|
-
_stdout, stderr, status = Open3.capture3(RbConfig.ruby, initializer)
|
|
29
|
-
assert status.success?, stderr
|
|
30
|
-
|
|
31
|
-
script = <<~RUBY
|
|
32
|
-
require "pathname"
|
|
17
|
+
source = File.read(initializer).sub('ENV.fetch("INDEXMAP_BASE_URL", "http://localhost:3000")', "Rails.origin")
|
|
18
|
+
source = source.sub("# config.sections = -> { Sitemap.sections }", <<~RUBY.strip)
|
|
19
|
+
config.format = :single_file
|
|
20
|
+
config.entries = -> { [Indexmap::Entry.new(loc: Rails.origin + "/page")] }
|
|
21
|
+
RUBY
|
|
22
|
+
File.write(initializer, source)
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
["before", "after"].each do |order|
|
|
25
|
+
script = <<~RUBY
|
|
26
|
+
require "pathname"
|
|
27
|
+
require "active_support/lazy_load_hooks"
|
|
28
|
+
module Rails
|
|
29
|
+
def self.public_path = Pathname.new(ENV.fetch("INDEXMAP_TEST_PUBLIC_PATH"))
|
|
30
|
+
def self.origin
|
|
31
|
+
raise "origin resolved before routes" unless @ready
|
|
32
|
+
"https://example.com"
|
|
33
|
+
end
|
|
34
|
+
def self.ready = @ready = true
|
|
37
35
|
end
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
script,
|
|
56
|
-
initializer
|
|
57
|
-
)
|
|
58
|
-
assert status.success?, stderr
|
|
36
|
+
require "indexmap" if ARGV.fetch(1) == "before"
|
|
37
|
+
load ARGV.fetch(0)
|
|
38
|
+
abort "Indexmap loaded during boot" if ARGV.fetch(1) == "after" && defined?(Indexmap::Configuration)
|
|
39
|
+
require "indexmap"
|
|
40
|
+
Rails.ready
|
|
41
|
+
result = Indexmap::TaskRunner.new.create
|
|
42
|
+
abort "wrong output" unless result.fetch(:files) == ["sitemap.xml"]
|
|
43
|
+
abort "wrong origin" unless Indexmap.configuration.storage.read("sitemap.xml").include?("https://example.com/page")
|
|
44
|
+
require "indexmap"
|
|
45
|
+
abort "configuration lost" unless Indexmap.configuration.base_url == "https://example.com"
|
|
46
|
+
RUBY
|
|
47
|
+
output, error, status = Open3.capture3(
|
|
48
|
+
{"INDEXMAP_TEST_PUBLIC_PATH" => File.join(destination, order)},
|
|
49
|
+
RbConfig.ruby, "-I#{File.expand_path("../../lib", __dir__)}", "-e", script, initializer, order
|
|
50
|
+
)
|
|
51
|
+
assert status.success?, output + error
|
|
52
|
+
end
|
|
59
53
|
end
|
|
60
54
|
end
|
|
61
55
|
|
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
require "test_helper"
|
|
4
4
|
|
|
5
5
|
class IndexmapValidatorTest < Minitest::Test
|
|
6
|
+
def test_rejects_non_utf8_sitemaps_even_when_the_xml_is_valid
|
|
7
|
+
body = %(<?xml version="1.0" encoding="ISO-8859-1"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://example.com/page</loc></url></urlset>)
|
|
8
|
+
|
|
9
|
+
error = assert_raises(Indexmap::ValidationError) { validate_sitemap(body) }
|
|
10
|
+
|
|
11
|
+
assert_match "UTF-8", error.message
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_accepts_utf8_with_a_byte_order_mark
|
|
15
|
+
assert validate_sitemap("\uFEFF" + %(<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://example.com/page</loc></url></urlset>))
|
|
16
|
+
end
|
|
17
|
+
|
|
6
18
|
def test_validate_raises_for_missing_sitemap
|
|
7
19
|
error = assert_raises(Indexmap::ValidationError) do
|
|
8
20
|
Indexmap::Validator.new(configuration: configuration_with).validate!
|
|
@@ -3,6 +3,50 @@
|
|
|
3
3
|
require "test_helper"
|
|
4
4
|
|
|
5
5
|
class IndexmapWriterTest < Minitest::Test
|
|
6
|
+
def test_transcodes_input_to_utf8_before_escaping_and_partitioning
|
|
7
|
+
location = "https://example.com/caf\xE9&tea".dup.force_encoding(Encoding::ISO_8859_1)
|
|
8
|
+
files = Indexmap::Writer.new(base_url: "https://example.com",
|
|
9
|
+
sections: [{filename: "sitemap-pages.xml", entries: [{loc: location}]}]).write
|
|
10
|
+
|
|
11
|
+
assert_equal Encoding::UTF_8, files.first.body.encoding
|
|
12
|
+
assert_includes files.first.body, "https://example.com/café&tea"
|
|
13
|
+
assert files.first.body.valid_encoding?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_rejects_invalid_input_encoding
|
|
17
|
+
location = "https://example.com/\xFF".dup.force_encoding(Encoding::UTF_8)
|
|
18
|
+
|
|
19
|
+
assert_raises(Indexmap::ValidationError) do
|
|
20
|
+
Indexmap::Writer.new(base_url: "https://example.com",
|
|
21
|
+
entries: [{loc: location}], format: :single_file).write
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_partitioning_counts_transcoded_and_escaped_bytes
|
|
26
|
+
entries = (1..3).map do |id|
|
|
27
|
+
{loc: ("https://example.com/#{id}" + "\xE9&" * 30).force_encoding(Encoding::ISO_8859_1)}
|
|
28
|
+
end
|
|
29
|
+
files = Indexmap::Writer.new(base_url: "https://example.com", max_bytes: 500,
|
|
30
|
+
sections: [{filename: "sitemap-pages.xml", entries: entries}]).write
|
|
31
|
+
|
|
32
|
+
assert_equal ["sitemap-pages.xml", "sitemap-pages-002.xml", "sitemap-pages-003.xml", "sitemap.xml"], files.map(&:filename)
|
|
33
|
+
files.each do |file|
|
|
34
|
+
assert_equal Encoding::UTF_8, file.body.encoding
|
|
35
|
+
assert_operator file.body.bytesize, :<=, 500
|
|
36
|
+
end
|
|
37
|
+
assert_includes files.first.body, "é&"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_default_url_limit_splits_a_lazy_source_without_losing_entries
|
|
41
|
+
entries = (1..50_001).lazy.map { |id| {loc: "https://example.com/#{id}"} }
|
|
42
|
+
files = Indexmap::Writer.new(base_url: "https://example.com",
|
|
43
|
+
sections: [{filename: "sitemap-pages.xml", entries: entries}]).write
|
|
44
|
+
|
|
45
|
+
assert_equal [50_000, 1], files.first(2).map { |file| file.body.scan("<url>").size }
|
|
46
|
+
assert_includes files.last.body, "https://example.com/sitemap-pages-002.xml"
|
|
47
|
+
assert_includes files[1].body, "https://example.com/50001"
|
|
48
|
+
end
|
|
49
|
+
|
|
6
50
|
def test_writes_sitemap_index_and_child_sitemap_documents
|
|
7
51
|
sections = [
|
|
8
52
|
Indexmap::Section.new(
|
|
@@ -7,11 +7,26 @@ require "rbconfig"
|
|
|
7
7
|
|
|
8
8
|
class QueueChecks < Minitest::Test
|
|
9
9
|
def setup
|
|
10
|
-
Indexmap
|
|
10
|
+
Indexmap.reset!
|
|
11
|
+
load Rails.root.join("config/initializers/indexmap.rb")
|
|
11
12
|
PublicPage.delete_all
|
|
12
13
|
5.times { |id| PublicPage.create!(slug: "page-#{id}", published: true) }
|
|
13
14
|
end
|
|
14
15
|
|
|
16
|
+
def test_http_serves_the_configured_publication_without_evaluating_sources
|
|
17
|
+
result = Indexmap::TaskRunner.new.create
|
|
18
|
+
Indexmap.configuration.sections = -> { raise "HTTP must not evaluate source records" }
|
|
19
|
+
client = Rack::MockRequest.new(Rails.application)
|
|
20
|
+
|
|
21
|
+
root = client.get("/sitemap.xml")
|
|
22
|
+
assert_equal 200, root.status
|
|
23
|
+
assert_includes root.body, result.fetch(:files).first
|
|
24
|
+
child = client.get("/" + result.fetch(:files).first)
|
|
25
|
+
assert_equal 200, child.status
|
|
26
|
+
assert_includes child.body, "https://example.com/page-0"
|
|
27
|
+
assert_includes child["cache-control"], "immutable"
|
|
28
|
+
end
|
|
29
|
+
|
|
15
30
|
def test_good_job_executes_database_projection_and_surfaces_validation_failure
|
|
16
31
|
IntegrationRefreshJob.queue_adapter = :good_job
|
|
17
32
|
job = IntegrationRefreshJob.perform_later
|
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.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paulo Fidalgo
|
|
@@ -201,8 +201,8 @@ metadata:
|
|
|
201
201
|
homepage_uri: https://www.ethos-link.com/opensource/indexmap
|
|
202
202
|
source_code_uri: https://github.com/ethos-link/indexmap
|
|
203
203
|
bug_tracker_uri: https://github.com/ethos-link/indexmap/issues
|
|
204
|
-
changelog_uri: https://github.com/ethos-link/indexmap/blob/v0.
|
|
205
|
-
documentation_uri: https://github.com/ethos-link/indexmap/blob/v0.
|
|
204
|
+
changelog_uri: https://github.com/ethos-link/indexmap/blob/v0.11.0/CHANGELOG.md
|
|
205
|
+
documentation_uri: https://github.com/ethos-link/indexmap/blob/v0.11.0/README.md
|
|
206
206
|
funding_uri: https://www.reviato.com/
|
|
207
207
|
github_repo: ssh://github.com/ethos-link/indexmap
|
|
208
208
|
allowed_push_host: https://rubygems.org
|