diff --git a/lib/perron/html_processor/absolute_urls.rb b/lib/perron/html_processor/absolute_urls.rb
index 6ce4c0f..40fe084 100644
--- a/lib/perron/html_processor/absolute_urls.rb
+++ b/lib/perron/html_processor/absolute_urls.rb
@@ -9,7 +9,7 @@ def process
next if src.blank? || absolute_url?(src)
- image["src"] = base_url + src
+ image["src"] = "#{base_url}/#{src.delete_prefix("/")}"
end
end
diff --git a/lib/perron/resource/metadata.rb b/lib/perron/resource/metadata.rb
index 4434734..5b7445b 100644
--- a/lib/perron/resource/metadata.rb
+++ b/lib/perron/resource/metadata.rb
@@ -71,7 +71,7 @@ def absolute_url(path)
return path if path.blank?
return path if path.start_with?("http://", "https://", "//")
- Perron.configuration.url.delete_suffix("/") + path
+ "#{Perron.configuration.url.delete_suffix("/")}/#{path.delete_prefix("/")}"
end
def site_data
diff --git a/test/perron/html_processor/absolute_urls_test.rb b/test/perron/html_processor/absolute_urls_test.rb
index 3d8b4ef..85e8d83 100644
--- a/test/perron/html_processor/absolute_urls_test.rb
+++ b/test/perron/html_processor/absolute_urls_test.rb
@@ -60,4 +60,13 @@ def process_html(html)
assert_dom_equal html, processed
end
+
+ test 'inserts a slash for a relative src without a leading slash' do
+ html = '
'
+ processed = process_html(html)
+
+ assert_dom_equal '
' \
+ '
',
+ processed
+ end
end
diff --git a/test/perron/resource/metadata_test.rb b/test/perron/resource/metadata_test.rb
index a4093e7..db94fda 100644
--- a/test/perron/resource/metadata_test.rb
+++ b/test/perron/resource/metadata_test.rb
@@ -105,6 +105,17 @@ def setup
assert_equal 'Kendall', metadata.author, 'Frontmatter author should take highest precedence'
end
+ test 'makes a relative frontmatter image absolute with a slash separator' do
+ metadata = Perron::Resource::Metadata.new(
+ resource: @post,
+ frontmatter: { image: 'cover.jpg' },
+ collection: @posts_collection
+ ).data
+
+ assert_equal 'http://localhost:3000/cover.jpg', metadata.image
+ assert_equal 'http://localhost:3000/cover.jpg', metadata.og_image
+ end
+
test 'removes nil values from final data after processing' do
metadata = Perron::Resource::Metadata.new(
resource: @about_page,