middleman-ogp 1.3.0 → 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 +0 -1
- data/.rubocop.yml +28 -0
- data/Gemfile +26 -0
- data/README.md +19 -32
- data/Rakefile +16 -6
- data/features/blog.feature +15 -0
- data/features/support/env.rb +5 -3
- data/fixtures/test-app/config.rb +2 -0
- data/fixtures/test-blog/config.rb +2 -0
- data/fixtures/test-blog/source/2019-07-18-multi-author-test.html.slim +16 -0
- data/lib/middleman-ogp.rb +5 -3
- data/lib/middleman-ogp/extension.rb +69 -54
- 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 +11 -27
- data/.travis.yml +0 -18
- data/Gemfile.mm3 +0 -23
- data/Gemfile.mm4 +0 -23
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/Gemfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gem 'middleman-blog', '~> 4.0'
|
6
|
+
gem 'middleman-cli', '~> 4.3'
|
7
|
+
gem 'middleman-core', '~> 4.3'
|
8
|
+
|
9
|
+
# Specify your gem's dependencies in middleman-ogp.gemspec
|
10
|
+
gemspec
|
11
|
+
|
12
|
+
gem 'rake', '~> 13.0.1', require: false
|
13
|
+
gem 'rubocop', '~> 0.84.0', require: false
|
14
|
+
gem 'yard', '~> 0.9.25', require: false
|
15
|
+
|
16
|
+
# Test tools
|
17
|
+
gem 'aruba', '~> 0.14.0'
|
18
|
+
gem 'capybara', '~> 3.32.2'
|
19
|
+
gem 'cucumber', '~> 3.1.2'
|
20
|
+
gem 'fivemat'
|
21
|
+
gem 'rspec'
|
22
|
+
|
23
|
+
gem 'slim'
|
24
|
+
|
25
|
+
# Code Quality
|
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
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
|
|
@@ -32,13 +29,13 @@ Example:
|
|
32
29
|
|
33
30
|
```yaml
|
34
31
|
image:
|
35
|
-
|
32
|
+
"": http://mydomain.tld/path/to/fbimage.png
|
36
33
|
secure_url: https://secure.mydomain.tld/path/to/fbimage.png
|
37
34
|
type: image/png
|
38
35
|
width: 400
|
39
36
|
height: 300
|
40
37
|
locale:
|
41
|
-
|
38
|
+
"": en_us
|
42
39
|
```
|
43
40
|
|
44
41
|
### In your layout
|
@@ -62,41 +59,38 @@ html
|
|
62
59
|
|
63
60
|
Page data overrides default options. (deep merge).
|
64
61
|
|
65
|
-
|
66
62
|
```markdown
|
67
63
|
---
|
68
64
|
ogp:
|
69
65
|
og:
|
70
|
-
description:
|
66
|
+
description: "This is my fixture Middleman site."
|
71
67
|
image:
|
72
|
-
|
68
|
+
"": http://mydomain.tld/path/to/fbimage.png
|
73
69
|
secure_url: https://secure.mydomain.tld/path/to/fbimage.png
|
74
70
|
type: image/png
|
75
71
|
width: 400
|
76
72
|
height: 300
|
77
73
|
locale:
|
78
|
-
|
74
|
+
"": en_us
|
79
75
|
alternate:
|
80
76
|
- ja_jp
|
81
77
|
- zh_tw
|
82
78
|
fb:
|
83
|
-
description:
|
79
|
+
description: "This is my fixture Middleman site."
|
84
80
|
image:
|
85
|
-
|
81
|
+
"": http://mydomain.tld/path/to/fbimage.png
|
86
82
|
secure_url: https://secure.mydomain.tld/path/to/fbimage.png
|
87
83
|
type: image/png
|
88
84
|
width: 400
|
89
85
|
height: 300
|
90
86
|
---
|
91
87
|
|
92
|
-
Hello
|
93
|
-
=====
|
88
|
+
# Hello
|
94
89
|
|
95
|
-
This is the
|
90
|
+
This is the **content**
|
96
91
|
```
|
97
92
|
|
98
|
-
Blog Support
|
99
|
-
------------
|
93
|
+
## Blog Support
|
100
94
|
|
101
95
|
`middleman-ogp` supports adding [article] properties like `article:published_time`, `article:tag` automatically for [middleman-blog] articles.
|
102
96
|
|
@@ -117,26 +111,19 @@ activate :ogp do |ogp|
|
|
117
111
|
end
|
118
112
|
```
|
119
113
|
|
120
|
-
|
121
|
-
Build & Dependency Status
|
122
|
-
-------------------------
|
114
|
+
## Build & Dependency Status
|
123
115
|
|
124
116
|
[![Gem Version](https://badge.fury.io/rb/middleman-ogp.png)][gem]
|
125
|
-
[![
|
126
|
-
[![Dependency Status](https://gemnasium.com/ngs/middleman-ogp.png?travis)][gemnasium]
|
127
|
-
[![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]
|
128
118
|
|
129
|
-
License
|
130
|
-
-------
|
119
|
+
## License
|
131
120
|
|
132
|
-
Copyright (c) 2014 [Atsushi Nagase]. MIT Licensed, see [LICENSE] for details.
|
121
|
+
Copyright (c) 2014-2020 [Atsushi Nagase]. MIT Licensed, see [LICENSE] for details.
|
133
122
|
|
134
123
|
[middleman]: http://middlemanapp.com
|
135
124
|
[middleman-blog]: https://github.com/middleman/middleman-blog
|
136
125
|
[gem]: https://rubygems.org/gems/middleman-ogp
|
137
|
-
[
|
138
|
-
[
|
139
|
-
[
|
140
|
-
[LICENSE]: https://github.com/ngs/middleman-ogp/blob/master/LICENSE.md
|
141
|
-
[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/
|
142
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
@@ -25,4 +25,19 @@ Feature: Middleman Blog support
|
|
25
25
|
Then I should see '<meta content="http://myblog.foo.tld/2014/04/12/my-test.html" property="og:url" />'
|
26
26
|
Then I should see '<meta content="Fixture page" property="og:title" />'
|
27
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
|
+
|
28
43
|
|
data/features/support/env.rb
CHANGED
@@ -1,7 +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
5
|
ENV['TZ'] = 'UTC'
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
6
|
+
require 'middleman-core'
|
7
|
+
require 'middleman-blog'
|
8
|
+
require 'middleman-core/step_definitions'
|
7
9
|
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-ogp')
|
data/fixtures/test-app/config.rb
CHANGED
@@ -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,13 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'padrino-helpers'
|
2
4
|
require 'active_support'
|
3
5
|
require 'middleman-core/extensions'
|
4
6
|
|
5
7
|
module Middleman
|
6
8
|
module OGP
|
9
|
+
# Middleman::OGP::OGPExtension
|
7
10
|
class OGPExtension < Extension
|
8
11
|
option :namespaces, {}, 'Default namespaces'
|
9
12
|
option :blog, false, 'Middleman Blog support'
|
10
|
-
option :auto, %w
|
13
|
+
option :auto, %w[title url description], 'Properties to automatically fill from page data.'
|
11
14
|
option :base_url, nil, 'Base URL to generate permalink for og:url'
|
12
15
|
option :image_base_url, nil, 'Base URL to generate og:image'
|
13
16
|
|
@@ -19,37 +22,51 @@ module Middleman
|
|
19
22
|
Middleman::OGP::Helper.image_base_url = options[:image_base_url]
|
20
23
|
end
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
#
|
26
|
+
helpers do # rubocop:disable Metrics/BlockLength
|
27
|
+
def ogp_tags(&block) # rubocop:disable all
|
24
28
|
opts = current_resource.data['ogp'] || {}
|
25
29
|
is_blog_article = Middleman::OGP::Helper.blog && respond_to?(:is_blog_article?) && is_blog_article?
|
26
30
|
if is_blog_article
|
27
31
|
opts.deep_merge4!({
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
if current_article.data.section
|
37
|
-
opts[:article][:section] = current_article.data.section
|
38
|
-
end
|
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
|
39
41
|
if current_article.data.expiration_time
|
40
|
-
|
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
|
41
48
|
end
|
42
49
|
if current_article.data.modified_time
|
43
|
-
|
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
|
44
56
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
+
)
|
53
70
|
end
|
54
71
|
end
|
55
72
|
end
|
@@ -69,11 +86,11 @@ module Middleman
|
|
69
86
|
end
|
70
87
|
end
|
71
88
|
if Middleman::OGP::Helper.auto.include?('url') &&
|
72
|
-
|
73
|
-
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)
|
74
91
|
end
|
75
92
|
|
76
|
-
Middleman::OGP::Helper.ogp_tags(opts) do|name, value|
|
93
|
+
Middleman::OGP::Helper.ogp_tags(opts) do |name, value|
|
77
94
|
if block_given?
|
78
95
|
block.call name, value
|
79
96
|
else
|
@@ -84,6 +101,7 @@ module Middleman
|
|
84
101
|
end
|
85
102
|
end
|
86
103
|
|
104
|
+
# Middleman::OGP::Helper
|
87
105
|
module Helper
|
88
106
|
include ::Padrino::Helpers::TagHelpers
|
89
107
|
mattr_accessor :namespaces
|
@@ -92,12 +110,12 @@ module Middleman
|
|
92
110
|
mattr_accessor :base_url
|
93
111
|
mattr_accessor :image_base_url
|
94
112
|
|
95
|
-
def self.ogp_tags(opts = {}, &block)
|
113
|
+
def self.ogp_tags(opts = {}, &block) # rubocop:disable Metrics/MethodLength
|
96
114
|
opts ||= {}
|
97
115
|
options = (namespaces.respond_to?(:to_h) ? namespaces.to_h : namespaces || {}).dup
|
98
116
|
opts.stringify_keys!
|
99
117
|
options.stringify_keys!
|
100
|
-
options = options.deep_merge4(opts)
|
118
|
+
options = options.deep_merge4(opts) do |_k, old_value, new_value|
|
101
119
|
if old_value.is_a?(Hash)
|
102
120
|
if new_value.is_a? Hash
|
103
121
|
old_value.deep_merge4 new_value
|
@@ -108,13 +126,13 @@ module Middleman
|
|
108
126
|
else
|
109
127
|
new_value
|
110
128
|
end
|
111
|
-
|
112
|
-
options.map
|
129
|
+
end.symbolize_keys
|
130
|
+
options.map do |k, v|
|
113
131
|
og_tag([], v, k, &block)
|
114
|
-
|
132
|
+
end.join("\n")
|
115
133
|
end
|
116
134
|
|
117
|
-
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
|
118
136
|
case key
|
119
137
|
when String, Symbol
|
120
138
|
key = [key]
|
@@ -125,28 +143,26 @@ module Middleman
|
|
125
143
|
end
|
126
144
|
case obj
|
127
145
|
when Hash
|
128
|
-
obj.map
|
129
|
-
og_tag(k.to_s.empty? ? key.dup : (key.dup << k.to_s)
|
130
|
-
|
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")
|
131
149
|
when Array
|
132
|
-
obj.map
|
150
|
+
obj.map do |v|
|
133
151
|
og_tag(key, v, prefix, &block)
|
134
|
-
|
152
|
+
end.join("\n")
|
135
153
|
else
|
136
154
|
if obj.respond_to?(:value)
|
137
155
|
value = obj.value
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
raise 'Unknown value'
|
144
|
-
end
|
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")
|
145
161
|
else
|
146
162
|
name = [prefix].concat(key).join(':')
|
147
163
|
value = obj.to_s
|
148
164
|
if Middleman::OGP::Helper.image_base_url && name == 'og:image' && !%r{^https?://}.match(value)
|
149
|
-
value = URI.join(Middleman::OGP::Helper.image_base_url,
|
165
|
+
value = URI.join(Middleman::OGP::Helper.image_base_url, value)
|
150
166
|
end
|
151
167
|
block.call name, value
|
152
168
|
end
|
@@ -156,22 +172,21 @@ module Middleman
|
|
156
172
|
end
|
157
173
|
end
|
158
174
|
|
175
|
+
# Hash extension
|
159
176
|
class Hash
|
160
|
-
|
161
177
|
def deep_merge4(other_hash, &block)
|
162
178
|
dup.deep_merge4!(other_hash, &block)
|
163
179
|
end
|
164
180
|
|
165
181
|
def deep_merge4!(other_hash, &block)
|
166
|
-
other_hash.each_pair do |k,v|
|
182
|
+
other_hash.each_pair do |k, v|
|
167
183
|
tv = self[k]
|
168
|
-
if tv.is_a?(Hash) && v.is_a?(Hash)
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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
|
173
189
|
end
|
174
190
|
self
|
175
191
|
end
|
176
|
-
|
177
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-ogp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
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
|
@@ -16,14 +16,14 @@ dependencies:
|
|
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,12 +31,13 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".github/workflows/rubygems.yml"
|
35
|
+
- ".github/workflows/test.yml"
|
34
36
|
- ".gitignore"
|
35
|
-
- ".
|
37
|
+
- ".rubocop.yml"
|
36
38
|
- CHANGELOG.md
|
37
39
|
- CONTRIBUTING.md
|
38
|
-
- Gemfile
|
39
|
-
- Gemfile.mm4
|
40
|
+
- Gemfile
|
40
41
|
- LICENSE.md
|
41
42
|
- README.md
|
42
43
|
- Rakefile
|
@@ -53,6 +54,7 @@ files:
|
|
53
54
|
- fixtures/test-blog/data/ogp/fb.yml
|
54
55
|
- fixtures/test-blog/data/ogp/og.yml
|
55
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
|
56
58
|
- fixtures/test-blog/source/index.html.slim
|
57
59
|
- fixtures/test-blog/source/layout.slim
|
58
60
|
- lib/middleman-ogp.rb
|
@@ -81,26 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
83
|
- !ruby/object:Gem::Version
|
82
84
|
version: '0'
|
83
85
|
requirements: []
|
84
|
-
|
85
|
-
rubygems_version: 2.6.13
|
86
|
+
rubygems_version: 3.1.2
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
89
|
summary: OpenGraph Protocol Helper for Middleman
|
89
|
-
test_files:
|
90
|
-
- features/blog.feature
|
91
|
-
- features/helper.feature
|
92
|
-
- features/support/env.rb
|
93
|
-
- fixtures/test-app/config.rb
|
94
|
-
- fixtures/test-app/data/ogp/fb.yml
|
95
|
-
- fixtures/test-app/data/ogp/og.yml
|
96
|
-
- fixtures/test-app/source/index.html.slim
|
97
|
-
- fixtures/test-app/source/layout.slim
|
98
|
-
- fixtures/test-app/source/page.html.slim
|
99
|
-
- fixtures/test-blog/config.rb
|
100
|
-
- fixtures/test-blog/data/ogp/fb.yml
|
101
|
-
- fixtures/test-blog/data/ogp/og.yml
|
102
|
-
- fixtures/test-blog/source/2014-04-12-my-test.html.slim
|
103
|
-
- fixtures/test-blog/source/index.html.slim
|
104
|
-
- fixtures/test-blog/source/layout.slim
|
105
|
-
- spec/helper_spec.rb
|
106
|
-
- spec/spec_helper.rb
|
90
|
+
test_files: []
|
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
rvm:
|
2
|
-
- 2.0.0
|
3
|
-
- 2.1.0
|
4
|
-
- 2.2.2
|
5
|
-
- 2.3.1
|
6
|
-
- jruby-19mode
|
7
|
-
env:
|
8
|
-
- MM_VERSION=3 TEST=true
|
9
|
-
- MM_VERSION=4 TEST=true
|
10
|
-
|
11
|
-
# Bug in jRuby w/ Rouge: https://github.com/jruby/jruby/issues/1392
|
12
|
-
matrix:
|
13
|
-
allow_failures:
|
14
|
-
- rvm: jruby-19mode
|
15
|
-
|
16
|
-
before_install: "ln -s \"Gemfile.mm${MM_VERSION}\" Gemfile"
|
17
|
-
|
18
|
-
script: "bundle exec rake test"
|
data/Gemfile.mm3
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gem "middleman-core", '~> 3.2'
|
4
|
-
gem "middleman-blog", '~> 3.5'
|
5
|
-
|
6
|
-
# Specify your gem's dependencies in middleman-ogp.gemspec
|
7
|
-
gemspec
|
8
|
-
|
9
|
-
gem "rake", "~> 10.1.0", :require => false
|
10
|
-
gem "yard", "~> 0.8.0", :require => false
|
11
|
-
|
12
|
-
# Test tools
|
13
|
-
gem "cucumber", "~> 2.4.0"
|
14
|
-
gem "fivemat"
|
15
|
-
gem "aruba", "~> 0.14.0"
|
16
|
-
gem "rspec"
|
17
|
-
|
18
|
-
gem "slim"
|
19
|
-
|
20
|
-
# Code Quality
|
21
|
-
gem "cane", :platforms => [:mri_19, :mri_20], :require => false
|
22
|
-
|
23
|
-
|
data/Gemfile.mm4
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gem "middleman-core", '~> 4.0'
|
4
|
-
gem "middleman-cli", '~> 4.0'
|
5
|
-
gem "middleman-blog", '~> 4.0'
|
6
|
-
|
7
|
-
# Specify your gem's dependencies in middleman-ogp.gemspec
|
8
|
-
gemspec
|
9
|
-
|
10
|
-
gem "rake", "~> 10.1.0", :require => false
|
11
|
-
gem "yard", "~> 0.8.0", :require => false
|
12
|
-
|
13
|
-
# Test tools
|
14
|
-
gem "cucumber", "~> 2.4.0"
|
15
|
-
gem "fivemat"
|
16
|
-
gem "aruba", "~> 0.14.0"
|
17
|
-
gem "rspec"
|
18
|
-
gem 'capybara', '~> 2.7', '>= 2.7.1'
|
19
|
-
|
20
|
-
gem "slim"
|
21
|
-
|
22
|
-
# Code Quality
|
23
|
-
gem "cane", :platforms => [:mri_19, :mri_20], :require => false
|