middleman-ogp 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/README.md +26 -1
- data/features/blog.feature +21 -0
- data/features/helper.feature +6 -2
- data/features/support/env.rb +1 -0
- data/fixtures/test-app/config.rb +2 -1
- data/fixtures/test-app/source/index.html.slim +3 -1
- data/fixtures/test-app/source/layout.slim +1 -1
- data/fixtures/test-app/source/page.html.slim +1 -0
- data/fixtures/test-blog/config.rb +11 -0
- data/fixtures/test-blog/data/ogp/fb.yml +7 -0
- data/fixtures/test-blog/data/ogp/og.yml +12 -0
- data/fixtures/test-blog/source/2014-04-12-my-test.html.slim +10 -0
- data/fixtures/test-blog/source/index.html.slim +11 -0
- data/fixtures/test-blog/source/layout.slim +10 -0
- data/lib/middleman-ogp/extension.rb +42 -1
- data/lib/middleman-ogp/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d59dba42be8e5b8512bf6ec22df723f202d2dd40
|
4
|
+
data.tar.gz: 1f211db3d5f975d00ebe96a8851a83f7baa27b11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 371fffa46683019462bf0969620cfbcbdc0c71951aa53d5dc14192c4e044b4d02e5f1010568efb6d6f1560306c51ec35205972f57a0cfec56fad7ea785898fc4
|
7
|
+
data.tar.gz: 55985da4cd0415f0b849e699f87601f3c0eb5c901145ca5cef34522107922ca82616cf58893e5b7aa185449a32f244a81db1de3694e371049803adea434dbac9
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
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]
|
85
|
-
[][travis]
|
86
109
|
[][gemnasium]
|
87
110
|
[][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
|
+
|
data/features/helper.feature
CHANGED
@@ -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="
|
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
|
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" />'
|
data/features/support/env.rb
CHANGED
data/fixtures/test-app/config.rb
CHANGED
@@ -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
|
@@ -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
|
-
|
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 ||= {}
|
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.
|
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:
|