canonical-rails 0.1.2 → 0.2.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
  SHA1:
3
- metadata.gz: 869cd13978490822f6915a4ed4398e349334ac17
4
- data.tar.gz: ebc920d8a0f5f77d607530235d186d562b308f8a
3
+ metadata.gz: 2e409d478f171870d36aa17c3ed45dca798c1e50
4
+ data.tar.gz: 28dca62d2cf3a8bec0134f22a2298a353f95e437
5
5
  SHA512:
6
- metadata.gz: e56c138eb35043f5f220e03f4ce4844b123fc9bdc9e088e8c44f2d02a08dd166f3e4ec9c92ba70fff0365bf1b1c74ed6f2a45c13c481fe4567af4a42900b08e0
7
- data.tar.gz: aa031e2f97df4104e9f20224416725be5e55d042f32e69010068f221dc2be9f52dbf7cafe5b8c5712bf2c109a12d3acb4c650a1c7eee4c05df0dd160b15b8d7a
6
+ metadata.gz: 971e25f120889a6fc7f294c51925e1fcb9106414df5b0bc19b3cc7432c8c55610335acb1cd912b420e29517f1f2a342d1e072cca87cd6889e59f169ff762993b
7
+ data.tar.gz: bbe5092d65dfa2828d81f19221dfef185a8d2c58fa593131c398383aaad0e870b382036a802b51721877f53541d638c7450e627006d4fff217a8342686937330
data/README.md CHANGED
@@ -15,7 +15,7 @@ Take a look at this blog post that can guide you through the idea and the setup:
15
15
 
16
16
  ## Challenge
17
17
 
18
- I've seen a lot of folks do more harm by neglecting canonicalization altogether than by applying to narrowly and conservatively, so here is an attempt to let people start modestly without spending too much time on it and whitelist parameters as they need to.
18
+ I've seen a lot of folks do more harm by neglecting canonicalization altogether than by applying too narrowly and conservatively, so here is an attempt to let people start modestly without spending too much time on it and whitelist parameters as they need to.
19
19
 
20
20
  ## Install
21
21
 
@@ -31,13 +31,21 @@ module CanonicalRails
31
31
  end
32
32
 
33
33
  def canonical_tag(host = canonical_host, port = canonical_port)
34
- tag(:link, href: canonical_href(host, port), rel: :canonical)
34
+ canonical_url = canonical_href(host, port)
35
+ capture do
36
+ if CanonicalRails.opengraph_url
37
+ concat tag(:meta, property: 'og:url', content: canonical_url)
38
+ end
39
+ concat tag(:link, href: canonical_url, rel: :canonical)
40
+ end
35
41
  end
36
42
 
37
43
  def whitelisted_params
38
- params.select do |key, value|
44
+ selected_params = params.select do |key, value|
39
45
  value.present? && CanonicalRails.sym_whitelisted_parameters.include?(key.to_sym)
40
46
  end
47
+
48
+ selected_params.respond_to?(:to_unsafe_h) ? selected_params.to_unsafe_h : selected_params.to_h
41
49
  end
42
50
 
43
51
  def whitelisted_query_string
@@ -51,7 +59,15 @@ module CanonicalRails
51
59
  # Rack 1.6.0 has it
52
60
  # https://github.com/rack/rack/blob/65a7104b6b3e9ecd8f33c63a478ab9a33a103507/test/spec_utils.rb#L251
53
61
 
54
- "?" + Rack::Utils.build_nested_query(Hash[whitelisted_params.map { |k, v| v.is_a?(Numeric) ? [k, v.to_s] : [k, v] }]) if whitelisted_params.present?
62
+ wl_params = whitelisted_params
63
+
64
+ "?" + Rack::Utils.build_nested_query(convert_numeric_params(wl_params)) if wl_params.present?
65
+ end
66
+
67
+ private
68
+
69
+ def convert_numeric_params(params_hash)
70
+ Hash[params_hash.map { |k, v| v.is_a?(Numeric) ? [k, v.to_s] : [k, v] }]
55
71
  end
56
72
  end
57
73
  end
@@ -26,6 +26,9 @@ module CanonicalRails
26
26
  mattr_accessor :whitelisted_parameters
27
27
  @@whitelisted_parameters = []
28
28
 
29
+ mattr_accessor :opengraph_url
30
+ @@opengraph_url = false
31
+
29
32
  def self.sym_collection_actions
30
33
  @@sym_collection_actions ||= self.collection_actions.map(&:to_sym)
31
34
  end
@@ -1,3 +1,3 @@
1
1
  module CanonicalRails
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,13 +1,13 @@
1
- # Do yourself a favor and set these up right when you install the engine.
1
+ # Do yourself a favor and set these up right when you install the engine.
2
2
 
3
3
  CanonicalRails.setup do |config|
4
4
 
5
5
  # Force the protocol. If you do not specify, the protocol will be based on the incoming request's protocol.
6
6
 
7
7
  config.protocol#= 'https://'
8
-
8
+
9
9
  # This is the main host, not just the TLD, omit slashes and protocol. If you have more than one, pick the one you want to rank in search results.
10
-
10
+
11
11
  config.host# = 'www.mywebstore.com'
12
12
  config.port# = '3000'
13
13
 
@@ -16,12 +16,14 @@ CanonicalRails.setup do |config|
16
16
  # otherwise we have to assume semantics of an instance of a resource type, a member view - implying a :show get route
17
17
  #
18
18
  # Acts as a whitelist for routes to have trailing slashes
19
-
19
+
20
20
  config.collection_actions# = [:index]
21
21
 
22
22
  # Parameter spamming can cause index dilution by creating seemingly different URLs with identical or near-identical content.
23
23
  # Unless whitelisted, these parameters will be omitted
24
-
24
+
25
25
  config.whitelisted_parameters# = []
26
-
26
+
27
+ # Output a matching OpenGraph URL meta tag (og:url) with the canonical URL, as recommended by Facebook et al
28
+ config.opengraph_url#= true
27
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canonical-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Ivanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.1'
22
+ version: '5.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.1'
32
+ version: '5.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: appraisal
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.5.2
128
+ rubygems_version: 2.6.10
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Simple and configurable Rails canonical ref tag helper