meta-tags 2.14.0 → 2.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a5fade8f101dbfec80dc93b0ede2c9c64961497828fa4544fd7b591f889e479
4
- data.tar.gz: fb031edc1dc4f16bc286961bc9772f8e9ef34855ce12ad84ae2a3c1306cf0013
3
+ metadata.gz: 623738e419a62299132050216fd53ae9e8c6bbc44cd1f17befd3e3560a1a4b98
4
+ data.tar.gz: 89e2a81fd16a51b31512adbcb732d76fa973c01d28f30fa92cdbec8961b9b88c
5
5
  SHA512:
6
- metadata.gz: a1ce2e4321fb30f1a2a95107436e7c31f2b6da89e4979988f80cea5690e720cfc7c05997c08b084991b8a3c69f13a99b44ad60af2455dd9944aede8d6ed3c598
7
- data.tar.gz: ddb7aeb1197227116a51d70d08d9921ce1c9d7194b35dda95fccaa09e4b8caf6e67f76f83b9bd5a46f191806572330d4dac0388a8d0068752e42e33acee8bbf9
6
+ metadata.gz: e5a8ddfaa667a93609c15955690aadd8e6afa01a02f1d1c7a469a2e0621cb2f1def23efffca69bd2a1c7a2ee5bbf2a2ddf6304d29c49a1024ff36c7c4429185d
7
+ data.tar.gz: baa13d008e47c3fb9a49826435382256dc14c8395d2a3fe00adb0a80fab9ca1ae8e4f776ab20a21cbfd0f8cd8afb0ce8a12c2efbcdf0af4b7b86d65611035f54
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ # Changelog
2
+
3
+ ## 2.15.0 (August 2, 2021) [☰](https://github.com/kpumuk/meta-tags/compare/v2.14.0...v2.15.0)
4
+
5
+ Changes:
6
+
7
+ - Added Ruby 3.0 to supported versions
8
+ - Ruby 2.5 is now a required minimum version (we dropped official support for Ruby versions older than 2.5 about 8 months ago)
9
+ - Added `skip_canonical_links_on_noindex` configuration variable that allows to disable canonical links of the pages that are excluded from indexing ([214](https://github.com/kpumuk/meta-tags/pull/214))
10
+ - Added support for `itemprop` in `_` tag for custom tags ([203](https://github.com/kpumuk/meta-tags/pull/203))
11
+
12
+ Bugfixes:
13
+
14
+ - Fixed error "can't modify frozen String" in `strip_tags`.
15
+ - Fixed Ruby warning about an instance variable that is not initialized.
16
+
1
17
  ## 2.14.0 (December 10, 2020) [☰](https://github.com/kpumuk/meta-tags/compare/v2.13.0...v2.14.0)
2
18
 
3
19
  Changes:
data/CONTRIBUTING.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Contributing
2
2
 
3
3
  We love pull requests from everyone. By participating in this project, you
4
- agree to abide by the [code of conduct](https://github.com/kpumuk/meta-tags/blob/master/CODE_OF_CONDUCT.md).
4
+ agree to abide by the [code of conduct](https://github.com/kpumuk/meta-tags/blob/main/CODE_OF_CONDUCT.md).
5
5
 
6
6
  ## Configuring Development Environment
7
7
 
@@ -29,13 +29,13 @@ Make your change. Add tests for your change. Make the tests pass:
29
29
  argument for the meta tag name should be `name`:
30
30
 
31
31
  ```html
32
- <meta name="keywords" content="HTML,CSS,XML,JavaScript">
32
+ <meta name="keywords" content="HTML,CSS,XML,JavaScript" />
33
33
  ```
34
34
 
35
35
  Some social networks require to use `property` argument instead (Facebook Open Graph).
36
36
  MetaTags supports the most popular meta tags, but there will be tags that are not covered
37
37
  by default. If you found one, and you feel like the community would benefit from
38
- MetaTags supporting it out of the box, feel free to add it to [the list](https://github.com/kpumuk/meta-tags/blob/master/lib/meta_tags/configuration.rb#L23-L57)
38
+ MetaTags supporting it out of the box, feel free to add it to [the list](https://github.com/kpumuk/meta-tags/blob/main/lib/meta_tags/configuration.rb#L23-L57)
39
39
  and submit a pull request.
40
40
 
41
41
  ## Raising a Pull Request
@@ -47,6 +47,6 @@ within couple days. We may suggest some changes or improvements or alternatives.
47
47
 
48
48
  Some things that will increase the chance that your pull request is accepted:
49
49
 
50
- * Write tests.
51
- * Make sure [CodeClimate](https://codeclimate.com/github/kpumuk/meta-tags/builds) build is clean.
52
- * Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
50
+ - Write tests.
51
+ - Make sure [CodeClimate](https://codeclimate.com/github/kpumuk/meta-tags/builds) build is clean.
52
+ - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
data/Gemfile CHANGED
@@ -13,7 +13,7 @@ end
13
13
  group :test do
14
14
  # Lock rubocop to a specific version we use on CI. If you update this,
15
15
  # don't forget to switch rubocop channel in the .codeclimate.yml
16
- gem 'rubocop', '~> 0.75.0'
16
+ gem 'rubocop', '~> 1.18.0'
17
17
  # Cops for rails apps
18
18
  gem 'rubocop-rails'
19
19
  # Apply RSpec rubocop cops
data/README.md CHANGED
@@ -5,13 +5,13 @@
5
5
  [![Code Climate](https://codeclimate.com/github/kpumuk/meta-tags/badges/gpa.svg)](https://codeclimate.com/github/kpumuk/meta-tags)
6
6
  [![Test Coverage](https://codeclimate.com/github/kpumuk/meta-tags/badges/coverage.svg)](https://codeclimate.com/github/kpumuk/meta-tags/coverage)
7
7
  [![Gem Downloads](https://img.shields.io/gem/dt/meta-tags.svg)](https://badge.fury.io/rb/meta-tags)
8
- [![Changelog](https://img.shields.io/badge/Changelog-latest-blue.svg)](https://github.com/kpumuk/meta-tags/blob/master/CHANGELOG.md)
8
+ [![Changelog](https://img.shields.io/badge/Changelog-latest-blue.svg)](https://github.com/kpumuk/meta-tags/blob/main/CHANGELOG.md)
9
9
 
10
10
  Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
11
11
 
12
12
  ## Ruby on Rails
13
13
 
14
- MetaTags master branch fully supports Ruby on Rails 5.1+, and is tested against all
14
+ MetaTags main branch fully supports Ruby on Rails 5.1+, and is tested against all
15
15
  major Rails releases up to 6.1.
16
16
 
17
17
  Ruby versions older than 2.5 are no longer officially supported.
@@ -409,6 +409,9 @@ Canonical link element tells a search engine what is the canonical or main URL
409
409
  for a content which have multiple URLs. The search engine will always return
410
410
  that URL, and link popularity and authority will be applied to that URL.
411
411
 
412
+ Note: If you like follow a hint of John Mueller that you shouldn't mix canonical with noindex, then you can
413
+ set `MetaTags.config.skip_canonical_links_on_noindex = true` and we'll handle it for you.
414
+
412
415
  ```ruby
413
416
  set_meta_tags canonical: "http://yoursite.com/canonical/url"
414
417
  # <link rel="canonical" href="http://yoursite.com/canonical/url">
@@ -694,6 +697,24 @@ set_meta_tags twitter: {
694
697
  # <meta name="twitter:image:height" content="100">
695
698
  ```
696
699
 
700
+ Special parameter `itemprop` can be used on a "anonymous" tag "\_" to generate "itemprop" HTML attribute:
701
+
702
+ ```ruby
703
+ set_meta_tags twitter: {
704
+ card: "photo",
705
+ image: {
706
+ _: "http://example.com/1.png",
707
+ width: 100,
708
+ height: 100,
709
+ itemprop: "image",
710
+ }
711
+ }
712
+ # <meta name="twitter:card" content="photo">
713
+ # <meta name="twitter:image" content="http://example.com/1.png" itemprop="image">
714
+ # <meta name="twitter:image:width" content="100">
715
+ # <meta name="twitter:image:height" content="100">
716
+ ```
717
+
697
718
  Further reading:
698
719
 
699
720
  - [Twitter Cards Documentation](https://dev.twitter.com/cards/)
data/lib/meta_tags.rb CHANGED
@@ -32,4 +32,4 @@ require 'meta_tags/content_tag'
32
32
  require 'meta_tags/text_normalizer'
33
33
  require 'meta_tags/view_helper'
34
34
 
35
- require 'meta_tags/railtie.rb' if defined?(Rails)
35
+ require 'meta_tags/railtie' if defined?(Rails)
@@ -33,6 +33,12 @@ module MetaTags
33
33
  # - an array of strings or symbols representing their names or name-prefixes.
34
34
  attr_reader :property_tags
35
35
 
36
+ # Configure whenever Meta-Tags should skip canonicals on pages with noindex: true
37
+ # "shouldn't mix noindex & rel=canonical comes from: they're very contradictory pieces of information for us."
38
+ # - John Mueller (Webmaster Trends Analyst at Google)
39
+ # https://www.reddit.com/r/TechSEO/comments/8yahdr/2_questions_about_the_canonical_tag/e2dey9i/
40
+ attr_accessor :skip_canonical_links_on_noindex
41
+
36
42
  # Initializes a new instance of Configuration class.
37
43
  def initialize
38
44
  reset_defaults!
@@ -77,6 +83,7 @@ module MetaTags
77
83
  @property_tags = default_property_tags.dup
78
84
  @open_meta_tags = true
79
85
  @minify_output = false
86
+ @skip_canonical_links_on_noindex = false
80
87
  end
81
88
  end
82
89
  end
@@ -15,9 +15,9 @@ module MetaTags
15
15
  # Processes the <tt>@page_title</tt>, <tt>@page_keywords</tt>, and
16
16
  # <tt>@page_description</tt> instance variables and calls +render+.
17
17
  def render(*args, &block)
18
- meta_tags[:title] = @page_title if @page_title
19
- meta_tags[:keywords] = @page_keywords if @page_keywords
20
- meta_tags[:description] = @page_description if @page_description
18
+ meta_tags[:title] = @page_title if defined?(@page_title) && @page_title
19
+ meta_tags[:keywords] = @page_keywords if defined?(@page_keywords) && @page_keywords
20
+ meta_tags[:description] = @page_description if defined?(@page_description) && @page_description
21
21
 
22
22
  super
23
23
  end
@@ -26,6 +26,7 @@ module MetaTags
26
26
  render_with_normalization(tags, :description)
27
27
  render_with_normalization(tags, :keywords)
28
28
  render_refresh(tags)
29
+ render_canonical_link(tags)
29
30
  render_noindex(tags)
30
31
  render_alternate(tags)
31
32
  render_open_search(tags)
@@ -150,7 +151,7 @@ module MetaTags
150
151
  # @param [Array<Tag>] tags a buffer object to store tag in.
151
152
  #
152
153
  def render_links(tags)
153
- [ :amphtml, :canonical, :prev, :next, :image_src, :manifest ].each do |tag_name|
154
+ [ :amphtml, :prev, :next, :image_src, :manifest ].each do |tag_name|
154
155
  href = meta_tags.extract(tag_name)
155
156
  if href.present?
156
157
  @normalized_meta_tags[tag_name] = href
@@ -159,6 +160,19 @@ module MetaTags
159
160
  end
160
161
  end
161
162
 
163
+ # Renders canonical link
164
+ #
165
+ # @param [Array<Tag>] tags a buffer object to store tag in.
166
+ #
167
+ def render_canonical_link(tags)
168
+ href = meta_tags.extract(:canonical) # extract, so its not used anywhere else
169
+ return if MetaTags.config.skip_canonical_links_on_noindex && meta_tags[:noindex]
170
+ return if href.blank?
171
+
172
+ @normalized_meta_tags[:canonical] = href
173
+ tags << Tag.new(:link, rel: :canonical, href: href)
174
+ end
175
+
162
176
  # Renders complex hash objects.
163
177
  #
164
178
  # @param [Array<Tag>] tags a buffer object to store tag in.
@@ -201,16 +215,17 @@ module MetaTags
201
215
  # @param [Hash, Array, String, Symbol] content text content or a symbol reference to
202
216
  # top-level meta tag.
203
217
  #
204
- def process_tree(tags, property, content, **opts)
218
+ def process_tree(tags, property, content, itemprop: nil, **opts)
205
219
  method = case content
206
220
  when Hash
207
221
  :process_hash
208
222
  when Array
209
223
  :process_array
210
224
  else
225
+ iprop = itemprop
211
226
  :render_tag
212
227
  end
213
- __send__(method, tags, property, content, **opts)
228
+ __send__(method, tags, property, content, itemprop: iprop, **opts)
214
229
  end
215
230
 
216
231
  # Recursive method to process a hash with meta tags
@@ -220,10 +235,16 @@ module MetaTags
220
235
  # @param [Hash] content nested meta tag attributes.
221
236
  #
222
237
  def process_hash(tags, property, content, **opts)
238
+ itemprop = content.delete(:itemprop)
223
239
  content.each do |key, value|
224
- key = key.to_s == '_' ? property : "#{property}:#{key}"
240
+ if key.to_s == '_'
241
+ iprop = itemprop
242
+ key = property
243
+ else
244
+ key = "#{property}:#{key}"
245
+ end
225
246
  value = normalized_meta_tags[value] if value.kind_of?(Symbol)
226
- process_tree(tags, key, value, **opts)
247
+ process_tree(tags, key, value, **opts.merge(itemprop: iprop))
227
248
  end
228
249
  end
229
250
 
@@ -244,9 +265,9 @@ module MetaTags
244
265
  # @param [String, Symbol] value text content or a symbol reference to
245
266
  # top-level meta tag.
246
267
  #
247
- def render_tag(tags, name, value, name_key: nil, value_key: :content)
268
+ def render_tag(tags, name, value, itemprop: nil)
248
269
  name_key ||= configured_name_key(name)
249
- tags << Tag.new(:meta, name_key => name.to_s, value_key => value) if value.present?
270
+ tags << Tag.new(:meta, name_key => name.to_s, content: value, itemprop: itemprop) if value.present?
250
271
  end
251
272
 
252
273
  # Returns meta tag property name for a give meta tag based on the
@@ -110,10 +110,12 @@ module MetaTags
110
110
  return '' if string.nil?
111
111
  raise ArgumentError, 'Expected a string or an object that implements #to_str' unless string.respond_to?(:to_str)
112
112
 
113
- strip_tags(string.to_str).tap do |s|
114
- s.gsub!(/\s+/, ' ')
115
- s.strip! if strip
116
- end
113
+ s = strip_tags(string.to_str)
114
+ s = s.dup if s.frozen?
115
+ s.gsub!(/\s+/, ' ')
116
+ s.strip! if strip
117
+
118
+ s
117
119
  end
118
120
 
119
121
  # Cleans multiple strings up.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module MetaTags
4
4
  # Gem version.
5
- VERSION = '2.14.0'
5
+ VERSION = '2.15.0'
6
6
  public_constant :VERSION
7
7
  end
data/meta-tags.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = "http://github.com/kpumuk/meta-tags"
16
16
  spec.license = "MIT"
17
17
  spec.platform = Gem::Platform::RUBY
18
+ spec.required_ruby_version = '>= 2.5.0'
18
19
 
19
20
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(\.|(bin|test|spec|features)/)}) }
20
21
  spec.bindir = "exe"
@@ -25,7 +26,7 @@ Gem::Specification.new do |spec|
25
26
 
26
27
  spec.add_development_dependency "railties", ">= 3.2.0", "< 6.2"
27
28
  spec.add_development_dependency "rake", "~> 13.0"
28
- spec.add_development_dependency "rspec", "~> 3.9.0"
29
+ spec.add_development_dependency "rspec", "~> 3.10.0"
29
30
  spec.add_development_dependency "rspec-html-matchers", "~> 0.9.1"
30
31
 
31
32
  spec.cert_chain = ["certs/kpumuk.pem"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta-tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.0
4
+ version: 2.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmytro Shteflyuk
@@ -29,7 +29,7 @@ cert_chain:
29
29
  U97JEQmXCpruLEeSVT2UqR+iJAWEAxPzqzDbTzZBTSPKn+nXeuF6h81e4hsJtkeJ
30
30
  HkYAoatF9iZrxT4E
31
31
  -----END CERTIFICATE-----
32
- date: 2020-12-10 00:00:00.000000000 Z
32
+ date: 2021-08-02 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: actionpack
@@ -91,14 +91,14 @@ dependencies:
91
91
  requirements:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
- version: 3.9.0
94
+ version: 3.10.0
95
95
  type: :development
96
96
  prerelease: false
97
97
  version_requirements: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: 3.9.0
101
+ version: 3.10.0
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rspec-html-matchers
104
104
  requirement: !ruby/object:Gem::Requirement
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - ">="
157
157
  - !ruby/object:Gem::Version
158
- version: '0'
158
+ version: 2.5.0
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  requirements:
161
161
  - - ">="
metadata.gz.sig CHANGED
Binary file