middleman-ogp 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96160b6adc9bfb778a9514674c56f7c123eebb84
4
- data.tar.gz: 9423c6302a1cc61e14696c8b00ec4afc680ed35b
3
+ metadata.gz: d59dba42be8e5b8512bf6ec22df723f202d2dd40
4
+ data.tar.gz: 1f211db3d5f975d00ebe96a8851a83f7baa27b11
5
5
  SHA512:
6
- metadata.gz: 317dd8172ab0d69f28f57b6005c92727f50c1970db9a6992033120b95d56d9c488774389da6236589ee35cbb7b6f8d3f231b686eae18bf5cc2ff036c3871dcbc
7
- data.tar.gz: 6faa50f42a43ee59a7ce58b06327f7b8e22913d547baf9ef8b330565bc3b5af0c78891db88b6f26f00a576382814d4962bc692552c62cb890c9949d19a06621c
6
+ metadata.gz: 371fffa46683019462bf0969620cfbcbdc0c71951aa53d5dc14192c4e044b4d02e5f1010568efb6d6f1560306c51ec35205972f57a0cfec56fad7ea785898fc4
7
+ data.tar.gz: 55985da4cd0415f0b849e699f87601f3c0eb5c901145ca5cef34522107922ca82616cf58893e5b7aa185449a32f244a81db1de3694e371049803adea434dbac9
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ doc
15
15
  tmp
16
16
  Makefile
17
17
  .mm-pid-*
18
+ *.gem
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "middleman-core", '~> 3.2'
4
+ gem "middleman-blog", '~> 3.5'
4
5
 
5
6
  # Specify your gem's dependencies in middleman-ogp.gemspec
6
7
  gemspec
data/README.md CHANGED
@@ -20,6 +20,7 @@ activate :ogp do |ogp|
20
20
  og: data.ogp.og
21
21
  # from data/ogp/og.yml
22
22
  }
23
+ og.base_url = 'http://mysite.tld/'
23
24
  end
24
25
  ```
25
26
 
@@ -77,12 +78,34 @@ Hello
77
78
  This is the __content__
78
79
  ```
79
80
 
81
+ Blog Support
82
+ ------------
83
+
84
+ `middleman-ogp` supports adding [article] properties like `article:published_time`, `article:tag` automatically for [middleman-blog] articles.
85
+
86
+ Set `ogp.blog` to `true` in your configuration. (Defaults to `false`)
87
+
88
+ ```ruby
89
+ activate :ogp do |ogp|
90
+ #
91
+ # register namespace with default options
92
+ #
93
+ ogp.namespaces = {
94
+ fb: data.ogp.fb,
95
+ # from data/ogp/fb.yml
96
+ og: data.ogp.og
97
+ # from data/ogp/og.yml
98
+ }
99
+ ogp.blog = true
100
+ end
101
+ ```
102
+
80
103
 
81
104
  Build & Dependency Status
82
105
  -------------------------
83
106
 
84
107
  [![Gem Version](https://badge.fury.io/rb/middleman-ogp.png)][gem]
85
- [![Build Status](https://travis-ci.org/ngs/middleman-ogp.png)][travis]
108
+ [![Build Status](https://travis-ci.org/ngs/middleman-ogp.svg?branch=master)][travis]
86
109
  [![Dependency Status](https://gemnasium.com/ngs/middleman-ogp.png?travis)][gemnasium]
87
110
  [![Code Quality](https://codeclimate.com/github/ngs/middleman-ogp.png)][codeclimate]
88
111
 
@@ -92,9 +115,11 @@ License
92
115
  Copyright (c) 2014 [Atsushi Nagase]. MIT Licensed, see [LICENSE] for details.
93
116
 
94
117
  [middleman]: http://middlemanapp.com
118
+ [middleman-blog]: https://github.com/middleman/middleman-blog
95
119
  [gem]: https://rubygems.org/gems/middleman-ogp
96
120
  [travis]: http://travis-ci.org/ngs/middleman-ogp
97
121
  [gemnasium]: https://gemnasium.com/ngs/middleman-ogp
98
122
  [codeclimate]: https://codeclimate.com/github/ngs/middleman-ogp
99
123
  [LICENSE]: https://github.com/ngs/middleman-ogp/blob/master/LICENSE.md
100
124
  [Atsushi Nagase]: http://ngs.io/
125
+ [article]: http://ogp.me/#type_article
@@ -0,0 +1,21 @@
1
+ Feature: Middleman Blog support
2
+
3
+ Scenario: Non article page
4
+ Given the Server is running at "test-blog"
5
+ When I go to "/"
6
+ Then I should see '<meta content="website" property="og:type" />'
7
+ Then I should see '<meta content="http://myblog.foo.tld/" property="og:url" />'
8
+ Then I should see '<meta content="Fixture page" property="og:title" />'
9
+
10
+ Scenario: article page
11
+ Given the Server is running at "test-blog"
12
+ When I go to "/2014/04/12/my-test.html"
13
+ Then I should see '<meta content="article" property="og:type" />'
14
+ Then I should see '<meta content="2014-04-12T04:00:00Z" property="article:published_time" />'
15
+ Then I should see '<meta content="ruby" property="article:tag" />'
16
+ Then I should see '<meta content="middleman" property="article:tag" />'
17
+ Then I should see '<meta content="blog" property="article:tag" />'
18
+ Then I should see '<meta content="http://myblog.foo.tld/2014/04/12/my-test.html" property="og:url" />'
19
+ Then I should see '<meta content="Fixture page" property="og:title" />'
20
+
21
+
@@ -9,7 +9,7 @@ Feature: OpenGraph Protocol Tags with the "ogp_tags" helper method
9
9
  Then I should see '<meta content="image/png" property="fb:image:type" />'
10
10
  Then I should see '<meta content="400" property="fb:image:width" />'
11
11
  Then I should see '<meta content="300" property="fb:image:height" />'
12
- Then I should see '<meta content="This is my fixture Middleman site for OpenGraph." property="og:description" />'
12
+ Then I should see '<meta content="My Description" property="og:description" />'
13
13
  Then I should see '<meta content="http://mydomain.tld/path/to/og-site-image.png" property="og:image" />'
14
14
  Then I should see '<meta content="https://secure.mydomain.tld/path/to/og-site-image.png" property="og:image:secure_url" />'
15
15
  Then I should see '<meta content="image/png" property="og:image:type" />'
@@ -18,6 +18,8 @@ Feature: OpenGraph Protocol Tags with the "ogp_tags" helper method
18
18
  Then I should see '<meta content="en_us" property="og:locale" />'
19
19
  Then I should see '<meta content="ja_jp" property="og:locale:alternate" />'
20
20
  Then I should see '<meta content="zh_tw" property="og:locale:alternate" />'
21
+ Then I should see '<meta content="http://myshop.foo.tld/" property="og:url" />'
22
+ Then I should see '<meta content="My Title" property="og:title" />'
21
23
 
22
24
  Scenario: With page data
23
25
  Given the Server is running at "test-app"
@@ -28,7 +30,7 @@ Feature: OpenGraph Protocol Tags with the "ogp_tags" helper method
28
30
  Then I should see '<meta content="image/png" property="fb:image:type" />'
29
31
  Then I should see '<meta content="400" property="fb:image:width" />'
30
32
  Then I should see '<meta content="300" property="fb:image:height" />'
31
- Then I should see '<meta content="This is my fixture Middleman article for OpenGraph." property="og:description" />'
33
+ Then I should see '<meta content="This is my fixture Middleman article." property="og:description" />'
32
34
  Then I should see '<meta content="http://mydomain.tld/path/to/og-article-image.png" property="og:image" />'
33
35
  Then I should see '<meta content="https://secure.mydomain.tld/path/to/og-article-image.png" property="og:image:secure_url" />'
34
36
  Then I should see '<meta content="image/png" property="og:image:type" />'
@@ -37,3 +39,5 @@ Feature: OpenGraph Protocol Tags with the "ogp_tags" helper method
37
39
  Then I should see '<meta content="en_us" property="og:locale" />'
38
40
  Then I should see '<meta content="ja_jp" property="og:locale:alternate" />'
39
41
  Then I should see '<meta content="zh_tw" property="og:locale:alternate" />'
42
+ Then I should see '<meta content="http://myshop.foo.tld/page.html" property="og:url" />'
43
+ Then I should see '<meta content="Fixture page" property="og:title" />'
@@ -1,5 +1,6 @@
1
1
  PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
2
  ENV['TEST'] = 'true'
3
3
  require "middleman-core"
4
+ require "middleman-blog"
4
5
  require "middleman-core/step_definitions"
5
6
  require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-ogp')
@@ -8,4 +8,5 @@ activate :ogp do |ogp|
8
8
  og: data.ogp.og
9
9
  # from data/ogp/og.yml
10
10
  }
11
- end
11
+ ogp.base_url = 'http://myshop.foo.tld/'
12
+ end
@@ -1,7 +1,9 @@
1
1
  ---
2
- title: Fixture page
2
+ description: My Description
3
+ title: My Title
3
4
  ---
4
5
 
5
6
  h1 Hello index
6
7
 
7
8
  p This is index
9
+
@@ -7,4 +7,4 @@ html
7
7
 
8
8
  body
9
9
  .container
10
- = yield
10
+ = yield
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  title: Fixture page
3
+ description: 'This is my fixture Middleman article.'
3
4
  ogp:
4
5
  og:
5
6
  description: 'This is my fixture Middleman article for OpenGraph.'
@@ -0,0 +1,11 @@
1
+ activate :blog do |blog|
2
+ end
3
+
4
+ activate :ogp do |ogp|
5
+ ogp.namespaces = {
6
+ fb: data.ogp.fb,
7
+ og: data.ogp.og
8
+ }
9
+ ogp.base_url = 'http://myblog.foo.tld/'
10
+ ogp.blog = true
11
+ end
@@ -0,0 +1,7 @@
1
+ description: 'This is my fixture Middleman site for Facebook.'
2
+ image:
3
+ '': http://mydomain.tld/path/to/fb-site-image.png
4
+ secure_url: https://secure.mydomain.tld/path/to/fb-site-image.png
5
+ type: image/png
6
+ width: 400
7
+ height: 300
@@ -0,0 +1,12 @@
1
+ description: 'This is my fixture Middleman site for OpenGraph.'
2
+ image:
3
+ '': http://mydomain.tld/path/to/og-site-image.png
4
+ secure_url: https://secure.mydomain.tld/path/to/og-site-image.png
5
+ type: image/png
6
+ width: 400
7
+ height: 300
8
+ locale:
9
+ '': en_us
10
+ alternate:
11
+ - ja_jp
12
+ - zh_tw
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: Fixture page
3
+ description: This is a ficture page
4
+ tags: ruby, middleman, blog
5
+ date: 2014-04-12 04:00
6
+ ---
7
+
8
+ h1 Hello article
9
+
10
+ p This is article
@@ -0,0 +1,11 @@
1
+ ---
2
+ title: Fixture page
3
+ description: This is a ficture page
4
+ ogp:
5
+ og:
6
+ type: website
7
+ ---
8
+
9
+ h1 Hello index
10
+
11
+ p This is index
@@ -0,0 +1,10 @@
1
+ html
2
+ head
3
+ meta charset="utf-8"
4
+ title= data.page.title
5
+ - ogp_tags do|name, value|
6
+ meta property=name content=value
7
+
8
+ body
9
+ .container
10
+ = yield
@@ -2,14 +2,52 @@ module Middleman
2
2
  module OGP
3
3
  class OGPExtension < Extension
4
4
  option :namespaces, {}, 'Default namespaces'
5
+ option :blog, false, 'Middleman Blog support'
6
+ option :auto, %w{title url description}, 'Properties to automatically fill from page data.'
7
+ option :base_url, nil, 'Base URL to generate permalink for og:url'
5
8
 
6
9
  def after_configuration
7
10
  Middleman::OGP::Helper.namespaces = options[:namespaces] || {}
11
+ Middleman::OGP::Helper.blog = options[:blog]
12
+ Middleman::OGP::Helper.auto = options[:auto]
13
+ Middleman::OGP::Helper.base_url = options[:base_url]
8
14
  end
9
15
 
10
16
  helpers do
11
17
  def ogp_tags(&block)
12
- Middleman::OGP::Helper.ogp_tags(data.page.ogp) do|name, value|
18
+ opts = data.page.ogp || {}
19
+ is_blog_article = Middleman::OGP::Helper.blog && respond_to?(:is_blog_article?) && is_blog_article?
20
+ if is_blog_article
21
+ opts.deep_merge4!({
22
+ og: {
23
+ type: 'article',
24
+ },
25
+ article: {
26
+ published_time: current_article.date.to_time.utc.iso8601,
27
+ tag: current_article.tags,
28
+ }
29
+ })
30
+ end
31
+ opts[:og] ||= {}
32
+ if Middleman::OGP::Helper.auto.include?('title')
33
+ if current_resource.data['title']
34
+ opts[:og][:title] = current_resource.data['title']
35
+ elsif content_for?(:title)
36
+ opts[:og][:title] = yield_content(:title)
37
+ end
38
+ end
39
+ if Middleman::OGP::Helper.auto.include?('description')
40
+ if current_resource.data['description']
41
+ opts[:og][:description] = current_resource.data['description']
42
+ elsif content_for?(:description)
43
+ opts[:og][:description] = yield_content(:description)
44
+ end
45
+ end
46
+ if Middleman::OGP::Helper.auto.include?('url') &&
47
+ Middleman::OGP::Helper.base_url
48
+ opts[:og][:url] = URI.join(Middleman::OGP::Helper.base_url, URI.encode(current_resource.url))
49
+ end
50
+ Middleman::OGP::Helper.ogp_tags(opts) do|name, value|
13
51
  if block_given?
14
52
  block.call name, value
15
53
  else
@@ -23,6 +61,9 @@ module Middleman
23
61
  module Helper
24
62
  include Padrino::Helpers::TagHelpers
25
63
  mattr_accessor :namespaces
64
+ mattr_accessor :blog
65
+ mattr_accessor :auto
66
+ mattr_accessor :base_url
26
67
 
27
68
  def self.ogp_tags(opts = {}, &block)
28
69
  opts ||= {}
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module OGP
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-ogp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atsushi Nagase
@@ -39,6 +39,7 @@ files:
39
39
  - LICENSE.md
40
40
  - README.md
41
41
  - Rakefile
42
+ - features/blog.feature
42
43
  - features/helper.feature
43
44
  - features/support/env.rb
44
45
  - fixtures/test-app/config.rb
@@ -47,6 +48,12 @@ files:
47
48
  - fixtures/test-app/source/index.html.slim
48
49
  - fixtures/test-app/source/layout.slim
49
50
  - fixtures/test-app/source/page.html.slim
51
+ - fixtures/test-blog/config.rb
52
+ - fixtures/test-blog/data/ogp/fb.yml
53
+ - fixtures/test-blog/data/ogp/og.yml
54
+ - fixtures/test-blog/source/2014-04-12-my-test.html.slim
55
+ - fixtures/test-blog/source/index.html.slim
56
+ - fixtures/test-blog/source/layout.slim
50
57
  - lib/middleman-ogp.rb
51
58
  - lib/middleman-ogp/extension.rb
52
59
  - lib/middleman-ogp/middleman_extension.rb
@@ -79,6 +86,7 @@ signing_key:
79
86
  specification_version: 4
80
87
  summary: OpenGraph Protocol Helper for Middleman
81
88
  test_files:
89
+ - features/blog.feature
82
90
  - features/helper.feature
83
91
  - features/support/env.rb
84
92
  - fixtures/test-app/config.rb
@@ -87,6 +95,12 @@ test_files:
87
95
  - fixtures/test-app/source/index.html.slim
88
96
  - fixtures/test-app/source/layout.slim
89
97
  - fixtures/test-app/source/page.html.slim
98
+ - fixtures/test-blog/config.rb
99
+ - fixtures/test-blog/data/ogp/fb.yml
100
+ - fixtures/test-blog/data/ogp/og.yml
101
+ - fixtures/test-blog/source/2014-04-12-my-test.html.slim
102
+ - fixtures/test-blog/source/index.html.slim
103
+ - fixtures/test-blog/source/layout.slim
90
104
  - spec/helper_spec.rb
91
105
  - spec/spec_helper.rb
92
106
  has_rdoc: