canonical-rails 0.0.11 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dbb138db50b84284c942035e43ee69bf159df10
|
4
|
+
data.tar.gz: b74bab55d53c5f52e0ed132c30d2e34037853545
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95fdb9912513679fd6b345b609b987b4b4f8cf1106c2b155fb4cb4115be9fe285454893009a7ef73e87378dc6b5af69b96d533a37cd6a10be8cc4ceac689402b
|
7
|
+
data.tar.gz: c56a57c38691e76c075e7161f99abcb991c8081f7ded42610950e43bcec3d94675f0881ec9feb04bfba7281a32ea54f458d83910722e01105828dbee3a3501a0
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
CanonicalRails
|
2
2
|
==============
|
3
3
|
[](https://gemnasium.com/jumph4x/canonical-rails)
|
4
|
+
[](https://travis-ci.org/jumph4x/canonical-rails)
|
4
5
|
|
5
6
|
This project rocks and uses MIT-LICENSE, foh sho. Works with rails 3 and 4.
|
6
7
|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module CanonicalRails
|
2
2
|
module TagHelper
|
3
|
-
|
4
3
|
def trailing_slash_needed?
|
5
4
|
CanonicalRails.sym_collection_actions.include? request.params['action'].to_sym
|
6
5
|
end
|
7
6
|
|
8
7
|
def trailing_slash_if_needed
|
9
|
-
"/" if trailing_slash_needed?
|
8
|
+
"/" if trailing_slash_needed? && request.path != '/'
|
10
9
|
end
|
11
10
|
|
12
11
|
def path_without_html_extension
|
@@ -21,18 +20,22 @@ module CanonicalRails
|
|
21
20
|
CanonicalRails.host || request.host
|
22
21
|
end
|
23
22
|
|
24
|
-
def
|
25
|
-
|
23
|
+
def canonical_port
|
24
|
+
(CanonicalRails.port || request.port).to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
def canonical_href(host = canonical_host, port = canonical_port)
|
28
|
+
port = port.present? && port.to_i != 80 ? ":#{port}" : ''
|
29
|
+
raw "#{canonical_protocol}#{host}#{port}#{path_without_html_extension}#{trailing_slash_if_needed}#{whitelisted_query_string}".downcase
|
26
30
|
end
|
27
31
|
|
28
|
-
def canonical_tag(host=canonical_host)
|
29
|
-
tag(:link, :
|
32
|
+
def canonical_tag(host = canonical_host, port = canonical_port)
|
33
|
+
tag(:link, href: canonical_href(host, port), rel: :canonical)
|
30
34
|
end
|
31
35
|
|
32
36
|
def whitelisted_params
|
33
37
|
request.params.select do |key, value|
|
34
|
-
value.present?
|
35
|
-
CanonicalRails.sym_whitelisted_parameters.include? key.to_sym
|
38
|
+
value.present? && CanonicalRails.sym_whitelisted_parameters.include?(key.to_sym)
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
@@ -47,7 +50,7 @@ module CanonicalRails
|
|
47
50
|
# Rack 1.6.0 has it
|
48
51
|
# https://github.com/rack/rack/blob/65a7104b6b3e9ecd8f33c63a478ab9a33a103507/test/spec_utils.rb#L251
|
49
52
|
|
50
|
-
"?" + 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?
|
53
|
+
"?" + 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?
|
51
54
|
end
|
52
55
|
end
|
53
56
|
end
|
data/lib/canonical-rails.rb
CHANGED
@@ -9,7 +9,8 @@ CanonicalRails.setup do |config|
|
|
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
14
|
# http://en.wikipedia.org/wiki/URL_normalization
|
14
15
|
# Trailing slash represents semantics of a directory, ie a collection view - implying an :index get route;
|
15
16
|
# otherwise we have to assume semantics of an instance of a resource type, a member view - implying a :show get route
|
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.0
|
4
|
+
version: 0.1.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:
|
11
|
+
date: 2016-05-24 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: '3.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '5.
|
22
|
+
version: '5.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '3.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '5.
|
32
|
+
version: '5.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: sqlite3
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,14 +50,28 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 3.4.2
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 3.4.2
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: pry
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
61
75
|
description: 'Configurable, but assumes a conservative strategy by default with a
|
62
76
|
goal to solve many search engine index problems: multiple hostnames, inbound links
|
63
77
|
with arbitrary parameters, trailing slashes. '
|