Merge pull request #1 from indirect/issue/461

Handle posts as well as pages. maybe.
This commit is contained in:
Scott Perry 2022-07-27 14:54:43 -07:00 committed by GitHub
commit 95eda2f953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -66,12 +66,12 @@ module Jekyll
def build_absolute_path
return raw_path unless raw_path.is_a?(String) && absolute_url?(raw_path) == false
return filters.absolute_url(raw_path) if raw_path.start_with?("/")
if !raw_path.start_with?("/")
return filters.absolute_url File.join(File.dirname(context.registers[:page]["url"]), raw_path)
end
page_dir = @page["url"]
page_dir = File.dirname(page_dir) unless page_dir.end_with?("/")
filters.absolute_url raw_path
filters.absolute_url File.join(page_dir, raw_path)
end
def filters

View File

@ -14,6 +14,15 @@ RSpec.describe Jekyll::SeoTag::ImageDrop do
Jekyll.logger.log_level = :error
end
context "with a post object" do
let(:image) { "image.png" }
let(:page) { make_post(page_meta) }
it "returns the image url relative to the post directory" do
expect(subject["path"]).to eql("/2022/07/26/image.png")
end
end
context "with image as a relative path" do
let(:image) { "image.png" }