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