|
3 | 3 | RSpec.describe Jekyll::SeoTag::ImageDrop do |
4 | 4 | let(:config) { { "title" => "site title" } } |
5 | 5 | let(:image) { nil } |
6 | | - let(:page_meta) { { "image" => image } } |
| 6 | + let(:page_meta) { { "image" => image, "dir" => "foo" } } |
7 | 7 | let(:page) { make_page(page_meta) } |
8 | 8 | let(:site) { make_site(config) } |
9 | 9 | let(:context) { make_context(:page => page, :site => site) } |
|
14 | 14 | Jekyll.logger.log_level = :error |
15 | 15 | end |
16 | 16 |
|
17 | | - context "with image as a string" do |
| 17 | + context "with a post object" do |
18 | 18 | let(:image) { "image.png" } |
| 19 | + let(:page_meta) { { "image" => image, "date" => "2017-01-01" } } |
| 20 | + let(:page) { make_post(page_meta) } |
| 21 | + |
| 22 | + it "returns the image url relative to the post directory" do |
| 23 | + expect(subject["path"]).to eql("/2017/01/01/image.png") |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + context "with image as a relative path" do |
| 28 | + let(:image) { "image.png" } |
| 29 | + |
| 30 | + it "returns the image with the page dir prepended" do |
| 31 | + expect(subject["path"]).to eql("/foo/image.png") |
| 32 | + end |
| 33 | + |
| 34 | + context "with site.url" do |
| 35 | + let(:config) { { "url" => "http://example.com" } } |
| 36 | + |
| 37 | + it "makes the path absolute" do |
| 38 | + expect(subject["path"]).to eql("http://example.com/foo/image.png") |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + context "with image as an absolute path" do |
| 44 | + let(:image) { "/image.png" } |
19 | 45 |
|
20 | 46 | it "returns the image" do |
21 | 47 | expect(subject["path"]).to eql("/image.png") |
|
30 | 56 | end |
31 | 57 |
|
32 | 58 | context "with a URL-escaped path" do |
33 | | - let(:image) { "some image.png" } |
| 59 | + let(:image) { "/some image.png" } |
34 | 60 |
|
35 | 61 | it "URL-escapes the image" do |
36 | 62 | expect(subject["path"]).to eql("/some%20image.png") |
|
39 | 65 | end |
40 | 66 |
|
41 | 67 | context "with image as a hash" do |
42 | | - context "with a path" do |
43 | | - let(:image) { { "path" => "image.png" } } |
| 68 | + context "with an absolute path" do |
| 69 | + let(:image) { { "path" => "/image.png" } } |
44 | 70 |
|
45 | 71 | it "returns the image" do |
46 | 72 | expect(subject["path"]).to eql("/image.png") |
47 | 73 | end |
48 | 74 | end |
49 | 75 |
|
50 | 76 | context "with facebook" do |
51 | | - let(:image) { { "facebook" => "image.png" } } |
| 77 | + let(:image) { { "facebook" => "/image.png" } } |
52 | 78 |
|
53 | 79 | it "returns the image" do |
54 | 80 | expect(subject["path"]).to eql("/image.png") |
55 | 81 | end |
56 | 82 | end |
57 | 83 |
|
58 | 84 | context "with twitter" do |
59 | | - let(:image) { { "twitter" => "image.png" } } |
| 85 | + let(:image) { { "twitter" => "/image.png" } } |
60 | 86 |
|
61 | 87 | it "returns the image" do |
62 | 88 | expect(subject["path"]).to eql("/image.png") |
|
0 commit comments