Skip to content

Commit 32ec930

Browse files
authored
Merge pull request #174 from jhabdas/twitter-uses-og-image
refactor(template): use og:image for twitter
2 parents dc767f1 + e264a9a commit 32ec930

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

README.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Jekyll SEO Tag adds the following meta tags to your site:
1313
* Canonical URL
1414
* Next and previous URLs on paginated pages
1515
* [JSON-LD Site and post metadata](https://developers.google.com/structured-data/) for richer indexing
16-
* [Open graph](http://ogp.me/) title, description, site title, and URL (for Facebook, LinkedIn, etc.)
17-
* [Twitter summary card](https://dev.twitter.com/cards/overview) metadata
16+
* [Open Graph](http://ogp.me/) title, description, site title, and URL (for Facebook, LinkedIn, etc.)
17+
* [Twitter Summary Card](https://dev.twitter.com/cards/overview) metadata
1818

1919
While you could theoretically add the necessary metadata tags yourself, Jekyll SEO Tag provides a battle-tested template of crowdsourced best-practices.
2020

@@ -191,17 +191,14 @@ The following options can be set for any particular page. While the default opti
191191
For most users, setting `image: [path-to-image]` on a per-page basis should be enough. If you need more control over how images are represented, the `image` property can also be an object, with the following options:
192192

193193
* `path` - The relative path to the image. Same as `image: [path-to-image]`
194-
* `twitter` - The relative path to a Twitter-specific image.
195-
* `facebook` - The relative path to a Facebook-specific image.
196-
* `height` - The height of the Facebook (`og:image`) image
197-
* `width` - The width of the Facebook (`og:image`) image
194+
* `height` - The height of the Open Graph (`og:image`) image
195+
* `width` - The width of the Open Graph (`og:image`) image
198196

199197
You can use any of the above, optional properties, like so:
200198

201199
```yml
202200
image:
203-
twitter: /img/twitter.png
204-
facebook: /img/facebook.png
201+
path: /img/twitter.png
205202
height: 100
206203
width: 100
207204
```

lib/template.html

+3-6
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
{% endif %}
9191

9292
{% if page.image %}
93-
{% assign seo_page_image = page.image.path | default: page.image.facebook | default: page.image %}
93+
{% assign seo_page_image = page.image.path | default: page.image.facebook | default: page.image.twitter | default: page.image %}
9494
{% unless seo_page_image contains "://" %}
9595
{% assign seo_page_image = seo_page_image | absolute_url %}
9696
{% endunless %}
@@ -124,7 +124,8 @@
124124
{% endif %}
125125

126126
{% if seo_page_image %}
127-
<meta property="og:image" content="{{ seo_page_image }}" />
127+
128+
<meta property="og:image" content="{{ seo_page_image }}" />
128129
{% if page.image.height %}
129130
<meta property="og:image:height" content="{{ page.image.height }}" />
130131
{% endif %}
@@ -133,10 +134,6 @@
133134
{% endif %}
134135
{% endif %}
135136

136-
{% if page.image.twitter %}
137-
<meta name="twitter:image" content="{{ page.image.twitter | absolute_url }}" />
138-
{% endif %}
139-
140137
{% if page.date %}
141138
<meta property="og:type" content="article" />
142139
<meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}" />

spec/jekyll_seo_tag_spec.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
context "with relative page.image as a string" do
173173
let(:page) { make_page("image" => "/img/foo.png") }
174174

175-
it "outputs the image" do
175+
it "outputs an open graph image" do
176176
expected = '<meta property="og:image" content="http://example.invalid/img/foo.png" />'
177177
expect(output).to include(expected)
178178
end
@@ -181,7 +181,7 @@
181181
context "with absolute page.image" do
182182
let(:page) { make_page("image" => "http://cdn.example.invalid/img/foo.png") }
183183

184-
it "outputs the image" do
184+
it "outputs an open graph image" do
185185
expected = '<meta property="og:image" content="http://cdn.example.invalid/img/foo.png" />'
186186
expect(output).to include(expected)
187187
end
@@ -191,7 +191,7 @@
191191
context "when given a path" do
192192
let(:page) { make_page("image" => { "path" => "/img/foo.png" }) }
193193

194-
it "outputs the image" do
194+
it "outputs an open graph image" do
195195
expected = %r!<meta property="og:image" content="http://example.invalid/img/foo.png" />!
196196
expect(output).to match(expected)
197197
end
@@ -200,7 +200,7 @@
200200
context "when given a facebook image" do
201201
let(:page) { make_page("image" => { "facebook" => "/img/facebook.png" }) }
202202

203-
it "outputs the image" do
203+
it "outputs an open graph image" do
204204
expected = %r!<meta property="og:image" content="http://example.invalid/img/facebook.png" />!
205205
expect(output).to match(expected)
206206
end
@@ -209,17 +209,17 @@
209209
context "when given a twitter image" do
210210
let(:page) { make_page("image" => { "twitter" => "/img/twitter.png" }) }
211211

212-
it "outputs the image" do
213-
expected = %r!<meta name="twitter:image" content="http://example.invalid/img/twitter.png" />!
212+
it "outputs an open graph image" do
213+
expected = %r!<meta property="og:image" content="http://example.invalid/img/twitter.png" />!
214214
expect(output).to match(expected)
215215
end
216216
end
217217

218-
context "when given the image height and width" do
219-
let(:image) { { "facebook" => "/img/foo.png", "height" => 1, "width" => 2 } }
218+
context "when given an image height and width" do
219+
let(:image) { { "path" => "/img/foo.png", "height" => 1, "width" => 2 } }
220220
let(:page) { make_page("image" => image) }
221221

222-
it "outputs the image" do
222+
it "outputs an open graph image width and height" do
223223
expected = %r!<meta property="og:image:height" content="1" />!
224224
expect(output).to match(expected)
225225
expected = %r!<meta property="og:image:width" content="2" />!

0 commit comments

Comments
 (0)