Skip to content

Commit 9f0b656

Browse files
committed
Merge pull request #26 from benbalter/author
Allow author data as an object
2 parents b8d9cc2 + 5638c19 commit 9f0b656

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/template.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@
4444
{% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %}
4545
{% endif %}
4646

47+
{% if page.author %}
48+
{% if page.author.name %}
49+
{% assign seo_author_name = page.author.name %}
50+
{% else %}
51+
{% assign seo_author_name = page.author %}
52+
{% endif %}
53+
54+
{% if page.author.twitter %}
55+
{% assign seo_author_twitter = page.author.twitter %}
56+
{% else %}
57+
{% assign seo_author_twitter = page.author %}
58+
{% endif %}
59+
{% endif %}
60+
{% if seo_author_twitter %}
61+
{% assign seo_author_twitter = seo_author_twitter | replace:"@","" | prepend:"@" %}
62+
{% endif %}
63+
4764
{% if seo_title %}
4865
<title>{{ seo_title }}</title>
4966
{% endif %}
@@ -106,8 +123,8 @@
106123
{% if page.image %}
107124
<meta name="twitter:image" content="{{ page.image | escape }}" />
108125
{% endif %}
109-
{% if page.author %}
110-
<meta name="twitter:creator" content="@{{ page.author | replace:"@","" }}" />
126+
{% if seo_author_twitter %}
127+
<meta name="twitter:creator" content="{{ seo_author_twitter }}" />
111128
{% endif %}
112129
{% endif %}
113130

spec/jekyll_seo_tag_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@
166166
expect(subject.render(context)).to match(expected)
167167
end
168168

169+
it "supports author data as an object" do
170+
site = site({"twitter" => { "username" => "jekyllrb" }})
171+
page = page({"author" => {"twitter" => "@test"}})
172+
context = context({ :site => site, :page => page })
173+
expected = %r!<meta name="twitter:creator" content="@test" />!
174+
expect(subject.render(context)).to match(expected)
175+
end
176+
169177
it "outputs valid HTML" do
170178
site.process
171179
options = {

0 commit comments

Comments
 (0)