link_thumbnailer 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.travis.yml +1 -1
- data/CHANGELOG.md +117 -104
- data/Gemfile +1 -1
- data/{LICENSE → LICENSE.txt} +21 -21
- data/README.md +153 -184
- data/lib/generators/link_thumbnailer/install_generator.rb +0 -4
- data/lib/generators/templates/initializer.rb +63 -41
- data/lib/link_thumbnailer/configuration.rb +52 -10
- data/lib/link_thumbnailer/exceptions.rb +6 -0
- data/lib/link_thumbnailer/grader.rb +37 -0
- data/lib/link_thumbnailer/graders/base.rb +32 -0
- data/lib/link_thumbnailer/graders/html_attribute.rb +49 -0
- data/lib/link_thumbnailer/graders/length.rb +19 -0
- data/lib/link_thumbnailer/graders/link_density.rb +21 -0
- data/lib/link_thumbnailer/graders/position.rb +11 -0
- data/lib/link_thumbnailer/image_comparator.rb +24 -0
- data/lib/link_thumbnailer/image_comparators/base.rb +17 -0
- data/lib/link_thumbnailer/image_comparators/size.rb +11 -0
- data/lib/link_thumbnailer/image_parser.rb +18 -0
- data/lib/link_thumbnailer/image_parsers/size.rb +15 -0
- data/lib/link_thumbnailer/image_parsers/type.rb +15 -0
- data/lib/link_thumbnailer/image_validator.rb +30 -0
- data/lib/link_thumbnailer/model.rb +16 -0
- data/lib/link_thumbnailer/models/description.rb +34 -0
- data/lib/link_thumbnailer/models/image.rb +54 -0
- data/lib/link_thumbnailer/models/title.rb +20 -0
- data/lib/link_thumbnailer/models/website.rb +39 -0
- data/lib/link_thumbnailer/page.rb +40 -0
- data/lib/link_thumbnailer/parser.rb +13 -0
- data/lib/link_thumbnailer/processor.rb +94 -0
- data/lib/link_thumbnailer/railtie.rb +9 -9
- data/lib/link_thumbnailer/scraper.rb +64 -0
- data/lib/link_thumbnailer/scrapers/base.rb +63 -0
- data/lib/link_thumbnailer/scrapers/default/base.rb +10 -0
- data/lib/link_thumbnailer/scrapers/default/description.rb +47 -0
- data/lib/link_thumbnailer/scrapers/default/images.rb +64 -0
- data/lib/link_thumbnailer/scrapers/default/title.rb +25 -0
- data/lib/link_thumbnailer/scrapers/opengraph/base.rb +43 -0
- data/lib/link_thumbnailer/scrapers/opengraph/description.rb +10 -0
- data/lib/link_thumbnailer/scrapers/opengraph/image.rb +30 -0
- data/lib/link_thumbnailer/scrapers/opengraph/images.rb +16 -0
- data/lib/link_thumbnailer/scrapers/opengraph/title.rb +10 -0
- data/lib/link_thumbnailer/version.rb +3 -3
- data/lib/link_thumbnailer.rb +36 -119
- data/link_thumbnailer.gemspec +26 -28
- data/spec/configuration_spec.rb +51 -0
- data/spec/examples/empty_og_image_example.html +9 -0
- data/spec/fixture_spec.rb +88 -0
- data/spec/fixtures/bar.png +2907 -0
- data/spec/fixtures/default_from_body.html +12 -0
- data/spec/fixtures/default_from_meta.html +11 -0
- data/spec/{examples → fixtures}/example.html +53 -53
- data/spec/fixtures/foo.png +0 -0
- data/spec/fixtures/og_not_valid_example.html +12 -0
- data/spec/fixtures/og_valid_example.html +12 -0
- data/spec/fixtures/og_valid_multi_image_example.html +13 -0
- data/spec/grader_spec.rb +24 -0
- data/spec/graders/base_spec.rb +12 -0
- data/spec/graders/html_attribute_spec.rb +48 -0
- data/spec/graders/length_spec.rb +81 -0
- data/spec/graders/link_density_spec.rb +22 -0
- data/spec/image_comparators/size_spec.rb +39 -0
- data/spec/image_parsers/size_spec.rb +34 -0
- data/spec/image_parsers/type_spec.rb +34 -0
- data/spec/image_validator_spec.rb +35 -0
- data/spec/model_spec.rb +17 -0
- data/spec/models/description_spec.rb +64 -0
- data/spec/models/image_spec.rb +71 -0
- data/spec/models/title_spec.rb +24 -0
- data/spec/models/website_spec.rb +49 -0
- data/spec/page_spec.rb +26 -0
- data/spec/processor_spec.rb +349 -0
- data/spec/scraper_spec.rb +95 -0
- data/spec/scrapers/base_spec.rb +67 -0
- data/spec/scrapers/opengraph/base_spec.rb +94 -0
- data/spec/spec_helper.rb +15 -13
- metadata +126 -120
- data/app/controllers/link_thumbnailer/application_controller.rb +0 -4
- data/app/controllers/link_thumbnailer/previews_controller.rb +0 -11
- data/lib/link_thumbnailer/doc.rb +0 -65
- data/lib/link_thumbnailer/doc_parser.rb +0 -15
- data/lib/link_thumbnailer/engine.rb +0 -4
- data/lib/link_thumbnailer/fetcher.rb +0 -34
- data/lib/link_thumbnailer/img_comparator.rb +0 -17
- data/lib/link_thumbnailer/img_parser.rb +0 -41
- data/lib/link_thumbnailer/img_url_filter.rb +0 -13
- data/lib/link_thumbnailer/object.rb +0 -41
- data/lib/link_thumbnailer/opengraph.rb +0 -20
- data/lib/link_thumbnailer/rails/routes/mapper.rb +0 -30
- data/lib/link_thumbnailer/rails/routes/mapping.rb +0 -33
- data/lib/link_thumbnailer/rails/routes.rb +0 -47
- data/lib/link_thumbnailer/web_image.rb +0 -19
- data/spec/doc_parser_spec.rb +0 -25
- data/spec/doc_spec.rb +0 -23
- data/spec/examples/empty_example.html +0 -11
- data/spec/examples/og_example.html +0 -12
- data/spec/fetcher_spec.rb +0 -97
- data/spec/img_comparator_spec.rb +0 -16
- data/spec/img_url_filter_spec.rb +0 -31
- data/spec/link_thumbnailer_spec.rb +0 -205
- data/spec/object_spec.rb +0 -130
- data/spec/opengraph_spec.rb +0 -7
- data/spec/web_image_spec.rb +0 -57
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZGY2MzVlMTM1OGQxNWEwODNjMDM2ZGIyNDIwZjAzNWZiNjI5ZmEzNA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c1f15206d5f7ec2528178fd2fc49a2c226cbd1d7
|
4
|
+
data.tar.gz: b10ea72d36315c40263688402b268075264131f6
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YTk0ZTJjOTg5YWJjZDBjN2U5NWM2ODg3YzRiNGY3ZGYzZGU3NTE0YzE2YjM3
|
11
|
-
MDIyM2UwNTQ3MmJkZWY4YzcwZjkzNWU0ZjRiNzNmMmViNzA2MTM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MGI4ZjIwNWEzODIwN2E4YjA0MGVjYWY1NzUzZGE0Njk3MzcxOTA0Zjk3OGY5
|
14
|
-
YmFkZmM3MTE3ODc5Mzk2OTYxZTY0NTQwYjY0NjQwNzFjODY5NmY2MDE2MDFj
|
15
|
-
ODY0NWYxMzNmMTAzY2FkYjU5YzY3YTg2ODhmNjhhODFlYzc5ZjA=
|
6
|
+
metadata.gz: fd9cb26e28184c783f82f866173b49988ceba7b62f04a26930be127e3382fdcfb7f891f9f21d73cbbfc176b61a29ed6581f7cbd9b52fe56bc474c7ba10cdacd9
|
7
|
+
data.tar.gz: 426fb6ec3bf6f2118807d7eb281b36fa1abb1bccce060b85e734704bb5489806483e4a048df2d81e54d9db5b9be0edb2359909ea4d267dd3f9800aac850e107a
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,104 +1,117 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
-
|
12
|
-
-
|
13
|
-
|
14
|
-
# 1.
|
15
|
-
|
16
|
-
- Fix issue
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
|
32
|
-
# 1.0.
|
33
|
-
|
34
|
-
- Thanks to [
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
-
|
40
|
-
|
41
|
-
# 1.0.
|
42
|
-
|
43
|
-
- Fix
|
44
|
-
|
45
|
-
# 1.0.
|
46
|
-
|
47
|
-
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
-
|
53
|
-
|
54
|
-
# 1.0.
|
55
|
-
|
56
|
-
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
- Add
|
79
|
-
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
- LinkThumbnailer
|
97
|
-
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
-
|
102
|
-
-
|
103
|
-
- LinkThumbnailer.
|
104
|
-
|
1
|
+
# 2.0.0
|
2
|
+
|
3
|
+
- Fully refactored LinkThumbnailer
|
4
|
+
- Introduced [Graders](https://github.com/gottfrois/link_thumbnailer/wiki/How-to-build-your-own-Grader%3F)
|
5
|
+
- Introduced [Scrapers](https://github.com/gottfrois/link_thumbnailer/wiki/Attributes-option-explained)
|
6
|
+
- Ability to score descriptions
|
7
|
+
- Ability to fetch multiple `og:image`
|
8
|
+
- Fixed memoized run-time options
|
9
|
+
- Fixed some website urls not working
|
10
|
+
- Refactor ugly code
|
11
|
+
- More specs
|
12
|
+
- Removed `PreviewsController` since it does not add much value. Simply create your own and use the `to_json` method.
|
13
|
+
|
14
|
+
# 1.1.2
|
15
|
+
|
16
|
+
- Fix issue with FastImage URLs [https://github.com/gottfrois/link_thumbnailer/pull/31](https://github.com/gottfrois/link_thumbnailer/pull/31)
|
17
|
+
|
18
|
+
# 1.1.1
|
19
|
+
|
20
|
+
- Fix route helper not working under rails 4.
|
21
|
+
|
22
|
+
# 1.1.0
|
23
|
+
|
24
|
+
- Replace RMagick by [FastImage](https://github.com/sdsykes/fastimage)
|
25
|
+
- Rename `rmagick_attributes` config into `image_attributes`
|
26
|
+
|
27
|
+
# 1.0.9
|
28
|
+
|
29
|
+
- Fix issue when Location header used a relative path instead of an absolute path
|
30
|
+
- Update gemfile to be more flexible when using Hashie gem
|
31
|
+
|
32
|
+
# 1.0.8
|
33
|
+
|
34
|
+
- Thanks to [juriglx](https://github.com/juriglx), support for canonical urls
|
35
|
+
- Bug fixes
|
36
|
+
|
37
|
+
# 1.0.7
|
38
|
+
|
39
|
+
- Fix: Issue with preview controller
|
40
|
+
|
41
|
+
# 1.0.6
|
42
|
+
|
43
|
+
- Fix: Issue when setting `strict` option. Always returning OG representation.
|
44
|
+
|
45
|
+
# 1.0.5
|
46
|
+
|
47
|
+
- Thanks to [phlegx](https://github.com/phlegx), support for timeout http connection through configurations.
|
48
|
+
|
49
|
+
# 1.0.4
|
50
|
+
|
51
|
+
- Fix issue #7: nil img was returned when exception is raised. Now skiping nil images in results.
|
52
|
+
- Thanks to [phlegx](https://github.com/phlegx), support for SSL and User Agent customization through configurations.
|
53
|
+
|
54
|
+
# 1.0.3
|
55
|
+
|
56
|
+
- Fix issue #5: Url was incorect in case of HTTP Redirections.
|
57
|
+
|
58
|
+
# 1.0.2
|
59
|
+
|
60
|
+
- Feature: User can now set options at runtime by passing valid options to ```generate``` method
|
61
|
+
- Bug fix when doing ```rails g link_thumbnailer:install``` by explicitly specifying the scope of Rails
|
62
|
+
|
63
|
+
# 1.0.1
|
64
|
+
|
65
|
+
- Refactor LinkThumbnailer#generate method to have a cleaner code
|
66
|
+
|
67
|
+
# 1.0.0
|
68
|
+
|
69
|
+
- Update readme
|
70
|
+
- Add PreviewController for easy integration with user's app
|
71
|
+
- Add link_thumbnailer routes for easy integration with user's app
|
72
|
+
- Refactor some code
|
73
|
+
- Change 'to_a' method to 'to_hash' in object model
|
74
|
+
|
75
|
+
# 0.0.6
|
76
|
+
|
77
|
+
- Update readme
|
78
|
+
- Add `to_a` to WebImage class
|
79
|
+
- Refactor `to_json` for WebImage class
|
80
|
+
- Add specs corresponding
|
81
|
+
|
82
|
+
# 0.0.5
|
83
|
+
|
84
|
+
- Bug fix
|
85
|
+
- Remove `require 'rails'` from spec_helper.rb
|
86
|
+
- Remove rails dependences (blank? method) in code
|
87
|
+
- Spec fix
|
88
|
+
|
89
|
+
# 0.0.4
|
90
|
+
|
91
|
+
- Add specs for almost all classes
|
92
|
+
- Add a method `to_json` for WebImage class to be able to get a usable array of images' attributes
|
93
|
+
|
94
|
+
# 0.0.3
|
95
|
+
|
96
|
+
- Add specs for LinkThumbnailer class
|
97
|
+
- Refactor config system, now using dedicated configuration class
|
98
|
+
|
99
|
+
# 0.0.2
|
100
|
+
|
101
|
+
- Added Rspec
|
102
|
+
- Bug fixes:
|
103
|
+
- Now checking if attribute is blank for LinkThumbnailer::Object.valid? method
|
104
|
+
|
105
|
+
# 0.0.1
|
106
|
+
|
107
|
+
- LinkThumbnailer::Object
|
108
|
+
- LinkThumbnailer::Doc
|
109
|
+
- LinkThumbnailer::DocParser
|
110
|
+
- LinkThumbnailer::Fetcher
|
111
|
+
- LinkThumbnailer::ImgComparator
|
112
|
+
- LinkThumbnailer::ImgParser
|
113
|
+
- LinkThumbnailer::ImgUrlFilter
|
114
|
+
- LinkThumbnailer::Opengraph
|
115
|
+
- LinkThumbnailer::WebImage
|
116
|
+
- LinkThumbnailer.configure
|
117
|
+
- LinkThumbnailer.generate
|
data/Gemfile
CHANGED
data/{LICENSE → LICENSE.txt}
RENAMED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2012 Pierre-Louis Gottfrois
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
1
|
+
Copyright (c) 2012 Pierre-Louis Gottfrois
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,184 +1,153 @@
|
|
1
|
-
# LinkThumbnailer
|
2
|
-
|
3
|
-
[![Code Climate](https://codeclimate.com/github/gottfrois/link_thumbnailer.png)](https://codeclimate.com/github/gottfrois/link_thumbnailer)
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/gottfrois/link_thumbnailer/badge.png?branch=master)](https://coveralls.io/r/gottfrois/link_thumbnailer?branch=master)
|
5
|
-
[![Build Status](https://travis-ci.org/gottfrois/link_thumbnailer.png?branch=master)](https://travis-ci.org/gottfrois/link_thumbnailer)
|
6
|
-
|
7
|
-
Ruby gem generating image thumbnails from a given URL. Rank them and give you back an object containing images and website informations. Works like Facebook link previewer.
|
8
|
-
|
9
|
-
Demo Application is [here](http://link-thumbnailer-demo.herokuapp.com/) !
|
10
|
-
|
11
|
-
##
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
This
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
#
|
120
|
-
|
121
|
-
#
|
122
|
-
|
123
|
-
#
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
# config.
|
128
|
-
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
Implemented:
|
156
|
-
|
157
|
-
- Implements [OpenGraph](http://ogp.me/) protocol.
|
158
|
-
- Find images and sort them according to how well they represent what the page is about (includes absolute images).
|
159
|
-
- Sort images based on their size and color.
|
160
|
-
- Blacklist some well known advertisings image urls.
|
161
|
-
- Routes and Controllers to handle preview generation
|
162
|
-
|
163
|
-
Coming soon:
|
164
|
-
|
165
|
-
- Use the gem [ruby-readability](https://github.com/iterationlabs/ruby-readability) to parse images and website information
|
166
|
-
- Cache results on filesystem
|
167
|
-
|
168
|
-
## Contributing
|
169
|
-
|
170
|
-
1. Fork it
|
171
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
172
|
-
3. Run the specs (`bundle exec rspec spec`)
|
173
|
-
4. Commit your changes (`git commit -am 'Added some feature'`)
|
174
|
-
5. Push to the branch (`git push origin my-new-feature`)
|
175
|
-
6. Create new Pull Request
|
176
|
-
|
177
|
-
## Contributors
|
178
|
-
|
179
|
-
- [phlegx](https://github.com/phlegx)
|
180
|
-
- [juriglx](https://github.com/juriglx)
|
181
|
-
|
182
|
-
|
183
|
-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/gottfrois/link_thumbnailer/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
184
|
-
|
1
|
+
# LinkThumbnailer
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/gottfrois/link_thumbnailer.png)](https://codeclimate.com/github/gottfrois/link_thumbnailer)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/gottfrois/link_thumbnailer/badge.png?branch=master)](https://coveralls.io/r/gottfrois/link_thumbnailer?branch=master)
|
5
|
+
[![Build Status](https://travis-ci.org/gottfrois/link_thumbnailer.png?branch=master)](https://travis-ci.org/gottfrois/link_thumbnailer)
|
6
|
+
|
7
|
+
Ruby gem generating image thumbnails from a given URL. Rank them and give you back an object containing images and website informations. Works like Facebook link previewer.
|
8
|
+
|
9
|
+
Demo Application is [here](http://link-thumbnailer-demo.herokuapp.com/) !
|
10
|
+
|
11
|
+
## Features
|
12
|
+
|
13
|
+
- Dead simple.
|
14
|
+
- Support [OpenGraph](http://ogp.me/) protocol.
|
15
|
+
- Find and sort images that best represent what the page is about.
|
16
|
+
- Find and rate description that best represent what the page is about.
|
17
|
+
- Allow for custom class to sort the website descriptions yourself.
|
18
|
+
- Support image urls blacklisting (advertisements).
|
19
|
+
- Works with and without Rails.
|
20
|
+
- Fully customizable.
|
21
|
+
- Fully tested.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'link_thumbnailer'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install link_thumbnailer
|
36
|
+
|
37
|
+
Run:
|
38
|
+
|
39
|
+
$ rails g link_thumbnailer:install
|
40
|
+
|
41
|
+
This will add `link_thumbnailer.rb` to `config/initializers/`.
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Run `irb` and require the gem:
|
46
|
+
|
47
|
+
require 'link_thumbnailer'
|
48
|
+
|
49
|
+
The gem handle regular website but also website that use the [Opengraph](http://ogp.me/) protocol.
|
50
|
+
|
51
|
+
object = LinkThumbnailer.generate('http://stackoverflow.com')
|
52
|
+
=> #<LinkThumbnailer::Models::Website:...>
|
53
|
+
|
54
|
+
object.title
|
55
|
+
=> "Stack Overflow"
|
56
|
+
|
57
|
+
object.description
|
58
|
+
=> "Q&A for professional and enthusiast programmers"
|
59
|
+
|
60
|
+
object.images.first.src.to_s
|
61
|
+
=> "http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6"
|
62
|
+
|
63
|
+
LinkThumbnailer `generate` method return an instance of `LinkThumbnailer::Models::Website` that respond to `to_json` and `as_json` as you would expect:
|
64
|
+
|
65
|
+
object.to_json
|
66
|
+
=> "{\"url\":\"http://stackoverflow.com\",\"title\":\"Stack Overflow\",\"description\":\"Q&A for professional and enthusiast programmers\",\"images\":[{\"src\":\"http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6\",\"size\":[316,316],\"type\":\"png\"}]}"
|
67
|
+
|
68
|
+
|
69
|
+
## Configuration
|
70
|
+
|
71
|
+
LinkThumnailer comes with default configuration values. You can change default value by overriding them in a rails initializer:
|
72
|
+
|
73
|
+
In `config/initializers/link_thumbnailer.rb`
|
74
|
+
|
75
|
+
LinkThumbnailer.configure do |config|
|
76
|
+
# Numbers of redirects before raising an exception when trying to parse given url.
|
77
|
+
#
|
78
|
+
# config.redirect_limit = 3
|
79
|
+
|
80
|
+
# Set user agent
|
81
|
+
#
|
82
|
+
# config.user_agent = 'link_thumbnailer'
|
83
|
+
|
84
|
+
# Enable or disable SSL verification
|
85
|
+
#
|
86
|
+
# config.verify_ssl = true
|
87
|
+
|
88
|
+
# The amount of time in seconds to wait for a connection to be opened.
|
89
|
+
# If the HTTP object cannot open a connection in this many seconds,
|
90
|
+
# it raises a Net::OpenTimeout exception.
|
91
|
+
#
|
92
|
+
# See http://www.ruby-doc.org/stdlib-2.1.1/libdoc/net/http/rdoc/Net/HTTP.html#open_timeout
|
93
|
+
#
|
94
|
+
# config.http_timeout = 5
|
95
|
+
|
96
|
+
# List of blacklisted urls you want to skip when searching for images.
|
97
|
+
#
|
98
|
+
# config.blacklist_urls = [
|
99
|
+
# %r{^http://ad\.doubleclick\.net/},
|
100
|
+
# %r{^http://b\.scorecardresearch\.com/},
|
101
|
+
# %r{^http://pixel\.quantserve\.com/},
|
102
|
+
# %r{^http://s7\.addthis\.com/}
|
103
|
+
# ]
|
104
|
+
|
105
|
+
# List of attributes you want LinkThumbnailer to fetch on a website.
|
106
|
+
#
|
107
|
+
# config.attributes = [:title, :images, :description]
|
108
|
+
|
109
|
+
# List of procedures used to rate the website description. Add you custom class
|
110
|
+
# here. Note that the order matter to compute the score. See wiki for more details
|
111
|
+
# on how to build your own graders.
|
112
|
+
#
|
113
|
+
# config.graders = [
|
114
|
+
# ->(description) { ::LinkThumbnailer::Graders::Length.new(description) },
|
115
|
+
# ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :class) },
|
116
|
+
# ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :id) },
|
117
|
+
# ->(description) { ::LinkThumbnailer::Graders::Position.new(description) },
|
118
|
+
# ->(description) { ::LinkThumbnailer::Graders::LinkDensity.new(description) }
|
119
|
+
# ]
|
120
|
+
|
121
|
+
# Minimum description length for a website.
|
122
|
+
#
|
123
|
+
# config.description_min_length = 25
|
124
|
+
|
125
|
+
# Regex of words considered positive to rate website description.
|
126
|
+
#
|
127
|
+
# config.positive_regex = /article|body|content|entry|hentry|main|page|pagination|post|text|blog|story/i
|
128
|
+
|
129
|
+
# Regex of words considered negative to rate website description.
|
130
|
+
#
|
131
|
+
# config.negative_regex = /combx|comment|com-|contact|foot|footer|footnote|masthead|media|meta|outbrain|promo|related|scroll|shoutbox|sidebar|sponsor|shopping|tags|tool|widget|modal/i
|
132
|
+
|
133
|
+
# Numbers of images to fetch. Fetching too many images will be slow.
|
134
|
+
#
|
135
|
+
# config.image_limit = 5
|
136
|
+
end
|
137
|
+
|
138
|
+
Or at runtime:
|
139
|
+
|
140
|
+
object = LinkThumbnailer.generate('http://stackoverflow.com', redirect_limit: 5, user_agent: 'foo')
|
141
|
+
|
142
|
+
Note that runtime options will override default global configuration.
|
143
|
+
|
144
|
+
See [Configuration Options Explained](https://github.com/gottfrois/link_thumbnailer/wiki/Configuration-options-explained) for more details on each configuration options.
|
145
|
+
|
146
|
+
## Contributing
|
147
|
+
|
148
|
+
1. Fork it
|
149
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
150
|
+
3. Run the specs (`bundle exec rspec spec`)
|
151
|
+
4. Commit your changes (`git commit -am 'Added some feature'`)
|
152
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
153
|
+
6. Create new Pull Request
|