middleman-meta-tags 0.3.0 → 0.7.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/ruby.yml +23 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +21 -1
- data/README.md +21 -7
- data/lib/middleman-meta-tags/extension.rb +1 -0
- data/lib/middleman-meta-tags/helpers.rb +153 -40
- data/lib/middleman-meta-tags/version.rb +1 -1
- data/middleman-meta-tags.gemspec +2 -1
- data/spec/middleman-meta-tags/helpers_spec.rb +118 -0
- data/spec/spec_helper.rb +6 -0
- metadata +30 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4136f9598fca0724748c1db041a36bbd41f57e734abe96ded4e2c2595e9765c2
|
4
|
+
data.tar.gz: 9cd54689e62522011bdb968b8e140f365310c1475ce25d4a39a9b71c88b9f874
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 289ab13ebc08cfef692870033b05efb9adc7ccda75f3904409f46f0285e96ea4f60bd5cca6a6b0c540f7103e214f895e4af4f91525990267e8c5c8b5d61e40a5
|
7
|
+
data.tar.gz: ea93d7c51a5a40d0ea1d94c6a1e740ef3a1d2f4ffdb8b39cacec8d067632252166be86ac1eb0ea7fde1f2e480b836d988a935d1b644124f0394501e06e703e04
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 2.6
|
20
|
+
- name: Install dependencies
|
21
|
+
run: bundle install
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2
|
1
|
+
ruby-2.6.2
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,24 @@
|
|
1
|
-
##
|
1
|
+
## 0.7.0 (13/11/21)
|
2
|
+
|
3
|
+
* Add middleman 4.4 support
|
4
|
+
|
5
|
+
## 0.6.0 (11/03/20)
|
6
|
+
|
7
|
+
* Allow viewport to be customized
|
8
|
+
* Add ability to not have images in meta data
|
9
|
+
* Use a newer version of Ruby
|
10
|
+
|
11
|
+
## 0.5.0 (08/01/20)
|
12
|
+
|
13
|
+
* Description truncate to 220 chars
|
14
|
+
* Add test
|
15
|
+
* Add more tags
|
16
|
+
|
17
|
+
## 0.4.0 (03/28/18)
|
18
|
+
|
19
|
+
* Added support for the meta HTTP refresh tag
|
20
|
+
* i18n compatibility for title and meta tags
|
21
|
+
* Description truncate to 300 chars
|
2
22
|
|
3
23
|
## 0.3.0 (01/30/17)
|
4
24
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Middleman MetaTags
|
1
|
+
# Middleman MetaTags [![Ruby](https://github.com/tiste/middleman-meta-tags/actions/workflows/ruby.yml/badge.svg)](https://github.com/tiste/middleman-meta-tags/actions/workflows/ruby.yml)
|
2
2
|
|
3
3
|
SEO gem for your Middleman apps.
|
4
4
|
|
@@ -49,6 +49,14 @@ set_meta_tags keywords: %w(some seo keywords).join(', ')
|
|
49
49
|
keywords %w(some seo keywords).join(', ')
|
50
50
|
```
|
51
51
|
|
52
|
+
### Meta-Refresh
|
53
|
+
|
54
|
+
To set the HTTP Meta-Refresh property of a page, use the `refresh` key:
|
55
|
+
|
56
|
+
```rb
|
57
|
+
set_meta_tags refresh: "0;url=http://example.com/"
|
58
|
+
```
|
59
|
+
|
52
60
|
## Display meta tags
|
53
61
|
|
54
62
|
Into your `<head></head>` tag:
|
@@ -79,14 +87,14 @@ Then it looks the page meta data to attempt to display the following keys:
|
|
79
87
|
- MM `twitter_card` (defaults to `summary_large_image`) => META `twitter:card`
|
80
88
|
- MM `twitter_author` => META `twitter:creator`
|
81
89
|
- MM `description` => META `twitter:description`
|
82
|
-
- MM `
|
90
|
+
- MM `thumbnail` => META `twitter:image:src`
|
83
91
|
- MM `publisher_twitter` => META `twitter:site`
|
84
92
|
- MM `title` => META `twitter:title`
|
85
93
|
- MM `description` => META `og:description`
|
86
|
-
- MM `
|
94
|
+
- MM `thumbnail` => META `og:image`
|
87
95
|
- MM `site` => META `og:site_name`
|
88
96
|
- MM `title` => META `og:title`
|
89
|
-
- MM `host` => optional attribute for composing `
|
97
|
+
- MM `host` => optional attribute for composing `thumbnail` src with asset helper
|
90
98
|
|
91
99
|
In addition, if you want to customize meta tags by each page's frontmatter, you
|
92
100
|
can add `customize_by_frontmatter: true` in `data/site.yml`. The priority would
|
@@ -108,10 +116,10 @@ And add it to the layouts and views that you need.
|
|
108
116
|
|
109
117
|
### Pull images
|
110
118
|
|
111
|
-
For the `
|
119
|
+
For the `thumbnail` to render for twitter metatags, a full url must be used:
|
112
120
|
|
113
121
|
```
|
114
|
-
|
122
|
+
thumbnail: 'http://example.com/path/to/image.jpg'
|
115
123
|
```
|
116
124
|
|
117
125
|
If pointing to an image in your Middleman source, you can instead specify the
|
@@ -125,7 +133,7 @@ metatags.
|
|
125
133
|
host: http://example.com
|
126
134
|
|
127
135
|
# your article
|
128
|
-
|
136
|
+
thumbnail 'page/to/image/jpg'
|
129
137
|
```
|
130
138
|
|
131
139
|
## Contributing
|
@@ -135,3 +143,9 @@ pull_image 'page/to/image/jpg'
|
|
135
143
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
136
144
|
4. Push to the branch (`git push origin my-new-feature`)
|
137
145
|
5. Create new Pull Request
|
146
|
+
|
147
|
+
## Publishing
|
148
|
+
|
149
|
+
1. Update `./lib/middleman-meta-tags/version.rb` and CHANGELOG.md
|
150
|
+
2. `gem build middleman-meta-tags.gemspec`
|
151
|
+
3. `bundle exec rake release`
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "active_support/core_ext/hash/indifferent_access"
|
2
|
+
|
1
3
|
module Middleman
|
2
4
|
module MetaTags
|
3
5
|
module Helpers
|
@@ -5,43 +7,89 @@ module Middleman
|
|
5
7
|
@meta_tags ||= ActiveSupport::HashWithIndifferentAccess.new
|
6
8
|
end
|
7
9
|
|
10
|
+
def link_tags
|
11
|
+
@link_tags ||= ActiveSupport::HashWithIndifferentAccess.new
|
12
|
+
end
|
13
|
+
|
8
14
|
def set_meta_tags(meta_tags = {})
|
9
15
|
self.meta_tags.merge! meta_tags
|
10
16
|
end
|
11
17
|
|
12
|
-
def
|
13
|
-
|
18
|
+
def set_link_tags(link_tags = {})
|
19
|
+
self.link_tags.merge! link_tags
|
14
20
|
end
|
15
21
|
|
16
|
-
def
|
17
|
-
|
22
|
+
def site_data
|
23
|
+
(data['site'] || {}).with_indifferent_access
|
18
24
|
end
|
19
25
|
|
20
26
|
def title(title = nil)
|
21
27
|
set_meta_tags(title: title) unless title.nil?
|
22
28
|
end
|
23
29
|
|
30
|
+
def description(description = nil)
|
31
|
+
set_meta_tags(description: description) unless description.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def keywords(keywords = nil)
|
35
|
+
set_meta_tags(keywords: keywords) unless keywords.nil?
|
36
|
+
end
|
37
|
+
|
24
38
|
def display_meta_tags(default = {})
|
25
39
|
result = []
|
26
40
|
meta_tags = default.merge(self.meta_tags).with_indifferent_access
|
41
|
+
link_tags = default.merge(self.link_tags)
|
42
|
+
|
43
|
+
charset = meta_tags.delete(:charset)
|
44
|
+
result << tag(:meta, charset: charset) if charset.present?
|
45
|
+
|
46
|
+
viewport = meta_tags.delete(:viewport)
|
47
|
+
result << tag(:meta, name: :viewport, content: viewport) if viewport.present?
|
27
48
|
|
28
|
-
|
49
|
+
http_equiv = meta_tags.delete('http-equiv')
|
50
|
+
result << tag(:meta, 'http-equiv': 'X-UA-Compatible', content: http_equiv) if http_equiv.present?
|
51
|
+
|
52
|
+
need_full_title = true
|
53
|
+
need_full_title = meta_tags['full_title'] unless meta_tags['full_title'].nil?
|
54
|
+
need_full_title = current_page.data['full_title'] unless current_page.data['full_title'].nil?
|
55
|
+
title = need_full_title ? full_title(meta_tags) : safe_title(meta_tags[:title])
|
29
56
|
meta_tags.delete(:title)
|
30
57
|
meta_tags.delete(:separator)
|
31
|
-
result << content_tag(:title, title)
|
58
|
+
result << content_tag(:title, title) if title.present?
|
32
59
|
|
33
60
|
description = safe_description(meta_tags.delete(:description))
|
34
|
-
result << tag(:meta, name: :description, content: description)
|
61
|
+
result << tag(:meta, name: :description, content: description) if description.present?
|
35
62
|
|
36
63
|
keywords = meta_tags.delete(:keywords)
|
37
64
|
keywords = keywords.join(', ') if keywords.is_a?(Array)
|
38
|
-
result << tag(:meta, name: :keywords, content: keywords)
|
65
|
+
result << tag(:meta, name: :keywords, content: keywords) if keywords.present?
|
66
|
+
|
67
|
+
refresh = meta_tags.delete(:refresh)
|
68
|
+
result << tag(:meta, {content: refresh, 'http-equiv': 'refresh'}) if refresh.present?
|
39
69
|
|
40
70
|
meta_tags.each do |name, content|
|
41
|
-
|
42
|
-
|
71
|
+
unless content.blank? || %(site latitude longitude).include?(name)
|
72
|
+
if name.start_with?('itemprop:')
|
73
|
+
result << tag(:meta, itemprop: name.gsub('itemprop:', ''), content: content)
|
74
|
+
elsif name.start_with?('og:')
|
75
|
+
result << tag(:meta, property: name, content: content)
|
76
|
+
else
|
77
|
+
result << tag(:meta, name: name, content: content)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
position = [meta_tags.delete(:latitude), meta_tags.delete(:longitude)] if meta_tags['latitude'] && meta_tags['longitude']
|
83
|
+
result << tag(:meta, name: 'geo:position', content: position.join(';')) if position
|
84
|
+
result << tag(:meta, name: 'ICBM', content: position.join(', ')) if position
|
85
|
+
|
86
|
+
link_tags.each do |rel, href|
|
87
|
+
if href.kind_of?(Array)
|
88
|
+
href.each do |link|
|
89
|
+
result << tag(:link, rel: rel, href: link)
|
90
|
+
end
|
43
91
|
else
|
44
|
-
result << tag(:
|
92
|
+
result << tag(:link, rel: rel, href: href) unless href.blank?
|
45
93
|
end
|
46
94
|
end
|
47
95
|
|
@@ -50,85 +98,150 @@ module Middleman
|
|
50
98
|
end
|
51
99
|
|
52
100
|
def auto_display_meta_tags(default = {})
|
53
|
-
|
101
|
+
auto_set_meta_tags
|
54
102
|
|
55
103
|
display_meta_tags default
|
56
104
|
end
|
57
105
|
|
58
|
-
def
|
59
|
-
|
106
|
+
def auto_set_meta_tags
|
107
|
+
geocoding_data = site_data['geocoding'] || {}
|
108
|
+
author_data = site_data['author'] || {}
|
60
109
|
|
61
|
-
set_meta_tags
|
62
|
-
|
110
|
+
set_meta_tags charset: 'utf-8',
|
111
|
+
'http-equiv': 'IE=edge,chrome=1'
|
63
112
|
|
113
|
+
fall_through(site_data, :site, 'name')
|
114
|
+
fall_through(site_data, :site, 'site')
|
64
115
|
fall_through(site_data, :title, 'title')
|
65
116
|
fall_through(site_data, :description, 'description')
|
66
117
|
fall_through(site_data, :keywords, 'keywords')
|
118
|
+
fall_through(site_data, :viewport, 'viewport', 'width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no')
|
119
|
+
|
120
|
+
# Microdata
|
121
|
+
fall_through(site_data, 'itemprop:name', 'name')
|
122
|
+
fall_through(site_data, 'itemprop:name', 'site')
|
123
|
+
fall_through(site_data, 'itemprop:name', 'title')
|
124
|
+
fall_through(site_data, 'itemprop:description', 'description')
|
125
|
+
fall_through_image(site_data, 'itemprop:image', 'thumbnail')
|
67
126
|
|
68
127
|
# Twitter cards
|
69
|
-
|
70
|
-
fall_through(site_data,
|
71
|
-
fall_through(site_data,
|
72
|
-
|
73
|
-
fall_through(
|
74
|
-
|
128
|
+
set_meta_tags 'twitter:card': 'summary_large_image'
|
129
|
+
fall_through(site_data, 'twitter:card', 'twitter_card')
|
130
|
+
fall_through(site_data, 'twitter:site', 'name')
|
131
|
+
fall_through(site_data, 'twitter:site', 'site')
|
132
|
+
fall_through(author_data, 'twitter:creator', 'twitter')
|
133
|
+
set_meta_tags 'twitter:url': current_page_url
|
134
|
+
fall_through(site_data, 'twitter:url', 'url')
|
135
|
+
fall_through(site_data, 'twitter:title', 'name')
|
136
|
+
fall_through(site_data, 'twitter:title', 'site')
|
137
|
+
fall_through(site_data, 'twitter:title', 'title')
|
138
|
+
fall_through(site_data, 'twitter:description', 'description')
|
139
|
+
fall_through_image(site_data, 'twitter:image', 'thumbnail')
|
75
140
|
|
76
141
|
# Open Graph
|
77
|
-
|
78
|
-
|
79
|
-
|
142
|
+
set_meta_tags 'og:url': current_page_url
|
143
|
+
fall_through(site_data, 'og:url', 'url')
|
144
|
+
set_meta_tags 'og:type': 'website'
|
145
|
+
fall_through(site_data, 'og:type', 'type')
|
146
|
+
fall_through(site_data, 'og:title', 'name')
|
147
|
+
fall_through(site_data, 'og:title', 'site')
|
148
|
+
fall_through(site_data, 'og:title', 'title')
|
149
|
+
fall_through_image(site_data, 'og:image', 'thumbnail')
|
150
|
+
fall_through(site_data, 'og:description', 'description')
|
151
|
+
fall_through(site_data, 'og:site_name', 'name')
|
152
|
+
fall_through(site_data, 'og:site_name', 'site')
|
153
|
+
set_meta_tags 'og:locale': 'en_US'
|
154
|
+
fall_through(site_data, 'og:locale', 'locale')
|
155
|
+
|
156
|
+
# Theme color
|
157
|
+
fall_through(site_data, 'theme-color', 'base_color')
|
158
|
+
fall_through(site_data, 'msapplication-TileColor', 'base_color')
|
159
|
+
|
160
|
+
# Geocoding
|
161
|
+
fall_through(geocoding_data, 'latitude', 'latitude')
|
162
|
+
fall_through(geocoding_data, 'longitude', 'longitude')
|
163
|
+
fall_through(geocoding_data, 'geo.placename', 'place')
|
164
|
+
fall_through(geocoding_data, 'geo.region', 'region')
|
165
|
+
|
166
|
+
# Author
|
167
|
+
set_link_tags author: author_data['website'] if author_data['website']
|
168
|
+
set_link_tags license: site_data['license'] if site_data['license']
|
169
|
+
|
170
|
+
me_link_tags = []
|
171
|
+
me_link_tags << author_data['website'] if author_data['website']
|
172
|
+
me_link_tags << "mailto:#{author_data['email']}" if author_data['email'].present?
|
173
|
+
me_link_tags += ["tel:#{author_data['phone']}", "sms:#{author_data['phone']}"] if author_data['phone'].present?
|
174
|
+
%w(github twitter dribbble medium linkedin facebook instagram gitlab bitbucket).each do |social|
|
175
|
+
me_link_tags << "https://#{social}#{['bitbucket'].include?(social) ? '.org' : '.com'}/#{'in/' if social == 'linkedin'}#{author_data[social]}" if author_data[social].present?
|
176
|
+
set_link_tags me: me_link_tags
|
177
|
+
end
|
80
178
|
end
|
81
179
|
|
82
|
-
|
180
|
+
private
|
83
181
|
|
84
182
|
def fall_through(site_data, name, key, default = nil)
|
85
|
-
|
86
|
-
|
87
|
-
(need_customized && current_page.data[key]) ||
|
183
|
+
value = current_page.data[key] ||
|
184
|
+
meta_tags[key] ||
|
88
185
|
site_data[key] ||
|
89
186
|
default
|
187
|
+
|
90
188
|
value = yield value if block_given?
|
91
|
-
|
189
|
+
|
190
|
+
value = safe_title(value) if key == 'title'
|
191
|
+
value = safe_description(value) if key == 'description'
|
192
|
+
|
193
|
+
set_meta_tags name => value if value.present?
|
92
194
|
value
|
93
195
|
end
|
94
196
|
|
95
197
|
def fall_through_image(*args)
|
96
198
|
fall_through(*args) do |path|
|
97
|
-
|
199
|
+
uri?(path) && path ? path : meta_tags_image_url(path)
|
98
200
|
end
|
99
201
|
end
|
100
202
|
|
203
|
+
def current_page_url
|
204
|
+
meta_tags_host + current_page.url unless (data['site'] || {})['host'].nil?
|
205
|
+
end
|
206
|
+
|
101
207
|
def meta_tags_image_url(source)
|
102
|
-
|
208
|
+
return nil unless source.present?
|
209
|
+
File.join(meta_tags_host, image_path(source))
|
103
210
|
end
|
104
211
|
|
105
212
|
def meta_tags_host
|
106
213
|
(data['site'] || {})['host'] || ''
|
107
214
|
end
|
108
215
|
|
109
|
-
|
110
|
-
# http://apidock.com/rails/v3.2.8/ActionView/AssetPaths/is_uri%3F
|
111
|
-
def is_uri?(path)
|
216
|
+
def uri?(path)
|
112
217
|
path =~ %r{^[-a-z]+://|^(?:cid|data):|^//}
|
113
218
|
end
|
114
219
|
|
115
220
|
def full_title(meta_tags)
|
116
|
-
separator = meta_tags[:separator] || '
|
221
|
+
separator = meta_tags[:separator] || '-'
|
117
222
|
full_title = ''
|
118
223
|
title = safe_title(meta_tags[:title])
|
119
224
|
|
120
|
-
(full_title << title)
|
225
|
+
(full_title << title) if title.present?
|
121
226
|
(full_title << " #{separator} ") unless title.blank? || meta_tags[:site].blank?
|
122
|
-
(full_title << meta_tags[:site])
|
227
|
+
(full_title << meta_tags[:site]) if meta_tags[:site].present?
|
123
228
|
full_title
|
124
229
|
end
|
125
230
|
|
126
231
|
def safe_description(description)
|
127
|
-
|
232
|
+
description = description[I18n.locale] if description.is_a?(Hash) && description[I18n.locale]
|
233
|
+
|
234
|
+
description = I18n.t(description[2..-1]) if description&.start_with?('t:')
|
235
|
+
|
236
|
+
truncate(strip_tags(description), length: 220)
|
128
237
|
end
|
129
238
|
|
130
239
|
def safe_title(title)
|
131
|
-
title =
|
240
|
+
title = title[I18n.locale] if title.is_a?(Hash) && title[I18n.locale]
|
241
|
+
|
242
|
+
title = I18n.t(title[2..-1]) if title&.start_with?('t:')
|
243
|
+
|
244
|
+
strip_tags(title)
|
132
245
|
end
|
133
246
|
end
|
134
247
|
end
|
data/middleman-meta-tags.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'middleman-core', ['>= 3.0.0']
|
22
22
|
|
23
|
-
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
24
|
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
25
26
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'middleman-core/core_extensions/data'
|
4
|
+
|
5
|
+
describe Middleman::MetaTags::Helpers do
|
6
|
+
let(:h) { Class.new { extend Middleman::MetaTags::Helpers } }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
allow(h).to receive_message_chain(:current_page, :data).and_return({ full_title: nil })
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'transforms title tag' do
|
13
|
+
h.set_meta_tags title: 'Relevant title'
|
14
|
+
expect(h.display_meta_tags).to eql('<title>Relevant title</title>')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'transforms description tag' do
|
18
|
+
h.set_meta_tags description: 'Relevant title of more than 220 characters
|
19
|
+
1 Relevant title of more than 220 characters
|
20
|
+
2 Relevant title of more than 220 characters
|
21
|
+
3 Relevant title of more than 220 characters
|
22
|
+
4 Relevant title of more than 220 characters'
|
23
|
+
expect(h.display_meta_tags).to eql('<meta name="description" content="Relevant title of more than 220 characters
|
24
|
+
1 Relevant title of more than 220 characters
|
25
|
+
2 Relevant title of more than 220 characters
|
26
|
+
3 Relevant title of more than 220 characters
|
27
|
+
4 Relevant title of more than 220 chara..." />')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'transforms keywords tag' do
|
31
|
+
h.set_meta_tags keywords: %w(some seo keywords)
|
32
|
+
expect(h.display_meta_tags).to eql('<meta name="keywords" content="some, seo, keywords" />')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'transforms site tag' do
|
36
|
+
expect(h.display_meta_tags site: 'My Awesome Website').to eql('<title>My Awesome Website</title>
|
37
|
+
<link rel="site" href="My Awesome Website" />')
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "auto_display_meta_tags" do
|
41
|
+
before do
|
42
|
+
allow(h).to receive(:data).and_return({})
|
43
|
+
end
|
44
|
+
|
45
|
+
it "includes a viewport tag" do
|
46
|
+
tags = h.auto_display_meta_tags.split("\n")
|
47
|
+
expect(tags).to include(
|
48
|
+
'<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "prefers viewport from site data" do
|
53
|
+
allow(h).to receive(:data).and_return(
|
54
|
+
{
|
55
|
+
"site" => {
|
56
|
+
"viewport" => "width=device-width,user-scalable=yes"
|
57
|
+
}
|
58
|
+
}
|
59
|
+
)
|
60
|
+
|
61
|
+
tags = h.auto_display_meta_tags.split("\n")
|
62
|
+
expect(tags).to include(
|
63
|
+
'<meta name="viewport" content="width=device-width,user-scalable=yes" />'
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "meta_tags_image_url" do
|
69
|
+
before do
|
70
|
+
allow(h).to receive(:data).and_return(
|
71
|
+
{
|
72
|
+
"site" => {
|
73
|
+
"host" => "https://example.com"
|
74
|
+
}
|
75
|
+
}
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns a URL when image is given" do
|
80
|
+
expect(
|
81
|
+
h.send(:meta_tags_image_url, "/awesome/image.jpg")
|
82
|
+
).to eq("https://example.com/awesome/image.jpg")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "returns nil when image is nil" do
|
86
|
+
expect(
|
87
|
+
h.send(:meta_tags_image_url, nil)
|
88
|
+
).to be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "site_data" do
|
93
|
+
before do
|
94
|
+
app = :app
|
95
|
+
data_store = Middleman::CoreExtensions::Data::DataStore.new(
|
96
|
+
app,
|
97
|
+
Middleman::CoreExtensions::Data::DATA_FILE_MATCHER
|
98
|
+
)
|
99
|
+
data_store.store(
|
100
|
+
:site,
|
101
|
+
{
|
102
|
+
:host => "https://middlemanapp.com/",
|
103
|
+
:site => "Middleman",
|
104
|
+
}
|
105
|
+
)
|
106
|
+
allow(h).to receive(:data).and_return(data_store)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "returns a HashWithIndifferentAccess" do
|
110
|
+
expect(h.site_data).to be_a(ActiveSupport::HashWithIndifferentAccess)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns data from the :site key" do
|
114
|
+
expect(h.site_data['site']).to eq("Middleman")
|
115
|
+
expect(h.site_data[:site]).to eq("Middleman")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-meta-tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Baptiste Lecocq
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
55
69
|
description: Easy integration of meta tags into your Middleman applications
|
56
70
|
email:
|
57
71
|
- hello@tiste.io
|
@@ -59,6 +73,7 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".github/workflows/ruby.yml"
|
62
77
|
- ".gitignore"
|
63
78
|
- ".ruby-gemset"
|
64
79
|
- ".ruby-version"
|
@@ -73,11 +88,13 @@ files:
|
|
73
88
|
- lib/middleman-meta-tags/version.rb
|
74
89
|
- lib/middleman_extension.rb
|
75
90
|
- middleman-meta-tags.gemspec
|
91
|
+
- spec/middleman-meta-tags/helpers_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
76
93
|
homepage: https://github.com/tiste/middleman-meta-tags
|
77
94
|
licenses:
|
78
95
|
- MIT
|
79
96
|
metadata: {}
|
80
|
-
post_install_message:
|
97
|
+
post_install_message:
|
81
98
|
rdoc_options: []
|
82
99
|
require_paths:
|
83
100
|
- lib
|
@@ -92,9 +109,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
109
|
- !ruby/object:Gem::Version
|
93
110
|
version: '0'
|
94
111
|
requirements: []
|
95
|
-
|
96
|
-
|
97
|
-
signing_key:
|
112
|
+
rubygems_version: 3.0.8
|
113
|
+
signing_key:
|
98
114
|
specification_version: 4
|
99
115
|
summary: Meta tags for Middleman
|
100
|
-
test_files:
|
116
|
+
test_files:
|
117
|
+
- spec/middleman-meta-tags/helpers_spec.rb
|
118
|
+
- spec/spec_helper.rb
|