Allow author data as an object

This commit is contained in:
Pat Hawks 2016-01-12 12:09:43 -08:00
parent 9f53718796
commit 5638c19a5d
No known key found for this signature in database
GPG Key ID: F1746FF5F18B3D1B
2 changed files with 27 additions and 2 deletions

View File

@ -44,6 +44,23 @@
{% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %}
{% endif %}
{% if page.author %}
{% if page.author.name %}
{% assign seo_author_name = page.author.name %}
{% else %}
{% assign seo_author_name = page.author %}
{% endif %}
{% if page.author.twitter %}
{% assign seo_author_twitter = page.author.twitter %}
{% else %}
{% assign seo_author_twitter = page.author %}
{% endif %}
{% endif %}
{% if seo_author_twitter %}
{% assign seo_author_twitter = seo_author_twitter | replace:"@","" | prepend:"@" %}
{% endif %}
{% if seo_title %}
<title>{{ seo_title }}</title>
{% endif %}
@ -106,8 +123,8 @@
{% if page.image %}
<meta name="twitter:image" content="{{ page.image | escape }}" />
{% endif %}
{% if page.author %}
<meta name="twitter:creator" content="@{{ page.author | replace:"@","" }}" />
{% if seo_author_twitter %}
<meta name="twitter:creator" content="{{ seo_author_twitter }}" />
{% endif %}
{% endif %}

View File

@ -166,6 +166,14 @@ describe Jekyll::SeoTag do
expect(subject.render(context)).to match(expected)
end
it "supports author data as an object" do
site = site({"twitter" => { "username" => "jekyllrb" }})
page = page({"author" => {"twitter" => "@test"}})
context = context({ :site => site, :page => page })
expected = %r!<meta name="twitter:creator" content="@test" />!
expect(subject.render(context)).to match(expected)
end
it "outputs valid HTML" do
site.process
options = {