From b7c533b740277a25d56d28d8181fe68f0ad4c476 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2022 22:13:58 -0700 Subject: [PATCH 1/2] test with a Post as well --- spec/jekyll_seo_tag/image_drop_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/jekyll_seo_tag/image_drop_spec.rb b/spec/jekyll_seo_tag/image_drop_spec.rb index 61531f2..98154c5 100644 --- a/spec/jekyll_seo_tag/image_drop_spec.rb +++ b/spec/jekyll_seo_tag/image_drop_spec.rb @@ -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" } From 6308799fe8466c12979bb13a052ff4f0dc07dcdb Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2022 22:14:38 -0700 Subject: [PATCH 2/2] handle pretty urls where posts get a directory expect files inside a post to be inside the post's directory rather than in the calendar day's directory --- lib/jekyll-seo-tag/image_drop.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jekyll-seo-tag/image_drop.rb b/lib/jekyll-seo-tag/image_drop.rb index 6e520c7..647ce1f 100644 --- a/lib/jekyll-seo-tag/image_drop.rb +++ b/lib/jekyll-seo-tag/image_drop.rb @@ -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