true_url 0.0.1 → 0.0.2
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 +4 -4
- data/.rubocop.yml +6 -0
- data/.travis.yml +3 -0
- data/Gemfile +7 -4
- data/README.md +47 -1
- data/lib/true_url/context.rb +1 -1
- data/lib/true_url/version.rb +1 -1
- data/lib/true_url.rb +1 -1
- data/true_url.gemspec +22 -22
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfa4b7a52e702e5a1665ab7fcddceeba5fad7548
|
4
|
+
data.tar.gz: de4c238df43b8a0655c5c3a8f51b55923d41aecf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5afa12c6ed53aa0be33fb080231590bbe31f4d2745844e08484de1b45ed3b342ffd0e959bb4dbbddd08a43d7437bd20a3ff114e2fc5f513b33883361ccb6428
|
7
|
+
data.tar.gz: a3e5afd1bd3ff13a64a4cdb98194de7952c264635c438be8ea0f716726f8152cbc6e0fcc3f3171c7bd69030a56e97afd2052f1f5720dbc92ce04fac5a9b9fa06
|
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1 +1,47 @@
|
|
1
|
-
|
1
|
+
[](https://badge.fury.io/rb/true_url)
|
2
|
+
[](https://codeclimate.com/github/armchairtheorist/true_url)
|
3
|
+
[](https://travis-ci.org/armchairtheorist/true_url)
|
4
|
+
|
5
|
+
# TrueURL
|
6
|
+
|
7
|
+
**TrueURL** helps normalize, clean and derive a canonical URL for any given URL. Unlike other similar projects, **TrueURL** uses a configurable multi-strategy approach, including tailored strategies for specific sites (e.g. YouTube, DailyMotion, Twitter, etc.) as well as general strategies (e.g. ```rel="canonical"```, etc.).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Install the gem from RubyGems:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install true_url
|
15
|
+
```
|
16
|
+
|
17
|
+
If you use Bundler, just add it to your Gemfile and run `bundle install`
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'true_url'
|
21
|
+
```
|
22
|
+
|
23
|
+
I have only tested this gem on Ruby 2.3.0, but there shouldn't be any reason why it wouldn't work on earlier Ruby versions as well. **TrueURL** only requires the **Addressable** gem as a dependency. if page fetching is required, then the **HTTP** and **Nokogiri** gems are also required as dependencies.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
x = TrueURL.new("https://youtu.be/RDocnbkHjhI?list=PLs4hTtftqnlAkiQNdWn6bbKUr-P1wuSm0")
|
29
|
+
puts x.canonical # => https://www.youtube.com/watch?v=RDocnbkHjhI
|
30
|
+
|
31
|
+
x = TrueURL.new("http://embed.nicovideo.jp/watch/sm25956031/script?w=490&h=307&redirect=1")
|
32
|
+
puts x.canonical # => http://www.nicovideo.jp/watch/sm25956031
|
33
|
+
|
34
|
+
x = TrueURL.new("http://t.co/fvaGuRa5Za")
|
35
|
+
puts x.canonical # => http://www.prdaily.com/Main/Articles/3_essential_skills_for_todays_PR_pro__18404.aspx
|
36
|
+
```
|
37
|
+
|
38
|
+
## Other URL Canonicalization Projects (for Ruby)
|
39
|
+
|
40
|
+
* [URLCanonicalize](https://github.com/dominicsayers/url_canonicalize)
|
41
|
+
* [UrlParser](https://github.com/activefx/url_parser)
|
42
|
+
* [PostRank URI](https://github.com/postrank-labs/postrank-uri)
|
43
|
+
* [Linkr](https://github.com/bbc/linkr)
|
44
|
+
* [Pope](https://github.com/socksforrobots/pope)
|
45
|
+
|
46
|
+
## License
|
47
|
+
**TrueURL** is released under the [MIT license](MIT-LICENSE).
|
data/lib/true_url/context.rb
CHANGED
data/lib/true_url/version.rb
CHANGED
data/lib/true_url.rb
CHANGED
@@ -102,7 +102,7 @@ class TrueURL
|
|
102
102
|
def find_canonical_header(headers)
|
103
103
|
return if headers['Link'].nil?
|
104
104
|
|
105
|
-
links =
|
105
|
+
links = headers['Link'].is_a?(String) ? [headers['Link']] : headers['Link']
|
106
106
|
links.each { |link| return link.split(/[<>;]/)[1] if link.end_with?('rel="canonical"') }
|
107
107
|
nil
|
108
108
|
end
|
data/true_url.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require File.expand_path('../lib/true_url/version', __FILE__)
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = 'true_url'
|
5
|
-
spec.version = TrueURL::VERSION
|
6
|
-
spec.authors = ['Jonathan Wong']
|
7
|
-
spec.email = ['jonathan@armchairtheorist.com']
|
8
|
-
spec.summary = 'A multi-strategy approach to find the absolutely cleanest and most likely canonical URL of any given URL.'
|
9
|
-
spec.homepage = 'http://github.com/armchairtheorist/true_url'
|
10
|
-
spec.license = 'MIT'
|
11
|
-
|
12
|
-
spec.files = `git ls-files`.split("\n")
|
13
|
-
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
|
14
|
-
spec.require_paths = ['lib']
|
15
|
-
|
16
|
-
spec.add_development_dependency 'rspec', '~> 0'
|
17
|
-
spec.add_development_dependency 'rake', '~> 0'
|
18
|
-
spec.add_development_dependency 'http', '~> 2.1',
|
19
|
-
spec.add_development_dependency 'nokogiri', '~> 1.6',
|
20
|
-
|
21
|
-
spec.add_runtime_dependency 'addressable', '~> 2.4',
|
22
|
-
end
|
1
|
+
require File.expand_path('../lib/true_url/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'true_url'
|
5
|
+
spec.version = TrueURL::VERSION
|
6
|
+
spec.authors = ['Jonathan Wong']
|
7
|
+
spec.email = ['jonathan@armchairtheorist.com']
|
8
|
+
spec.summary = 'A multi-strategy approach to find the absolutely cleanest and most likely canonical URL of any given URL.'
|
9
|
+
spec.homepage = 'http://github.com/armchairtheorist/true_url'
|
10
|
+
spec.license = 'MIT'
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split("\n")
|
13
|
+
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
|
14
|
+
spec.require_paths = ['lib']
|
15
|
+
|
16
|
+
spec.add_development_dependency 'rspec', '~> 0'
|
17
|
+
spec.add_development_dependency 'rake', '~> 0'
|
18
|
+
spec.add_development_dependency 'http', '~> 2.1', '>= 2.1.0'
|
19
|
+
spec.add_development_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'addressable', '~> 2.4', '>= 2.4.0'
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: true_url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Wong
|
@@ -107,6 +107,8 @@ extra_rdoc_files: []
|
|
107
107
|
files:
|
108
108
|
- ".gitignore"
|
109
109
|
- ".rspec"
|
110
|
+
- ".rubocop.yml"
|
111
|
+
- ".travis.yml"
|
110
112
|
- Gemfile
|
111
113
|
- LICENSE.txt
|
112
114
|
- README.md
|