indexmap 0.6.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.
data/lib/indexmap/path.rb DELETED
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "uri"
4
-
5
- module Indexmap
6
- module Path
7
- INDEX_FILENAME = "sitemap.xml"
8
- LEGACY_FILENAME = "sitemap_index.xml"
9
-
10
- module_function
11
-
12
- def canonical_public_path(public_path: default_public_path_root, index_filename: default_index_filename)
13
- Pathname(public_path).join(index_filename)
14
- end
15
-
16
- def existing_public_path(public_path: default_public_path_root, index_filename: default_index_filename, legacy_filename: LEGACY_FILENAME)
17
- index_path = canonical_public_path(public_path: public_path, index_filename: index_filename)
18
- return index_path if index_path.exist?
19
-
20
- Pathname(public_path).join(legacy_filename)
21
- end
22
-
23
- def canonical_url(base_url, index_filename: default_index_filename)
24
- URI.join(base_url, "/#{index_filename}").to_s
25
- end
26
-
27
- def default_index_filename
28
- configured = Indexmap.configuration.index_filename
29
- configured.to_s.strip.empty? ? INDEX_FILENAME : configured
30
- rescue
31
- INDEX_FILENAME
32
- end
33
-
34
- def default_public_path_root
35
- if defined?(Rails)
36
- Rails.public_path
37
- else
38
- Pathname("public")
39
- end
40
- end
41
- end
42
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class IndexmapPathTest < Minitest::Test
6
- def test_existing_public_path_prefers_sitemap_index_when_present
7
- Dir.mktmpdir do |dir|
8
- public_path = Pathname(dir)
9
- public_path.join("sitemap_index.xml").write("<urlset/>")
10
- public_path.join("sitemap.xml").write("<sitemapindex/>")
11
-
12
- assert_equal public_path.join("sitemap.xml"), Indexmap::Path.existing_public_path(public_path: public_path)
13
- end
14
- end
15
-
16
- def test_existing_public_path_falls_back_to_legacy_sitemap_path
17
- Dir.mktmpdir do |dir|
18
- public_path = Pathname(dir)
19
- public_path.join("sitemap_index.xml").write("<sitemapindex/>")
20
-
21
- assert_equal public_path.join("sitemap_index.xml"), Indexmap::Path.existing_public_path(public_path: public_path)
22
- end
23
- end
24
-
25
- def test_canonical_url_targets_sitemap_index
26
- assert_equal "https://www.example.com/sitemap.xml", Indexmap::Path.canonical_url("https://www.example.com")
27
- end
28
- end