indexmap 0.5.0 → 0.7.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 +2 -2
- data/README.md +162 -10
- data/lib/indexmap/configuration.rb +27 -26
- data/lib/indexmap/creator.rb +62 -0
- data/lib/indexmap/index_now_configuration.rb +12 -5
- data/lib/indexmap/output.rb +72 -0
- data/lib/indexmap/parser.rb +26 -15
- data/lib/indexmap/pinger/base.rb +5 -1
- data/lib/indexmap/pinger/google.rb +17 -6
- data/lib/indexmap/pinger/index_now.rb +21 -24
- data/lib/indexmap/storage/active_storage.rb +105 -0
- data/lib/indexmap/storage/file.rb +11 -0
- data/lib/indexmap/storage/filesystem.rb +77 -0
- data/lib/indexmap/storage/memory.rb +61 -0
- data/lib/indexmap/task_runner.rb +13 -13
- data/lib/indexmap/validator.rb +42 -30
- data/lib/indexmap/version.rb +1 -1
- data/lib/indexmap/writer.rb +10 -9
- data/lib/indexmap.rb +10 -2
- data/lib/tasks/indexmap_tasks.rake +7 -9
- data/test/indexmap/configuration_test.rb +129 -26
- data/test/indexmap/parser_test.rb +44 -3
- data/test/indexmap/pinger/google_test.rb +125 -96
- data/test/indexmap/pinger/index_now_test.rb +148 -179
- data/test/indexmap/storage_test.rb +123 -0
- data/test/indexmap/task_runner_test.rb +97 -41
- data/test/indexmap/validator_test.rb +96 -92
- data/test/indexmap/writer_test.rb +63 -74
- metadata +8 -3
- data/lib/indexmap/path.rb +0 -43
- data/test/indexmap/path_test.rb +0 -28
|
@@ -5,61 +5,117 @@ require "test_helper"
|
|
|
5
5
|
class IndexmapTaskRunnerTest < Minitest::Test
|
|
6
6
|
VALID_KEY = "1234567890abcdef1234567890abcdef"
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
public_path.join("sitemap-pages.xml.gz").write("old")
|
|
8
|
+
class KeywordContentTypeStorage < Indexmap::Storage::Memory
|
|
9
|
+
def write(filename, body, content_type:)
|
|
10
|
+
super
|
|
11
|
+
end
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
def read_file(filename)
|
|
14
|
+
instance_variable_get(:@files).fetch(filename)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_create_writes_new_sitemap_and_key_file_without_deleting_unrelated_files
|
|
19
|
+
storage = Indexmap::Storage::Memory.new
|
|
20
|
+
storage.write("sitemap-pages.xml.gz", "old")
|
|
21
|
+
storage.write("sitemap-extra.xml", "existing")
|
|
22
|
+
|
|
23
|
+
configuration = configuration_with(storage: storage)
|
|
24
|
+
configuration.index_now.key = VALID_KEY
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
result = Indexmap::TaskRunner.new(configuration: configuration).create
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
assert storage.exist?("sitemap-pages.xml.gz")
|
|
29
|
+
assert_equal "existing", storage.read("sitemap-extra.xml")
|
|
30
|
+
assert_includes storage.read("sitemap.xml"), "<sitemapindex"
|
|
31
|
+
assert_equal VALID_KEY, storage.read("#{VALID_KEY}.txt")
|
|
32
|
+
assert_equal ["sitemap-pages.xml", "sitemap.xml"], result[:files]
|
|
33
|
+
assert_equal ["sitemap-pages.xml", "sitemap.xml"], result[:written_files]
|
|
34
|
+
assert_equal "#{VALID_KEY}.txt", result[:index_now_key_filename]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_create_runs_after_create_callbacks_after_validation
|
|
38
|
+
calls = []
|
|
39
|
+
storage = Indexmap::Storage::Memory.new
|
|
40
|
+
configuration = configuration_with(storage: storage)
|
|
41
|
+
configuration.after_create do
|
|
42
|
+
calls << :called
|
|
43
|
+
calls << storage.read("sitemap.xml").include?("<sitemapindex")
|
|
32
44
|
end
|
|
45
|
+
|
|
46
|
+
Indexmap::TaskRunner.new(configuration: configuration).create
|
|
47
|
+
|
|
48
|
+
assert_equal [:called, true], calls
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_create_reuses_existing_index_now_key_file
|
|
52
|
+
storage = Indexmap::Storage::Memory.new
|
|
53
|
+
storage.write("#{VALID_KEY}.txt", VALID_KEY, content_type: "text/plain")
|
|
54
|
+
configuration = configuration_with(storage: storage)
|
|
55
|
+
configuration.index_now.key = VALID_KEY
|
|
56
|
+
|
|
57
|
+
result = Indexmap::TaskRunner.new(configuration: configuration).create
|
|
58
|
+
|
|
59
|
+
assert_equal "#{VALID_KEY}.txt", result[:index_now_key_filename]
|
|
60
|
+
assert_equal VALID_KEY, storage.read("#{VALID_KEY}.txt")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_create_can_skip_index_now_key_file_writing
|
|
64
|
+
storage = Indexmap::Storage::Memory.new
|
|
65
|
+
configuration = configuration_with(storage: storage)
|
|
66
|
+
configuration.index_now.key = VALID_KEY
|
|
67
|
+
configuration.index_now.write_key_file = false
|
|
68
|
+
|
|
69
|
+
result = Indexmap::TaskRunner.new(configuration: configuration).create
|
|
70
|
+
|
|
71
|
+
refute storage.exist?("#{VALID_KEY}.txt")
|
|
72
|
+
assert_nil result[:index_now_key_filename]
|
|
73
|
+
assert_equal ["sitemap-pages.xml", "sitemap.xml"], result[:files]
|
|
33
74
|
end
|
|
34
75
|
|
|
35
76
|
def test_write_index_now_key_returns_nil_when_key_is_not_configured
|
|
36
|
-
|
|
37
|
-
|
|
77
|
+
result = Indexmap::TaskRunner.new(configuration: configuration_with).write_index_now_key
|
|
78
|
+
|
|
79
|
+
assert_nil result
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_write_index_now_key_can_generate_a_key_when_requested
|
|
83
|
+
storage = Indexmap::Storage::Memory.new
|
|
84
|
+
configuration = configuration_with(storage: storage)
|
|
85
|
+
|
|
86
|
+
result = Indexmap::TaskRunner.new(configuration: configuration).write_index_now_key(generate_if_missing: true)
|
|
87
|
+
|
|
88
|
+
assert_match(/\A[a-f0-9]{32}\.txt\z/, result)
|
|
89
|
+
assert_equal result.delete_suffix(".txt"), storage.read(result)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_format_passes_content_type_when_rewriting_sitemaps
|
|
93
|
+
storage = KeywordContentTypeStorage.new
|
|
94
|
+
storage.write("sitemap.xml", <<~XML, content_type: "application/xml")
|
|
95
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
96
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://example.com/about</loc></url></urlset>
|
|
97
|
+
XML
|
|
98
|
+
configuration = configuration_with(storage: storage)
|
|
99
|
+
|
|
100
|
+
result = Indexmap::TaskRunner.new(configuration: configuration).format
|
|
101
|
+
|
|
102
|
+
assert_equal ["sitemap.xml"], result
|
|
103
|
+
assert_equal "application/xml", storage.read_file("sitemap.xml").content_type
|
|
104
|
+
assert_includes storage.read("sitemap.xml"), "\n <url>"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def configuration_with(storage: Indexmap::Storage::Memory.new)
|
|
110
|
+
Indexmap::Configuration.new.tap do |configuration|
|
|
38
111
|
configuration.base_url = "https://example.com"
|
|
39
|
-
configuration.
|
|
112
|
+
configuration.storage = storage
|
|
40
113
|
configuration.sections = [
|
|
41
114
|
Indexmap::Section.new(
|
|
42
115
|
filename: "sitemap-pages.xml",
|
|
43
116
|
entries: [Indexmap::Entry.new(loc: "https://example.com/about")]
|
|
44
117
|
)
|
|
45
118
|
]
|
|
46
|
-
|
|
47
|
-
result = Indexmap::TaskRunner.new(configuration: configuration).write_index_now_key
|
|
48
|
-
|
|
49
|
-
assert_nil result
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_write_index_now_key_can_generate_a_key_when_requested
|
|
54
|
-
Dir.mktmpdir do |dir|
|
|
55
|
-
configuration = Indexmap::Configuration.new
|
|
56
|
-
configuration.base_url = "https://example.com"
|
|
57
|
-
configuration.public_path = Pathname(dir)
|
|
58
|
-
|
|
59
|
-
result = Indexmap::TaskRunner.new(configuration: configuration).write_index_now_key(generate_if_missing: true)
|
|
60
|
-
|
|
61
|
-
assert_match(/\A[a-f0-9]{32}\.txt\z/, result.basename.to_s)
|
|
62
|
-
assert_equal result.basename(".txt").to_s, result.read
|
|
63
119
|
end
|
|
64
120
|
end
|
|
65
121
|
end
|
|
@@ -4,115 +4,82 @@ require "test_helper"
|
|
|
4
4
|
|
|
5
5
|
class IndexmapValidatorTest < Minitest::Test
|
|
6
6
|
def test_validate_raises_for_missing_sitemap
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
error = assert_raises(Indexmap::ValidationError) do
|
|
11
|
-
Indexmap::Validator.new(path: path).validate!
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
assert_equal "Missing sitemap file: #{path}", error.message
|
|
7
|
+
error = assert_raises(Indexmap::ValidationError) do
|
|
8
|
+
Indexmap::Validator.new(configuration: configuration_with).validate!
|
|
15
9
|
end
|
|
10
|
+
|
|
11
|
+
assert_equal "Missing sitemap file: sitemap.xml", error.message
|
|
16
12
|
end
|
|
17
13
|
|
|
18
14
|
def test_validate_raises_for_duplicate_urls
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
path.write(<<~XML)
|
|
15
|
+
error = assert_raises(Indexmap::ValidationError) do
|
|
16
|
+
validate_sitemap(<<~XML)
|
|
22
17
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
23
18
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
24
19
|
<url><loc>https://example.com/about</loc></url>
|
|
25
20
|
<url><loc>https://example.com/about</loc></url>
|
|
26
21
|
</urlset>
|
|
27
22
|
XML
|
|
28
|
-
|
|
29
|
-
error = assert_raises(Indexmap::ValidationError) do
|
|
30
|
-
Indexmap::Validator.new(path: path).validate!
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
assert_equal "Duplicate sitemap URLs detected: https://example.com/about", error.message
|
|
34
23
|
end
|
|
24
|
+
|
|
25
|
+
assert_equal "Duplicate sitemap URLs detected: https://example.com/about", error.message
|
|
35
26
|
end
|
|
36
27
|
|
|
37
28
|
def test_validate_raises_for_parameterized_urls
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
path.write(<<~XML)
|
|
29
|
+
error = assert_raises(Indexmap::ValidationError) do
|
|
30
|
+
validate_sitemap(<<~XML)
|
|
41
31
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
42
32
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
43
33
|
<url><loc>https://example.com/about?ref=test</loc></url>
|
|
44
34
|
</urlset>
|
|
45
35
|
XML
|
|
46
|
-
|
|
47
|
-
error = assert_raises(Indexmap::ValidationError) do
|
|
48
|
-
Indexmap::Validator.new(path: path).validate!
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
assert_equal "Parameterized sitemap URLs detected: https://example.com/about?ref=test", error.message
|
|
52
36
|
end
|
|
37
|
+
|
|
38
|
+
assert_equal "Parameterized sitemap URLs detected: https://example.com/about?ref=test", error.message
|
|
53
39
|
end
|
|
54
40
|
|
|
55
41
|
def test_validate_raises_for_fragment_urls
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
path.write(<<~XML)
|
|
42
|
+
error = assert_raises(Indexmap::ValidationError) do
|
|
43
|
+
validate_sitemap(<<~XML)
|
|
59
44
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
60
45
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
61
46
|
<url><loc>https://example.com/about#team</loc></url>
|
|
62
47
|
</urlset>
|
|
63
48
|
XML
|
|
64
|
-
|
|
65
|
-
error = assert_raises(Indexmap::ValidationError) do
|
|
66
|
-
Indexmap::Validator.new(path: path).validate!
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
assert_equal "Fragment sitemap URLs detected: https://example.com/about#team", error.message
|
|
70
49
|
end
|
|
50
|
+
|
|
51
|
+
assert_equal "Fragment sitemap URLs detected: https://example.com/about#team", error.message
|
|
71
52
|
end
|
|
72
53
|
|
|
73
54
|
def test_validate_raises_for_relative_urls
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
path.write(<<~XML)
|
|
55
|
+
error = assert_raises(Indexmap::ValidationError) do
|
|
56
|
+
validate_sitemap(<<~XML)
|
|
77
57
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
78
58
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
79
59
|
<url><loc>/about</loc></url>
|
|
80
60
|
</urlset>
|
|
81
61
|
XML
|
|
82
|
-
|
|
83
|
-
error = assert_raises(Indexmap::ValidationError) do
|
|
84
|
-
Indexmap::Validator.new(path: path).validate!
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
assert_equal "Invalid sitemap URLs detected: /about", error.message
|
|
88
62
|
end
|
|
63
|
+
|
|
64
|
+
assert_equal "Invalid sitemap URLs detected: /about", error.message
|
|
89
65
|
end
|
|
90
66
|
|
|
91
67
|
def test_validate_raises_for_urls_outside_configured_base_url
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
path.write(<<~XML)
|
|
68
|
+
error = assert_raises(Indexmap::ValidationError) do
|
|
69
|
+
validate_sitemap(<<~XML)
|
|
95
70
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
96
71
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
97
72
|
<url><loc>https://other.example.com/about</loc></url>
|
|
98
73
|
</urlset>
|
|
99
74
|
XML
|
|
100
|
-
|
|
101
|
-
configuration = Indexmap::Configuration.new
|
|
102
|
-
configuration.base_url = "https://example.com"
|
|
103
|
-
|
|
104
|
-
error = assert_raises(Indexmap::ValidationError) do
|
|
105
|
-
Indexmap::Validator.new(configuration: configuration, path: path).validate!
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
assert_equal "Sitemap URLs outside configured base URL detected: https://other.example.com/about", error.message
|
|
109
75
|
end
|
|
76
|
+
|
|
77
|
+
assert_equal "Sitemap URLs outside configured base URL detected: https://other.example.com/about", error.message
|
|
110
78
|
end
|
|
111
79
|
|
|
112
80
|
def test_validate_raises_for_invalid_lastmod_values
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
path.write(<<~XML)
|
|
81
|
+
error = assert_raises(Indexmap::ValidationError) do
|
|
82
|
+
validate_sitemap(<<~XML)
|
|
116
83
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
117
84
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
118
85
|
<url>
|
|
@@ -121,62 +88,99 @@ class IndexmapValidatorTest < Minitest::Test
|
|
|
121
88
|
</url>
|
|
122
89
|
</urlset>
|
|
123
90
|
XML
|
|
124
|
-
|
|
125
|
-
error = assert_raises(Indexmap::ValidationError) do
|
|
126
|
-
Indexmap::Validator.new(path: path).validate!
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
assert_equal "Invalid sitemap lastmod values detected: https://example.com/about", error.message
|
|
130
91
|
end
|
|
92
|
+
|
|
93
|
+
assert_equal "Invalid sitemap lastmod values detected: https://example.com/about", error.message
|
|
131
94
|
end
|
|
132
95
|
|
|
133
96
|
def test_validate_raises_for_empty_sitemaps
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
path.write(<<~XML)
|
|
97
|
+
error = assert_raises(Indexmap::ValidationError) do
|
|
98
|
+
validate_sitemap(<<~XML)
|
|
137
99
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
138
100
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
139
101
|
</urlset>
|
|
140
102
|
XML
|
|
141
|
-
|
|
142
|
-
error = assert_raises(Indexmap::ValidationError) do
|
|
143
|
-
Indexmap::Validator.new(path: path).validate!
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
assert_equal "Sitemap has no URLs: #{path}", error.message
|
|
147
103
|
end
|
|
104
|
+
|
|
105
|
+
assert_equal "Sitemap has no URLs: sitemap.xml", error.message
|
|
148
106
|
end
|
|
149
107
|
|
|
150
108
|
def test_validate_raises_for_missing_child_sitemap_files
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
child_path = Pathname(directory).join("sitemap-pages.xml")
|
|
154
|
-
path.write(<<~XML)
|
|
109
|
+
error = assert_raises(Indexmap::ValidationError) do
|
|
110
|
+
validate_sitemap(<<~XML)
|
|
155
111
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
156
112
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
157
113
|
<sitemap><loc>https://example.com/sitemap-pages.xml</loc></sitemap>
|
|
158
114
|
</sitemapindex>
|
|
159
115
|
XML
|
|
116
|
+
end
|
|
160
117
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
end
|
|
118
|
+
assert_equal "Missing child sitemap file: sitemap-pages.xml", error.message
|
|
119
|
+
end
|
|
164
120
|
|
|
165
|
-
|
|
166
|
-
|
|
121
|
+
def test_validate_preserves_directory_keys_for_child_sitemap_files
|
|
122
|
+
storage = Indexmap::Storage::Memory.new
|
|
123
|
+
storage.write("sitemaps/sitemap.xml", <<~XML)
|
|
124
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
125
|
+
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
126
|
+
<sitemap><loc>https://example.com/sitemaps/sitemap-pages.xml</loc></sitemap>
|
|
127
|
+
</sitemapindex>
|
|
128
|
+
XML
|
|
129
|
+
storage.write("sitemaps/sitemap-pages.xml", <<~XML)
|
|
130
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
131
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
132
|
+
<url><loc>https://example.com/about</loc></url>
|
|
133
|
+
</urlset>
|
|
134
|
+
XML
|
|
135
|
+
|
|
136
|
+
assert Indexmap::Validator.new(
|
|
137
|
+
configuration: configuration_with(storage: storage, index_filename: "sitemaps/sitemap.xml")
|
|
138
|
+
).validate!
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_validate_resolves_relative_child_sitemaps_from_parent_directory
|
|
142
|
+
storage = Indexmap::Storage::Memory.new
|
|
143
|
+
storage.write("sitemaps/sitemap.xml", <<~XML)
|
|
144
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
145
|
+
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
146
|
+
<sitemap><loc>sitemap-pages.xml</loc></sitemap>
|
|
147
|
+
</sitemapindex>
|
|
148
|
+
XML
|
|
149
|
+
storage.write("sitemaps/sitemap-pages.xml", <<~XML)
|
|
150
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
151
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
152
|
+
<url><loc>https://example.com/about</loc></url>
|
|
153
|
+
</urlset>
|
|
154
|
+
XML
|
|
155
|
+
|
|
156
|
+
assert Indexmap::Validator.new(
|
|
157
|
+
configuration: configuration_with(storage: storage, index_filename: "sitemaps/sitemap.xml")
|
|
158
|
+
).validate!
|
|
167
159
|
end
|
|
168
160
|
|
|
169
161
|
def test_validate_passes_for_valid_sitemap
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
XML
|
|
162
|
+
assert validate_sitemap(<<~XML)
|
|
163
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
164
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
165
|
+
<url><loc>https://example.com/about</loc></url>
|
|
166
|
+
</urlset>
|
|
167
|
+
XML
|
|
168
|
+
end
|
|
178
169
|
|
|
179
|
-
|
|
170
|
+
private
|
|
171
|
+
|
|
172
|
+
def validate_sitemap(body)
|
|
173
|
+
storage = Indexmap::Storage::Memory.new
|
|
174
|
+
storage.write("sitemap.xml", body)
|
|
175
|
+
|
|
176
|
+
Indexmap::Validator.new(configuration: configuration_with(storage: storage)).validate!
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def configuration_with(storage: Indexmap::Storage::Memory.new, index_filename: "sitemap.xml")
|
|
180
|
+
Indexmap::Configuration.new.tap do |configuration|
|
|
181
|
+
configuration.base_url = "https://example.com"
|
|
182
|
+
configuration.index_filename = index_filename
|
|
183
|
+
configuration.storage = storage
|
|
180
184
|
end
|
|
181
185
|
end
|
|
182
186
|
end
|
|
@@ -3,97 +3,86 @@
|
|
|
3
3
|
require "test_helper"
|
|
4
4
|
|
|
5
5
|
class IndexmapWriterTest < Minitest::Test
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
]
|
|
6
|
+
def test_writes_sitemap_index_and_child_sitemap_documents
|
|
7
|
+
sections = [
|
|
8
|
+
Indexmap::Section.new(
|
|
9
|
+
filename: "sitemap-pages.xml",
|
|
10
|
+
entries: [
|
|
11
|
+
Indexmap::Entry.new(loc: "https://example.com/", lastmod: Date.new(2026, 4, 21)),
|
|
12
|
+
Indexmap::Entry.new(loc: "https://example.com/pricing", lastmod: Time.utc(2026, 4, 22, 10, 30, 0))
|
|
13
|
+
]
|
|
14
|
+
)
|
|
15
|
+
]
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
).write
|
|
17
|
+
files = Indexmap::Writer.new(
|
|
18
|
+
sections: sections,
|
|
19
|
+
base_url: "https://example.com"
|
|
20
|
+
).write
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
index_xml = files.find { |file| file.filename == "sitemap.xml" }.body
|
|
23
|
+
child_xml = files.find { |file| file.filename == "sitemap-pages.xml" }.body
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
25
|
+
assert_includes index_xml, "<loc>https://example.com/sitemap-pages.xml</loc>"
|
|
26
|
+
assert_includes child_xml, "<loc>https://example.com/</loc>"
|
|
27
|
+
assert_includes child_xml, "<loc>https://example.com/pricing</loc>"
|
|
28
|
+
assert_includes child_xml, "<lastmod>2026-04-21</lastmod>"
|
|
29
|
+
assert_includes child_xml, "<lastmod>2026-04-22T10:30:00Z</lastmod>"
|
|
33
30
|
end
|
|
34
31
|
|
|
35
32
|
def test_accepts_hash_based_sections_and_entries
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
base_url: "https://example.com"
|
|
48
|
-
).write
|
|
33
|
+
files = Indexmap::Writer.new(
|
|
34
|
+
sections: [
|
|
35
|
+
{
|
|
36
|
+
filename: "sitemap-pages.xml",
|
|
37
|
+
entries: [
|
|
38
|
+
{loc: "https://example.com/about", lastmod: "2026-04-20T09:15:00Z"}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
base_url: "https://example.com"
|
|
43
|
+
).write
|
|
49
44
|
|
|
50
|
-
|
|
45
|
+
child_xml = files.find { |file| file.filename == "sitemap-pages.xml" }.body
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
47
|
+
assert_includes child_xml, "<loc>https://example.com/about</loc>"
|
|
48
|
+
assert_includes child_xml, "<lastmod>2026-04-20T09:15:00Z</lastmod>"
|
|
55
49
|
end
|
|
56
50
|
|
|
57
51
|
def test_writes_single_file_urlset
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
base_url: "https://example.com"
|
|
67
|
-
).write
|
|
52
|
+
files = Indexmap::Writer.new(
|
|
53
|
+
format: :single_file,
|
|
54
|
+
entries: [
|
|
55
|
+
Indexmap::Entry.new(loc: "https://example.com/", lastmod: Date.new(2026, 4, 21)),
|
|
56
|
+
{loc: "https://example.com/about", lastmod: "2026-04-22T09:15:00Z"}
|
|
57
|
+
],
|
|
58
|
+
base_url: "https://example.com"
|
|
59
|
+
).write
|
|
68
60
|
|
|
69
|
-
|
|
61
|
+
sitemap_xml = files.fetch(0).body
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
assert_equal 1, files.size
|
|
64
|
+
assert_equal "sitemap.xml", files.fetch(0).filename
|
|
65
|
+
assert_includes sitemap_xml, "<urlset"
|
|
66
|
+
assert_includes sitemap_xml, "<loc>https://example.com/</loc>"
|
|
67
|
+
assert_includes sitemap_xml, "<loc>https://example.com/about</loc>"
|
|
68
|
+
assert_includes sitemap_xml, "<lastmod>2026-04-21</lastmod>"
|
|
69
|
+
assert_includes sitemap_xml, "<lastmod>2026-04-22T09:15:00Z</lastmod>"
|
|
70
|
+
refute_includes sitemap_xml, "<sitemapindex"
|
|
79
71
|
end
|
|
80
72
|
|
|
81
73
|
def test_omits_sitemap_index_lastmod_when_sections_have_no_lastmod
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
base_url: "https://example.com"
|
|
92
|
-
).write
|
|
74
|
+
files = Indexmap::Writer.new(
|
|
75
|
+
sections: [
|
|
76
|
+
Indexmap::Section.new(
|
|
77
|
+
filename: "sitemap-pages.xml",
|
|
78
|
+
entries: [Indexmap::Entry.new(loc: "https://example.com/about")]
|
|
79
|
+
)
|
|
80
|
+
],
|
|
81
|
+
base_url: "https://example.com"
|
|
82
|
+
).write
|
|
93
83
|
|
|
94
|
-
|
|
84
|
+
index_xml = files.find { |file| file.filename == "sitemap.xml" }.body
|
|
95
85
|
|
|
96
|
-
|
|
97
|
-
end
|
|
86
|
+
refute_includes index_xml, "<lastmod>"
|
|
98
87
|
end
|
|
99
88
|
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.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paulo Fidalgo
|
|
@@ -177,16 +177,21 @@ files:
|
|
|
177
177
|
- README.md
|
|
178
178
|
- lib/indexmap.rb
|
|
179
179
|
- lib/indexmap/configuration.rb
|
|
180
|
+
- lib/indexmap/creator.rb
|
|
180
181
|
- lib/indexmap/entry.rb
|
|
181
182
|
- lib/indexmap/google_configuration.rb
|
|
182
183
|
- lib/indexmap/index_now_configuration.rb
|
|
184
|
+
- lib/indexmap/output.rb
|
|
183
185
|
- lib/indexmap/parser.rb
|
|
184
|
-
- lib/indexmap/path.rb
|
|
185
186
|
- lib/indexmap/pinger/base.rb
|
|
186
187
|
- lib/indexmap/pinger/google.rb
|
|
187
188
|
- lib/indexmap/pinger/index_now.rb
|
|
188
189
|
- lib/indexmap/railtie.rb
|
|
189
190
|
- lib/indexmap/section.rb
|
|
191
|
+
- lib/indexmap/storage/active_storage.rb
|
|
192
|
+
- lib/indexmap/storage/file.rb
|
|
193
|
+
- lib/indexmap/storage/filesystem.rb
|
|
194
|
+
- lib/indexmap/storage/memory.rb
|
|
190
195
|
- lib/indexmap/task_runner.rb
|
|
191
196
|
- lib/indexmap/validator.rb
|
|
192
197
|
- lib/indexmap/version.rb
|
|
@@ -194,9 +199,9 @@ files:
|
|
|
194
199
|
- lib/tasks/indexmap_tasks.rake
|
|
195
200
|
- test/indexmap/configuration_test.rb
|
|
196
201
|
- test/indexmap/parser_test.rb
|
|
197
|
-
- test/indexmap/path_test.rb
|
|
198
202
|
- test/indexmap/pinger/google_test.rb
|
|
199
203
|
- test/indexmap/pinger/index_now_test.rb
|
|
204
|
+
- test/indexmap/storage_test.rb
|
|
200
205
|
- test/indexmap/task_runner_test.rb
|
|
201
206
|
- test/indexmap/validator_test.rb
|
|
202
207
|
- test/indexmap/writer_test.rb
|