This commit is contained in:
Scott Perry 2022-07-25 22:28:26 -07:00
parent 7d1d478c0b
commit bfb31af482
5 changed files with 38 additions and 18 deletions

View File

@ -61,13 +61,17 @@ module Jekyll
def absolute_url
return unless raw_path
return @absolute_url if defined? @absolute_url
@absolute_url ||= build_absolute_path
end
@absolute_url = if raw_path.is_a?(String) && absolute_url?(raw_path) == false
filters.absolute_url raw_path
else
raw_path
end
def build_absolute_path
return raw_path unless raw_path.is_a?(String) && absolute_url?(raw_path) == false
if !raw_path.start_with?("/")
return filters.absolute_url File.join(File.dirname(context.registers[:page]["url"]), raw_path)
end
filters.absolute_url raw_path
end
def filters

View File

@ -415,7 +415,7 @@ RSpec.describe Jekyll::SeoTag::Drop do
end
context "image" do
let(:image) { "foo.png" }
let(:image) { "/foo.png" }
let(:page_meta) { { "image" => image } }
it "returns a Drop" do

View File

@ -3,7 +3,7 @@
RSpec.describe Jekyll::SeoTag::ImageDrop do
let(:config) { { "title" => "site title" } }
let(:image) { nil }
let(:page_meta) { { "image" => image } }
let(:page_meta) { { "image" => image, "dir" => "foo" } }
let(:page) { make_page(page_meta) }
let(:site) { make_site(config) }
let(:context) { make_context(:page => page, :site => site) }
@ -14,9 +14,25 @@ RSpec.describe Jekyll::SeoTag::ImageDrop do
Jekyll.logger.log_level = :error
end
context "with image as a string" do
context "with image as a relative path" do
let(:image) { "image.png" }
it "returns the image with the page dir prepended" do
expect(subject["path"]).to eql("/foo/image.png")
end
context "with site.url" do
let(:config) { { "url" => "http://example.com" } }
it "makes the path absolute" do
expect(subject["path"]).to eql("http://example.com/foo/image.png")
end
end
end
context "with image as an absolute path" do
let(:image) { "/image.png" }
it "returns the image" do
expect(subject["path"]).to eql("/image.png")
end
@ -30,7 +46,7 @@ RSpec.describe Jekyll::SeoTag::ImageDrop do
end
context "with a URL-escaped path" do
let(:image) { "some image.png" }
let(:image) { "/some image.png" }
it "URL-escapes the image" do
expect(subject["path"]).to eql("/some%20image.png")
@ -39,8 +55,8 @@ RSpec.describe Jekyll::SeoTag::ImageDrop do
end
context "with image as a hash" do
context "with a path" do
let(:image) { { "path" => "image.png" } }
context "with an absolute path" do
let(:image) { { "path" => "/image.png" } }
it "returns the image" do
expect(subject["path"]).to eql("/image.png")
@ -48,7 +64,7 @@ RSpec.describe Jekyll::SeoTag::ImageDrop do
end
context "with facebook" do
let(:image) { { "facebook" => "image.png" } }
let(:image) { { "facebook" => "/image.png" } }
it "returns the image" do
expect(subject["path"]).to eql("/image.png")
@ -56,7 +72,7 @@ RSpec.describe Jekyll::SeoTag::ImageDrop do
end
context "with twitter" do
let(:image) { { "twitter" => "image.png" } }
let(:image) { { "twitter" => "/image.png" } }
it "returns the image" do
expect(subject["path"]).to eql("/image.png")

View File

@ -113,8 +113,8 @@ RSpec.describe Jekyll::SeoTag::JSONLDDrop do
end
context "image" do
context "with image as a string" do
let(:image) { "image" }
context "with image as an absolute path" do
let(:image) { "/image" }
it "returns the image as a string" do
expect(subject).to have_key("image")
@ -124,7 +124,7 @@ RSpec.describe Jekyll::SeoTag::JSONLDDrop do
end
context "with image as a hash" do
let(:image) { { "path" => "image", "height" => 5, "width" => 10 } }
let(:image) { { "path" => "/image", "height" => 5, "width" => 10 } }
it "returns the image as a hash" do
expect(subject).to have_key("image")

View File

@ -31,7 +31,7 @@ CONFIG_DEFAULTS = {
}.freeze
def make_page(options = {})
page = Jekyll::Page.new site, CONFIG_DEFAULTS["source"], "", "page.md"
page = Jekyll::Page.new site, CONFIG_DEFAULTS["source"], options.delete("dir") || "", "page.md"
page.data = options
page
end