Skip to content

Commit

Permalink
Merge pull request #8 from greenhost/more-blog-post-article-tags
Browse files Browse the repository at this point in the history
Add author, modified_time and expiration_time to og tags
  • Loading branch information
ngs authored Feb 20, 2018
2 parents 70f4d45 + 3225c09 commit 1a28636
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions features/blog.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Feature: Middleman Blog support
Then I should see '<meta content="2014-04-12T04:00:00Z" property="article:published_time" />'
Then I should see '<meta content="ruby" property="article:tag" />'
Then I should see '<meta content="middleman" property="article:tag" />'
Then I should see '<meta content="Test" property="article:author:first_name" />'
Then I should see '<meta content="Author" property="article:author:last_name" />'
Then I should see '<meta content="test_author" property="article:author:username" />'
Then I should see '<meta content="female" property="article:author:gender" />'
Then I should see '<meta content="Test Section" property="article:section" />'
Then I should see '<meta content="2014-04-13T03:00:00Z" property="article:modified_time" />'
Then I should see '<meta content="2018-04-12T04:00:00Z" property="article:expiration_time" />'
Then I should see '<meta content="blog" property="article:tag" />'
Then I should see '<meta content="http://myblog.foo.tld/2014/04/12/my-test.html" property="og:url" />'
Then I should see '<meta content="Fixture page" property="og:title" />'
Expand Down
1 change: 1 addition & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
ENV['TEST'] = 'true'
ENV['TZ'] = 'UTC'
require "middleman-core"
require "middleman-blog"
require "middleman-core/step_definitions"
Expand Down
8 changes: 8 additions & 0 deletions fixtures/test-blog/source/2014-04-12-my-test.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ title: Fixture page
description: This is a ficture page
tags: ruby, middleman, blog
date: 2014-04-12 04:00
author:
first_name: Test
last_name: Author
username: test_author
gender: female
section: Test Section
modified_time: 2014-04-13 03:00
expiration_time: 2018-04-12 04:00
---

h1 Hello article
Expand Down
19 changes: 19 additions & 0 deletions lib/middleman-ogp/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ def ogp_tags(&block)
tag: current_article.tags,
}
})
if current_article.data.section
opts[:article][:section] = current_article.data.section
end
if current_article.data.expiration_time
opts[:article][:expiration_time] = Time.parse(current_article.data.expiration_time).utc.iso8601
end
if current_article.data.modified_time
opts[:article][:modified_time] = Time.parse(current_article.data.modified_time).utc.iso8601
end
if current_article.data.author
if current_article.data.author.kind_of?(Object)
opts[:article][:author] = {}
[:first_name, :last_name, :username, :gender].each do | field |
if current_article.data.author[field]
opts[:article][:author][field] = current_article.data.author[field]
end
end
end
end
end
opts[:og] ||= {}
if Middleman::OGP::Helper.auto.include?('title')
Expand Down

0 comments on commit 1a28636

Please sign in to comment.