middleman-ogp 1.0.3 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rubygems.yml +30 -0
- data/.github/workflows/test.yml +21 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +28 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +16 -11
- data/README.md +36 -32
- data/Rakefile +16 -6
- data/features/blog.feature +22 -0
- data/features/helper.feature +4 -16
- data/features/support/env.rb +6 -3
- data/fixtures/test-app/config.rb +3 -0
- data/fixtures/test-app/data/ogp/fb.yml +1 -7
- data/fixtures/test-app/data/ogp/og.yml +2 -3
- data/fixtures/test-app/source/layout.slim +1 -1
- data/fixtures/test-app/source/page.html.slim +2 -9
- data/fixtures/test-blog/config.rb +2 -0
- data/fixtures/test-blog/source/2014-04-12-my-test.html.slim +8 -0
- data/fixtures/test-blog/source/2019-07-18-multi-author-test.html.slim +16 -0
- data/fixtures/test-blog/source/layout.slim +2 -2
- data/lib/middleman-ogp.rb +5 -3
- data/lib/middleman-ogp/extension.rb +97 -41
- data/lib/middleman-ogp/middleman_extension.rb +2 -1
- data/lib/middleman-ogp/version.rb +3 -1
- data/middleman-ogp.gemspec +13 -12
- data/spec/helper_spec.rb +25 -23
- data/spec/spec_helper.rb +3 -1
- metadata +15 -31
- data/.travis.yml +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e28b058adeca6fe8e0b7e97aafd4cf618400827679ee43d284e3ef6b8304a8fd
|
4
|
+
data.tar.gz: 9200114785f92ad9128b98a17b425b958d1d35c09e4a81e41751a342d3aab705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa5956a7a27974dddfa2884361d6f3dce2a109c041f1037b6dcddcdf477b03a36127d80e4bd1e548f1496912af19b01e8dfda420613971ff0ef5ab8ad1e51d7d
|
7
|
+
data.tar.gz: 453fe68b5d44ba2d4de8038c5f3bc91216442c3b4612a21f976f37ab7e48b90465b26edfb635a6114b041441ce490093d18cfb23415d9d689650fcc9046ed03a
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Publish to RubyGems
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
tags:
|
5
|
+
- v[1-9].[0-9]+.[0-9]+
|
6
|
+
jobs:
|
7
|
+
publish:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.7
|
14
|
+
- run: bundle install
|
15
|
+
- run: bundle exec rake build
|
16
|
+
- name: Export RubyGems Credentials
|
17
|
+
run: |
|
18
|
+
CRED=~/.gem/credentials
|
19
|
+
mkdir -p ~/.gem
|
20
|
+
echo "---" > $CRED
|
21
|
+
echo ":rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" >> $CRED
|
22
|
+
chmod 0600 $CRED
|
23
|
+
- name: Push gem
|
24
|
+
run: |
|
25
|
+
VERSION=$(bundle exec rake print_version)
|
26
|
+
if [ "refs/tags/v${VERSION}" != $GITHUB_REF ]; then
|
27
|
+
echo "Ref ${GITHUB_REF} not match"
|
28
|
+
exit 1
|
29
|
+
fi
|
30
|
+
gem push "pkg/middleman-ogp-${VERSION}.gem"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Run tests
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- '*'
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
ruby: [2.5, 2.6, 2.7, head, debug]
|
12
|
+
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
18
|
+
- run: bundle install
|
19
|
+
- run: bundle exec rake rubocop
|
20
|
+
- run: bundle exec rake spec
|
21
|
+
- run: bundle exec rake cucumber
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Naming/FileName:
|
2
|
+
Enabled: false
|
3
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
4
|
+
Enabled: true
|
5
|
+
Layout/SpaceAroundMethodCallOperator:
|
6
|
+
Enabled: true
|
7
|
+
Lint/DeprecatedOpenSSLConstant:
|
8
|
+
Enabled: true
|
9
|
+
Lint/RaiseException:
|
10
|
+
Enabled: true
|
11
|
+
Lint/StructNewOverride:
|
12
|
+
Enabled: true
|
13
|
+
Style/ExponentialNotation:
|
14
|
+
Enabled: true
|
15
|
+
Style/HashEachMethods:
|
16
|
+
Enabled: true
|
17
|
+
Style/HashTransformKeys:
|
18
|
+
Enabled: true
|
19
|
+
Style/HashTransformValues:
|
20
|
+
Enabled: true
|
21
|
+
Style/SlicingWithRange:
|
22
|
+
Enabled: true
|
23
|
+
Metrics/AbcSize:
|
24
|
+
Enabled: false
|
25
|
+
Metrics/CyclomaticComplexity:
|
26
|
+
Enabled: false
|
27
|
+
Metrics/PerceivedComplexity:
|
28
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -1,21 +1,26 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gem 'middleman-blog', '~> 4.0'
|
6
|
+
gem 'middleman-cli', '~> 4.3'
|
7
|
+
gem 'middleman-core', '~> 4.3'
|
5
8
|
|
6
9
|
# Specify your gem's dependencies in middleman-ogp.gemspec
|
7
10
|
gemspec
|
8
11
|
|
9
|
-
gem
|
10
|
-
gem
|
12
|
+
gem 'rake', '~> 13.0.1', require: false
|
13
|
+
gem 'rubocop', '~> 0.84.0', require: false
|
14
|
+
gem 'yard', '~> 0.9.25', require: false
|
11
15
|
|
12
16
|
# Test tools
|
13
|
-
gem
|
14
|
-
gem
|
15
|
-
gem
|
16
|
-
gem
|
17
|
+
gem 'aruba', '~> 0.14.0'
|
18
|
+
gem 'capybara', '~> 3.32.2'
|
19
|
+
gem 'cucumber', '~> 3.1.2'
|
20
|
+
gem 'fivemat'
|
21
|
+
gem 'rspec'
|
17
22
|
|
18
|
-
gem
|
23
|
+
gem 'slim'
|
19
24
|
|
20
25
|
# Code Quality
|
21
|
-
gem
|
26
|
+
gem 'cane', platforms: %i[mri_19 mri_20], require: false
|
data/README.md
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
Middleman-OGP
|
2
|
-
=============
|
1
|
+
# Middleman-OGP
|
3
2
|
|
4
|
-
`middleman-
|
3
|
+
`middleman-ogp` is an extension for the [Middleman] static site generator that adds OpenGraph Protocol support.
|
5
4
|
|
6
|
-
|
7
|
-
Configuration
|
8
|
-
-------------
|
5
|
+
## Configuration
|
9
6
|
|
10
7
|
### In your `config.rb`
|
11
8
|
|
@@ -20,10 +17,27 @@ activate :ogp do |ogp|
|
|
20
17
|
og: data.ogp.og
|
21
18
|
# from data/ogp/og.yml
|
22
19
|
}
|
23
|
-
|
20
|
+
ogp.base_url = 'http://mysite.tld/'
|
24
21
|
end
|
25
22
|
```
|
26
23
|
|
24
|
+
### In your project's root directory
|
25
|
+
|
26
|
+
Create `data/ogp/fb.yml` and `data/ogp/og.yml` files.
|
27
|
+
|
28
|
+
Example:
|
29
|
+
|
30
|
+
```yaml
|
31
|
+
image:
|
32
|
+
"": http://mydomain.tld/path/to/fbimage.png
|
33
|
+
secure_url: https://secure.mydomain.tld/path/to/fbimage.png
|
34
|
+
type: image/png
|
35
|
+
width: 400
|
36
|
+
height: 300
|
37
|
+
locale:
|
38
|
+
"": en_us
|
39
|
+
```
|
40
|
+
|
27
41
|
### In your layout
|
28
42
|
|
29
43
|
source/layout.slim
|
@@ -45,41 +59,38 @@ html
|
|
45
59
|
|
46
60
|
Page data overrides default options. (deep merge).
|
47
61
|
|
48
|
-
|
49
62
|
```markdown
|
50
63
|
---
|
51
64
|
ogp:
|
52
65
|
og:
|
53
|
-
description:
|
66
|
+
description: "This is my fixture Middleman site."
|
54
67
|
image:
|
55
|
-
|
68
|
+
"": http://mydomain.tld/path/to/fbimage.png
|
56
69
|
secure_url: https://secure.mydomain.tld/path/to/fbimage.png
|
57
70
|
type: image/png
|
58
71
|
width: 400
|
59
72
|
height: 300
|
60
73
|
locale:
|
61
|
-
|
74
|
+
"": en_us
|
62
75
|
alternate:
|
63
76
|
- ja_jp
|
64
77
|
- zh_tw
|
65
78
|
fb:
|
66
|
-
description:
|
79
|
+
description: "This is my fixture Middleman site."
|
67
80
|
image:
|
68
|
-
|
81
|
+
"": http://mydomain.tld/path/to/fbimage.png
|
69
82
|
secure_url: https://secure.mydomain.tld/path/to/fbimage.png
|
70
83
|
type: image/png
|
71
84
|
width: 400
|
72
85
|
height: 300
|
73
86
|
---
|
74
87
|
|
75
|
-
Hello
|
76
|
-
=====
|
88
|
+
# Hello
|
77
89
|
|
78
|
-
This is the
|
90
|
+
This is the **content**
|
79
91
|
```
|
80
92
|
|
81
|
-
Blog Support
|
82
|
-
------------
|
93
|
+
## Blog Support
|
83
94
|
|
84
95
|
`middleman-ogp` supports adding [article] properties like `article:published_time`, `article:tag` automatically for [middleman-blog] articles.
|
85
96
|
|
@@ -100,26 +111,19 @@ activate :ogp do |ogp|
|
|
100
111
|
end
|
101
112
|
```
|
102
113
|
|
103
|
-
|
104
|
-
Build & Dependency Status
|
105
|
-
-------------------------
|
114
|
+
## Build & Dependency Status
|
106
115
|
|
107
116
|
[![Gem Version](https://badge.fury.io/rb/middleman-ogp.png)][gem]
|
108
|
-
[![
|
109
|
-
[![Dependency Status](https://gemnasium.com/ngs/middleman-ogp.png?travis)][gemnasium]
|
110
|
-
[![Code Quality](https://codeclimate.com/github/ngs/middleman-ogp.png)][codeclimate]
|
117
|
+
[![Run tests](https://github.com/ngs/middleman-ogp/workflows/Run%20tests/badge.svg)][ghaction]
|
111
118
|
|
112
|
-
License
|
113
|
-
-------
|
119
|
+
## License
|
114
120
|
|
115
|
-
Copyright (c) 2014 [Atsushi Nagase]. MIT Licensed, see [LICENSE] for details.
|
121
|
+
Copyright (c) 2014-2020 [Atsushi Nagase]. MIT Licensed, see [LICENSE] for details.
|
116
122
|
|
117
123
|
[middleman]: http://middlemanapp.com
|
118
124
|
[middleman-blog]: https://github.com/middleman/middleman-blog
|
119
125
|
[gem]: https://rubygems.org/gems/middleman-ogp
|
120
|
-
[
|
121
|
-
[
|
122
|
-
[
|
123
|
-
[LICENSE]: https://github.com/ngs/middleman-ogp/blob/master/LICENSE.md
|
124
|
-
[Atsushi Nagase]: http://ngs.io/
|
126
|
+
[ghaction]: https://github.com/ngs/middleman-ogp/actions?query=workflow%3A%22Run+tests%22
|
127
|
+
[license]: https://github.com/ngs/middleman-ogp/blob/master/LICENSE.md
|
128
|
+
[atsushi nagase]: http://ngs.io/
|
125
129
|
[article]: http://ogp.me/#type_article
|
data/Rakefile
CHANGED
@@ -1,35 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler'
|
2
4
|
Bundler::GemHelper.install_tasks
|
3
5
|
|
4
6
|
require 'cucumber/rake/task'
|
5
7
|
require 'rspec/core/rake_task'
|
8
|
+
require 'rubocop/rake_task'
|
6
9
|
|
7
10
|
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
RuboCop::RakeTask.new
|
8
12
|
|
9
13
|
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
10
|
-
exempt_tags =
|
11
|
-
exempt_tags <<
|
14
|
+
exempt_tags = ''
|
15
|
+
exempt_tags << '--tags ~@nojava ' if RUBY_PLATFORM == 'java'
|
12
16
|
t.cucumber_opts = "--color --tags ~@wip #{exempt_tags} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
|
13
17
|
end
|
14
18
|
|
15
19
|
require 'rake/clean'
|
16
20
|
|
17
|
-
task :
|
21
|
+
task test: %w[spec cucumber]
|
18
22
|
|
19
23
|
begin
|
20
24
|
require 'cane/rake_task'
|
21
25
|
|
22
|
-
desc
|
26
|
+
desc 'Run cane to check quality metrics'
|
23
27
|
Cane::RakeTask.new(:quality) do |cane|
|
24
28
|
cane.no_style = true
|
25
29
|
cane.no_doc = true
|
26
|
-
cane.abc_glob =
|
30
|
+
cane.abc_glob = 'lib/middleman-ogp/**/*.rb'
|
27
31
|
end
|
28
32
|
rescue LoadError
|
29
33
|
# warn "cane not available, quality task not provided."
|
30
34
|
end
|
31
35
|
|
32
|
-
desc
|
36
|
+
desc 'Build HTML documentation'
|
33
37
|
task :doc do
|
34
38
|
sh 'bundle exec yard'
|
35
39
|
end
|
40
|
+
|
41
|
+
desc 'Print version'
|
42
|
+
task :print_version do
|
43
|
+
require 'rubygems'
|
44
|
+
print Gem::Specification.load('middleman-ogp.gemspec').version
|
45
|
+
end
|
data/features/blog.feature
CHANGED
@@ -14,8 +14,30 @@ Feature: Middleman Blog support
|
|
14
14
|
Then I should see '<meta content="2014-04-12T04:00:00Z" property="article:published_time" />'
|
15
15
|
Then I should see '<meta content="ruby" property="article:tag" />'
|
16
16
|
Then I should see '<meta content="middleman" property="article:tag" />'
|
17
|
+
Then I should see '<meta content="Test" property="article:author:first_name" />'
|
18
|
+
Then I should see '<meta content="Author" property="article:author:last_name" />'
|
19
|
+
Then I should see '<meta content="test_author" property="article:author:username" />'
|
20
|
+
Then I should see '<meta content="female" property="article:author:gender" />'
|
21
|
+
Then I should see '<meta content="Test Section" property="article:section" />'
|
22
|
+
Then I should see '<meta content="2014-04-13T03:00:00Z" property="article:modified_time" />'
|
23
|
+
Then I should see '<meta content="2018-04-12T04:00:00Z" property="article:expiration_time" />'
|
17
24
|
Then I should see '<meta content="blog" property="article:tag" />'
|
18
25
|
Then I should see '<meta content="http://myblog.foo.tld/2014/04/12/my-test.html" property="og:url" />'
|
19
26
|
Then I should see '<meta content="Fixture page" property="og:title" />'
|
20
27
|
|
28
|
+
Scenario: multi author article page
|
29
|
+
Given the Server is running at "test-blog"
|
30
|
+
When I go to "2019/07/18/multi-author-test.html"
|
31
|
+
Then I should see '<meta content="article" property="og:type" />'
|
32
|
+
Then I should see '<meta content="Maria" property="article:author:first_name" />'
|
33
|
+
Then I should see '<meta content="Eaton" property="article:author:last_name" />'
|
34
|
+
Then I should see '<meta content="meaton" property="article:author:username" />'
|
35
|
+
Then I should see '<meta content="female" property="article:author:gender" />'
|
36
|
+
Then I should see '<meta content="Shawn" property="article:author:first_name" />'
|
37
|
+
Then I should see '<meta content="justshawn" property="article:author:username" />'
|
38
|
+
Then I should see '<meta content="male" property="article:author:gender" />'
|
39
|
+
Then I should see '<meta content="http://myblog.foo.tld/2019/07/18/multi-author-test.html" property="og:url" />'
|
40
|
+
Then I should see '<meta content="Multi author fixture page" property="og:title" />'
|
41
|
+
|
42
|
+
|
21
43
|
|
data/features/helper.feature
CHANGED
@@ -3,15 +3,9 @@ Feature: OpenGraph Protocol Tags with the "ogp_tags" helper method
|
|
3
3
|
Scenario: Without page data
|
4
4
|
Given the Server is running at "test-app"
|
5
5
|
When I go to "/"
|
6
|
-
Then I should see '<meta content="
|
7
|
-
Then I should see '<meta content="http://mydomain.tld/path/to/fb-site-image.png" property="fb:image" />'
|
8
|
-
Then I should see '<meta content="https://secure.mydomain.tld/path/to/fb-site-image.png" property="fb:image:secure_url" />'
|
9
|
-
Then I should see '<meta content="image/png" property="fb:image:type" />'
|
10
|
-
Then I should see '<meta content="400" property="fb:image:width" />'
|
11
|
-
Then I should see '<meta content="300" property="fb:image:height" />'
|
6
|
+
Then I should see '<meta content="5678" property="fb:app_id" />'
|
12
7
|
Then I should see '<meta content="My Description" property="og:description" />'
|
13
|
-
Then I should see '<meta content="
|
14
|
-
Then I should see '<meta content="https://secure.mydomain.tld/path/to/og-site-image.png" property="og:image:secure_url" />'
|
8
|
+
Then I should see '<meta content="https://images.mydomain.tld/path/to/og-site-image.png" property="og:image" />'
|
15
9
|
Then I should see '<meta content="image/png" property="og:image:type" />'
|
16
10
|
Then I should see '<meta content="400" property="og:image:width" />'
|
17
11
|
Then I should see '<meta content="300" property="og:image:height" />'
|
@@ -24,15 +18,9 @@ Feature: OpenGraph Protocol Tags with the "ogp_tags" helper method
|
|
24
18
|
Scenario: With page data
|
25
19
|
Given the Server is running at "test-app"
|
26
20
|
When I go to "/page.html"
|
27
|
-
Then I should see '<meta content="
|
28
|
-
Then I should see '<meta content="http://mydomain.tld/path/to/fb-article-image.png" property="fb:image" />'
|
29
|
-
Then I should see '<meta content="https://secure.mydomain.tld/path/to/fb-article-image.png" property="fb:image:secure_url" />'
|
30
|
-
Then I should see '<meta content="image/png" property="fb:image:type" />'
|
31
|
-
Then I should see '<meta content="400" property="fb:image:width" />'
|
32
|
-
Then I should see '<meta content="300" property="fb:image:height" />'
|
21
|
+
Then I should see '<meta content="1234" property="fb:app_id" />'
|
33
22
|
Then I should see '<meta content="This is my fixture Middleman article." property="og:description" />'
|
34
|
-
Then I should see '<meta content="
|
35
|
-
Then I should see '<meta content="https://secure.mydomain.tld/path/to/og-article-image.png" property="og:image:secure_url" />'
|
23
|
+
Then I should see '<meta content="https://images.mydomain.tld/path/to/og-article-image.png" property="og:image" />'
|
36
24
|
Then I should see '<meta content="image/png" property="og:image:type" />'
|
37
25
|
Then I should see '<meta content="400" property="og:image:width" />'
|
38
26
|
Then I should see '<meta content="300" property="og:image:height" />'
|
data/features/support/env.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
|
2
4
|
ENV['TEST'] = 'true'
|
3
|
-
|
4
|
-
require
|
5
|
-
require
|
5
|
+
ENV['TZ'] = 'UTC'
|
6
|
+
require 'middleman-core'
|
7
|
+
require 'middleman-blog'
|
8
|
+
require 'middleman-core/step_definitions'
|
6
9
|
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-ogp')
|
data/fixtures/test-app/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
activate :ogp do |ogp|
|
2
4
|
#
|
3
5
|
# register namespace with default options
|
@@ -9,4 +11,5 @@ activate :ogp do |ogp|
|
|
9
11
|
# from data/ogp/og.yml
|
10
12
|
}
|
11
13
|
ogp.base_url = 'http://myshop.foo.tld/'
|
14
|
+
ogp.image_base_url = 'https://images.mydomain.tld/path/'
|
12
15
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
description: 'This is my fixture Middleman site for OpenGraph.'
|
2
2
|
image:
|
3
|
-
'':
|
4
|
-
secure_url: https://secure.mydomain.tld/path/to/og-site-image.png
|
3
|
+
'': to/og-site-image.png
|
5
4
|
type: image/png
|
6
5
|
width: 400
|
7
6
|
height: 300
|
@@ -9,4 +8,4 @@ locale:
|
|
9
8
|
'': en_us
|
10
9
|
alternate:
|
11
10
|
- ja_jp
|
12
|
-
- zh_tw
|
11
|
+
- zh_tw
|
@@ -5,8 +5,7 @@ ogp:
|
|
5
5
|
og:
|
6
6
|
description: 'This is my fixture Middleman article for OpenGraph.'
|
7
7
|
image:
|
8
|
-
'':
|
9
|
-
secure_url: https://secure.mydomain.tld/path/to/og-article-image.png
|
8
|
+
'': to/og-article-image.png
|
10
9
|
type: image/png
|
11
10
|
width: 400
|
12
11
|
height: 300
|
@@ -16,13 +15,7 @@ ogp:
|
|
16
15
|
- ja_jp
|
17
16
|
- zh_tw
|
18
17
|
fb:
|
19
|
-
|
20
|
-
image:
|
21
|
-
'': http://mydomain.tld/path/to/fb-article-image.png
|
22
|
-
secure_url: https://secure.mydomain.tld/path/to/fb-article-image.png
|
23
|
-
type: image/png
|
24
|
-
width: 400
|
25
|
-
height: 300
|
18
|
+
app_id: 1234
|
26
19
|
---
|
27
20
|
|
28
21
|
h1 Hello page
|
@@ -3,6 +3,14 @@ title: Fixture page
|
|
3
3
|
description: This is a ficture page
|
4
4
|
tags: ruby, middleman, blog
|
5
5
|
date: 2014-04-12 04:00
|
6
|
+
author:
|
7
|
+
first_name: Test
|
8
|
+
last_name: Author
|
9
|
+
username: test_author
|
10
|
+
gender: female
|
11
|
+
section: Test Section
|
12
|
+
modified_time: 2014-04-13 03:00
|
13
|
+
expiration_time: 2018-04-12 04:00
|
6
14
|
---
|
7
15
|
|
8
16
|
h1 Hello article
|
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
title: Multi author fixture page
|
3
|
+
date: 2019-07-18 16:45
|
4
|
+
authors:
|
5
|
+
- first_name: Maria
|
6
|
+
last_name: Eaton
|
7
|
+
username: meaton
|
8
|
+
gender: female
|
9
|
+
- first_name: Shawn
|
10
|
+
username: justshawn
|
11
|
+
gender: male
|
12
|
+
---
|
13
|
+
|
14
|
+
h1 Hello multi author article
|
15
|
+
|
16
|
+
p This is a multi author article
|
data/lib/middleman-ogp.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'middleman-core'
|
4
|
+
require 'middleman-ogp/version'
|
3
5
|
|
4
6
|
::Middleman::Extensions.register(:ogp) do
|
5
|
-
require
|
7
|
+
require 'middleman-ogp/extension'
|
6
8
|
::Middleman::OGP::OGPExtension
|
7
9
|
end
|
@@ -1,32 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'padrino-helpers'
|
4
|
+
require 'active_support'
|
5
|
+
require 'middleman-core/extensions'
|
6
|
+
|
1
7
|
module Middleman
|
2
8
|
module OGP
|
9
|
+
# Middleman::OGP::OGPExtension
|
3
10
|
class OGPExtension < Extension
|
4
|
-
option :namespaces,
|
5
|
-
option :blog,
|
6
|
-
option :auto,
|
7
|
-
option :base_url,
|
11
|
+
option :namespaces, {}, 'Default namespaces'
|
12
|
+
option :blog, false, 'Middleman Blog support'
|
13
|
+
option :auto, %w[title url description], 'Properties to automatically fill from page data.'
|
14
|
+
option :base_url, nil, 'Base URL to generate permalink for og:url'
|
15
|
+
option :image_base_url, nil, 'Base URL to generate og:image'
|
8
16
|
|
9
17
|
def after_configuration
|
10
18
|
Middleman::OGP::Helper.namespaces = options[:namespaces] || {}
|
11
19
|
Middleman::OGP::Helper.blog = options[:blog]
|
12
20
|
Middleman::OGP::Helper.auto = options[:auto]
|
13
21
|
Middleman::OGP::Helper.base_url = options[:base_url]
|
22
|
+
Middleman::OGP::Helper.image_base_url = options[:image_base_url]
|
14
23
|
end
|
15
24
|
|
16
|
-
|
17
|
-
|
18
|
-
|
25
|
+
#
|
26
|
+
helpers do # rubocop:disable Metrics/BlockLength
|
27
|
+
def ogp_tags(&block) # rubocop:disable all
|
28
|
+
opts = current_resource.data['ogp'] || {}
|
19
29
|
is_blog_article = Middleman::OGP::Helper.blog && respond_to?(:is_blog_article?) && is_blog_article?
|
20
30
|
if is_blog_article
|
21
31
|
opts.deep_merge4!({
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
og: {
|
33
|
+
type: 'article'
|
34
|
+
},
|
35
|
+
article: {
|
36
|
+
published_time: current_article.date.to_time.utc.iso8601,
|
37
|
+
tag: current_article.tags
|
38
|
+
}
|
39
|
+
})
|
40
|
+
opts[:article][:section] = current_article.data.section if current_article.data.section
|
41
|
+
if current_article.data.expiration_time
|
42
|
+
expiration_time = if current_article.data.expiration_time.is_a? Time
|
43
|
+
current_article.data.expiration_time
|
44
|
+
else
|
45
|
+
Time.parse(current_article.data.expiration_time.to_s)
|
46
|
+
end
|
47
|
+
opts[:article][:expiration_time] = expiration_time.utc.iso8601
|
48
|
+
end
|
49
|
+
if current_article.data.modified_time
|
50
|
+
modified_time = if current_article.data.modified_time.is_a? Time
|
51
|
+
current_article.data.modified_time
|
52
|
+
else
|
53
|
+
Time.parse(current_article.data.modified_time.to_s)
|
54
|
+
end
|
55
|
+
opts[:article][:modified_time] = modified_time.utc.iso8601
|
56
|
+
end
|
57
|
+
|
58
|
+
if current_article.data.author || current_article.data.authors
|
59
|
+
authors = current_article.data.authors || [current_article.data.author]
|
60
|
+
opts[:article][:author] = []
|
61
|
+
authors.each do |author|
|
62
|
+
next unless author.is_a?(Hash)
|
63
|
+
|
64
|
+
opts[:article][:author] << author.to_h.symbolize_keys.slice(
|
65
|
+
:first_name,
|
66
|
+
:last_name,
|
67
|
+
:username,
|
68
|
+
:gender
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
30
72
|
end
|
31
73
|
opts[:og] ||= {}
|
32
74
|
if Middleman::OGP::Helper.auto.include?('title')
|
@@ -44,10 +86,11 @@ module Middleman
|
|
44
86
|
end
|
45
87
|
end
|
46
88
|
if Middleman::OGP::Helper.auto.include?('url') &&
|
47
|
-
|
48
|
-
opts[:og][:url] = URI.join(Middleman::OGP::Helper.base_url,
|
89
|
+
Middleman::OGP::Helper.base_url
|
90
|
+
opts[:og][:url] = URI.join(Middleman::OGP::Helper.base_url, current_resource.url)
|
49
91
|
end
|
50
|
-
|
92
|
+
|
93
|
+
Middleman::OGP::Helper.ogp_tags(opts) do |name, value|
|
51
94
|
if block_given?
|
52
95
|
block.call name, value
|
53
96
|
else
|
@@ -58,19 +101,21 @@ module Middleman
|
|
58
101
|
end
|
59
102
|
end
|
60
103
|
|
104
|
+
# Middleman::OGP::Helper
|
61
105
|
module Helper
|
62
|
-
include Padrino::Helpers::TagHelpers
|
106
|
+
include ::Padrino::Helpers::TagHelpers
|
63
107
|
mattr_accessor :namespaces
|
64
108
|
mattr_accessor :blog
|
65
109
|
mattr_accessor :auto
|
66
110
|
mattr_accessor :base_url
|
111
|
+
mattr_accessor :image_base_url
|
67
112
|
|
68
|
-
def self.ogp_tags(opts = {}, &block)
|
113
|
+
def self.ogp_tags(opts = {}, &block) # rubocop:disable Metrics/MethodLength
|
69
114
|
opts ||= {}
|
70
115
|
options = (namespaces.respond_to?(:to_h) ? namespaces.to_h : namespaces || {}).dup
|
71
116
|
opts.stringify_keys!
|
72
117
|
options.stringify_keys!
|
73
|
-
options = options.deep_merge4(opts)
|
118
|
+
options = options.deep_merge4(opts) do |_k, old_value, new_value|
|
74
119
|
if old_value.is_a?(Hash)
|
75
120
|
if new_value.is_a? Hash
|
76
121
|
old_value.deep_merge4 new_value
|
@@ -81,13 +126,13 @@ module Middleman
|
|
81
126
|
else
|
82
127
|
new_value
|
83
128
|
end
|
84
|
-
|
85
|
-
options.map
|
129
|
+
end.symbolize_keys
|
130
|
+
options.map do |k, v|
|
86
131
|
og_tag([], v, k, &block)
|
87
|
-
|
132
|
+
end.join("\n")
|
88
133
|
end
|
89
134
|
|
90
|
-
def self.og_tag(key, obj = nil, prefix = 'og', &block)
|
135
|
+
def self.og_tag(key, obj = nil, prefix = 'og', &block) # rubocop:disable Metrics/MethodLength
|
91
136
|
case key
|
92
137
|
when String, Symbol
|
93
138
|
key = [key]
|
@@ -98,39 +143,50 @@ module Middleman
|
|
98
143
|
end
|
99
144
|
case obj
|
100
145
|
when Hash
|
101
|
-
obj.map
|
102
|
-
og_tag(k.to_s.empty? ? key.dup : (key.dup << k.to_s)
|
103
|
-
|
146
|
+
obj.map do |k, v|
|
147
|
+
og_tag(k.to_s.empty? ? key.dup : (key.dup << k.to_s), v, prefix, &block)
|
148
|
+
end.join("\n")
|
104
149
|
when Array
|
105
|
-
obj.map
|
150
|
+
obj.map do |v|
|
106
151
|
og_tag(key, v, prefix, &block)
|
107
|
-
|
152
|
+
end.join("\n")
|
108
153
|
else
|
109
|
-
|
154
|
+
if obj.respond_to?(:value)
|
155
|
+
value = obj.value
|
156
|
+
raise 'Unknown value' unless value.is_a?(Hash)
|
157
|
+
|
158
|
+
value.map do |k, v|
|
159
|
+
og_tag(k.to_s.empty? ? key.dup : (key.dup << k.to_s), v, prefix, &block)
|
160
|
+
end.join("\n")
|
161
|
+
else
|
162
|
+
name = [prefix].concat(key).join(':')
|
163
|
+
value = obj.to_s
|
164
|
+
if Middleman::OGP::Helper.image_base_url && name == 'og:image' && !%r{^https?://}.match(value)
|
165
|
+
value = URI.join(Middleman::OGP::Helper.image_base_url, value)
|
166
|
+
end
|
167
|
+
block.call name, value
|
168
|
+
end
|
110
169
|
end
|
111
170
|
end
|
112
|
-
|
113
171
|
end
|
114
172
|
end
|
115
173
|
end
|
116
174
|
|
117
|
-
|
175
|
+
# Hash extension
|
118
176
|
class Hash
|
119
|
-
|
120
177
|
def deep_merge4(other_hash, &block)
|
121
178
|
dup.deep_merge4!(other_hash, &block)
|
122
179
|
end
|
123
180
|
|
124
181
|
def deep_merge4!(other_hash, &block)
|
125
|
-
other_hash.each_pair do |k,v|
|
182
|
+
other_hash.each_pair do |k, v|
|
126
183
|
tv = self[k]
|
127
|
-
if tv.is_a?(Hash) && v.is_a?(Hash)
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
184
|
+
self[k] = if tv.is_a?(Hash) && v.is_a?(Hash)
|
185
|
+
tv.deep_merge4(v, &block)
|
186
|
+
else
|
187
|
+
block && tv ? block.call(k, tv, v) : v
|
188
|
+
end
|
132
189
|
end
|
133
190
|
self
|
134
191
|
end
|
135
|
-
|
136
192
|
end
|
data/middleman-ogp.gemspec
CHANGED
@@ -1,19 +1,20 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
require 'middleman-ogp/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
7
|
+
s.name = 'middleman-ogp'
|
7
8
|
s.version = Middleman::OGP::VERSION
|
8
9
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = [
|
10
|
-
s.email = [
|
11
|
-
s.homepage =
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
14
|
-
s.license =
|
10
|
+
s.authors = ['Atsushi Nagase']
|
11
|
+
s.email = ['a@ngs.io']
|
12
|
+
s.homepage = 'https://github.com/ngs/middleman-ogp'
|
13
|
+
s.summary = 'OpenGraph Protocol Helper for Middleman'
|
14
|
+
s.description = 'OpenGraph Protocol Helper for Middleman'
|
15
|
+
s.license = 'MIT'
|
15
16
|
s.files = `git ls-files -z`.split("\0")
|
16
17
|
s.test_files = `git ls-files -z -- {fixtures,features,spec}/*`.split("\0")
|
17
|
-
s.require_paths = [
|
18
|
-
s.add_runtime_dependency(
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
s.add_runtime_dependency('middleman-core', ['>= 4.0'])
|
19
20
|
end
|
data/spec/helper_spec.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe
|
4
|
-
subject
|
5
|
+
describe 'Middleman::OGP::Helper' do # rubocop:disable Metrics/BlockLength
|
6
|
+
subject do
|
5
7
|
Middleman::OGP::Helper.namespaces = namespaces
|
6
|
-
Middleman::OGP::Helper.ogp_tags(options) do|name, value|
|
7
|
-
%
|
8
|
+
Middleman::OGP::Helper.ogp_tags(options) do |name, value|
|
9
|
+
%(<meta property="#{name}" content="#{value}" />)
|
8
10
|
end
|
9
|
-
|
10
|
-
describe
|
11
|
+
end
|
12
|
+
describe 'default namespace and options are nil' do
|
11
13
|
let(:namespaces) { nil }
|
12
14
|
let(:options) { nil }
|
13
15
|
it { subject.should eq '' }
|
14
16
|
end
|
15
|
-
context
|
16
|
-
let(:namespaces)
|
17
|
+
context 'with default namespaces' do # rubocop:disable Metrics/BlockLength
|
18
|
+
let(:namespaces) do
|
17
19
|
{
|
18
20
|
og: {
|
19
21
|
image: {
|
@@ -27,21 +29,21 @@ describe "Middleman::OGP::Helper" do
|
|
27
29
|
description: 'foo'
|
28
30
|
}
|
29
31
|
}
|
30
|
-
|
31
|
-
describe
|
32
|
-
let(:options)
|
32
|
+
end
|
33
|
+
describe 'options is nil' do
|
34
|
+
let(:options) { nil }
|
33
35
|
it {
|
34
|
-
subject.should eq <<-
|
36
|
+
subject.should eq <<-HTML.unindent
|
35
37
|
<meta property="og:image" content="http://mydomain.tld/mysite.png" />
|
36
38
|
<meta property="og:image:type" content="image/png" />
|
37
39
|
<meta property="og:image:width" content="300" />
|
38
40
|
<meta property="og:image:height" content="400" />
|
39
41
|
<meta property="fb:description" content="foo" />
|
40
|
-
|
42
|
+
HTML
|
41
43
|
}
|
42
44
|
end
|
43
|
-
describe
|
44
|
-
let(:options)
|
45
|
+
describe 'options are presented' do
|
46
|
+
let(:options) do
|
45
47
|
{
|
46
48
|
og: {
|
47
49
|
image: 'http://mydomain.tld/myarticle.png'
|
@@ -53,35 +55,35 @@ describe "Middleman::OGP::Helper" do
|
|
53
55
|
id: '123'
|
54
56
|
}
|
55
57
|
}
|
56
|
-
|
58
|
+
end
|
57
59
|
it {
|
58
|
-
subject.should eq <<-
|
60
|
+
subject.should eq <<-HTML.unindent
|
59
61
|
<meta property="og:image" content="http://mydomain.tld/myarticle.png" />
|
60
62
|
<meta property="og:image:type" content="image/png" />
|
61
63
|
<meta property="og:image:width" content="300" />
|
62
64
|
<meta property="og:image:height" content="400" />
|
63
65
|
<meta property="fb:description" content="bar" />
|
64
66
|
<meta property="music:id" content="123" />
|
65
|
-
|
67
|
+
HTML
|
66
68
|
}
|
67
69
|
end
|
68
|
-
describe
|
69
|
-
let(:options)
|
70
|
+
describe 'only additional option is presented' do
|
71
|
+
let(:options) do
|
70
72
|
{
|
71
73
|
og: {
|
72
74
|
type: 'article'
|
73
75
|
}
|
74
76
|
}
|
75
|
-
|
77
|
+
end
|
76
78
|
it {
|
77
|
-
subject.should eq <<-
|
79
|
+
subject.should eq <<-HTML.unindent
|
78
80
|
<meta property="og:image" content="http://mydomain.tld/mysite.png" />
|
79
81
|
<meta property="og:image:type" content="image/png" />
|
80
82
|
<meta property="og:image:width" content="300" />
|
81
83
|
<meta property="og:image:height" content="400" />
|
82
84
|
<meta property="og:type" content="article" />
|
83
85
|
<meta property="fb:description" content="foo" />
|
84
|
-
|
86
|
+
HTML
|
85
87
|
}
|
86
88
|
end
|
87
89
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
PROJECT_ROOT_PATH = File.dirname(File.dirname(__FILE__))
|
2
4
|
|
3
5
|
require 'rubygems'
|
@@ -6,6 +8,6 @@ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-ogp/extension')
|
|
6
8
|
|
7
9
|
class String
|
8
10
|
def unindent
|
9
|
-
gsub(/^#{scan(/^\s*/).min_by
|
11
|
+
gsub(/^#{scan(/^\s*/).min_by(&:length)}/, '').sub(/\n$/, '')
|
10
12
|
end
|
11
13
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atsushi Nagase
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
description: OpenGraph Protocol Helper for Middleman
|
28
28
|
email:
|
29
29
|
- a@ngs.io
|
@@ -31,8 +31,10 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
- .
|
35
|
-
- .
|
34
|
+
- ".github/workflows/rubygems.yml"
|
35
|
+
- ".github/workflows/test.yml"
|
36
|
+
- ".gitignore"
|
37
|
+
- ".rubocop.yml"
|
36
38
|
- CHANGELOG.md
|
37
39
|
- CONTRIBUTING.md
|
38
40
|
- Gemfile
|
@@ -52,6 +54,7 @@ files:
|
|
52
54
|
- fixtures/test-blog/data/ogp/fb.yml
|
53
55
|
- fixtures/test-blog/data/ogp/og.yml
|
54
56
|
- fixtures/test-blog/source/2014-04-12-my-test.html.slim
|
57
|
+
- fixtures/test-blog/source/2019-07-18-multi-author-test.html.slim
|
55
58
|
- fixtures/test-blog/source/index.html.slim
|
56
59
|
- fixtures/test-blog/source/layout.slim
|
57
60
|
- lib/middleman-ogp.rb
|
@@ -71,36 +74,17 @@ require_paths:
|
|
71
74
|
- lib
|
72
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
76
|
requirements:
|
74
|
-
- -
|
77
|
+
- - ">="
|
75
78
|
- !ruby/object:Gem::Version
|
76
79
|
version: '0'
|
77
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
81
|
requirements:
|
79
|
-
- -
|
82
|
+
- - ">="
|
80
83
|
- !ruby/object:Gem::Version
|
81
84
|
version: '0'
|
82
85
|
requirements: []
|
83
|
-
|
84
|
-
rubygems_version: 2.0.14
|
86
|
+
rubygems_version: 3.1.2
|
85
87
|
signing_key:
|
86
88
|
specification_version: 4
|
87
89
|
summary: OpenGraph Protocol Helper for Middleman
|
88
|
-
test_files:
|
89
|
-
- features/blog.feature
|
90
|
-
- features/helper.feature
|
91
|
-
- features/support/env.rb
|
92
|
-
- fixtures/test-app/config.rb
|
93
|
-
- fixtures/test-app/data/ogp/fb.yml
|
94
|
-
- fixtures/test-app/data/ogp/og.yml
|
95
|
-
- fixtures/test-app/source/index.html.slim
|
96
|
-
- fixtures/test-app/source/layout.slim
|
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
|
104
|
-
- spec/helper_spec.rb
|
105
|
-
- spec/spec_helper.rb
|
106
|
-
has_rdoc:
|
90
|
+
test_files: []
|
data/.travis.yml
DELETED