link_thumbnailer 2.0.4 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +7 -0
- data/README.md +8 -0
- data/lib/generators/templates/initializer.rb +6 -0
- data/lib/link_thumbnailer/configuration.rb +2 -1
- data/lib/link_thumbnailer/image_parsers/size.rb +7 -0
- data/lib/link_thumbnailer/image_parsers/type.rb +8 -1
- data/lib/link_thumbnailer/models/image.rb +3 -3
- data/lib/link_thumbnailer/scrapers/base.rb +2 -2
- data/lib/link_thumbnailer/scrapers/default/description.rb +2 -2
- data/lib/link_thumbnailer/scrapers/default/images.rb +2 -2
- data/lib/link_thumbnailer/scrapers/default/title.rb +2 -2
- data/lib/link_thumbnailer/scrapers/opengraph/base.rb +2 -2
- data/lib/link_thumbnailer/scrapers/opengraph/image.rb +41 -1
- data/lib/link_thumbnailer/version.rb +1 -1
- data/spec/configuration_spec.rb +1 -0
- data/spec/fixture_spec.rb +1 -0
- data/spec/fixtures/og_valid_example.html +2 -0
- data/spec/image_parsers/type_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmRlNGRiODRmOGM2ZGZmNmVjYzE4M2MwM2NlY2VhMzdmYTdiYzdjNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGMyMTFjZTg4Y2M1ODQxMmU3ZWU5NjcwMmEzYTU2MzM2MDkyZjllYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmM4YzhlMzcxZWYzZTU5OGE3ZjU2NDRlYmY3MzQwMDUxZDlhNWRlMTdjODYx
|
10
|
+
NzRjYTk1ZTQzMjJlZGUzYzY5YmM2NzlmMDdjMmViM2M3NGU4MTg3ZGJkMWUx
|
11
|
+
MDJkNmVlNWFmZGU0ZTYyMjQ4ZjVkZTYzYzFkNjhjOTc1ZTlhOGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmUwMTY3NmNjNjU3OTJlOTQyOTQ1YWViZTZlNWNkNDNhYWEyNzg5ZWE5MWE4
|
14
|
+
NDNmZDdlZjUyOWUwZTgyZjIxMGQxZGRiMTJjMzNjOGI1MTMwNjJiM2E4NmU1
|
15
|
+
NmY5NWNjNDU4MjgwYzVlMTdkYmVhOWZiMjk5NTg0NTQ3MjJiOTg=
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 2.1.0
|
2
|
+
|
3
|
+
- Increased `og:image` scraping performance by parsing `og:image:width` and `og:image:height` attribute if specified
|
4
|
+
- Introduced `image_stats` option to allow disabling image size and type parsing causing performance issues.
|
5
|
+
|
6
|
+
When disabled, size will be `[0, 0]` and type will be `nil`
|
7
|
+
|
1
8
|
# 2.0.4
|
2
9
|
|
3
10
|
- Fixes [#39](https://github.com/gottfrois/link_thumbnailer/issues/39)
|
data/README.md
CHANGED
@@ -10,6 +10,8 @@ Ruby gem generating image thumbnails from a given URL. Rank them and give you ba
|
|
10
10
|
|
11
11
|
Demo Application is [here](http://link-thumbnailer-demo.herokuapp.com/) !
|
12
12
|
|
13
|
+
**OpenSource** and **Free** API available [here](https://github.com/gottfrois/link_thumbnailer_api) !
|
14
|
+
|
13
15
|
## Features
|
14
16
|
|
15
17
|
- Dead simple.
|
@@ -135,6 +137,12 @@ In `config/initializers/link_thumbnailer.rb`
|
|
135
137
|
# Numbers of images to fetch. Fetching too many images will be slow.
|
136
138
|
#
|
137
139
|
# config.image_limit = 5
|
140
|
+
|
141
|
+
# Whether you want LinkThumbnailer to return image size and type or not.
|
142
|
+
# Setting this value to false will increase performance since for each images, LinkThumbnailer
|
143
|
+
# does not have to fetch its size and type.
|
144
|
+
#
|
145
|
+
# config.image_stats = true
|
138
146
|
end
|
139
147
|
|
140
148
|
Or at runtime:
|
@@ -60,4 +60,10 @@ LinkThumbnailer.configure do |config|
|
|
60
60
|
# Numbers of images to fetch. Fetching too many images will be slow.
|
61
61
|
#
|
62
62
|
# config.image_limit = 5
|
63
|
+
|
64
|
+
# Whether you want LinkThumbnailer to return image size and type or not.
|
65
|
+
# Setting this value to false will increase performance since for each images, LinkThumbnailer
|
66
|
+
# does not have to fetch its size and type.
|
67
|
+
#
|
68
|
+
# config.image_stats = true
|
63
69
|
end
|
@@ -25,7 +25,7 @@ module LinkThumbnailer
|
|
25
25
|
attr_accessor :redirect_limit, :blacklist_urls, :user_agent,
|
26
26
|
:verify_ssl, :http_timeout, :attributes, :graders,
|
27
27
|
:description_min_length, :positive_regex, :negative_regex,
|
28
|
-
:image_limit
|
28
|
+
:image_limit, :image_stats
|
29
29
|
|
30
30
|
# Create a new instance.
|
31
31
|
#
|
@@ -53,6 +53,7 @@ module LinkThumbnailer
|
|
53
53
|
@positive_regex = /article|body|content|entry|hentry|main|page|pagination|post|text|blog|story/i
|
54
54
|
@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
|
55
55
|
@image_limit = 5
|
56
|
+
@image_stats = true
|
56
57
|
end
|
57
58
|
|
58
59
|
end
|
@@ -5,11 +5,18 @@ module LinkThumbnailer
|
|
5
5
|
class Size
|
6
6
|
|
7
7
|
def self.perform(image)
|
8
|
+
return [0, 0] unless perform?
|
8
9
|
::FastImage.size(image.src.to_s, raise_on_failure: true)
|
9
10
|
rescue ::FastImage::FastImageException, ::Errno::ENAMETOOLONG
|
10
11
|
[0, 0]
|
11
12
|
end
|
12
13
|
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.perform?
|
17
|
+
::LinkThumbnailer.page.config.image_stats
|
18
|
+
end
|
19
|
+
|
13
20
|
end
|
14
21
|
end
|
15
22
|
end
|
@@ -5,9 +5,16 @@ module LinkThumbnailer
|
|
5
5
|
class Type
|
6
6
|
|
7
7
|
def self.perform(image)
|
8
|
+
return unless perform?
|
8
9
|
::FastImage.type(image.src.to_s, raise_on_failure: true)
|
9
10
|
rescue ::FastImage::FastImageException, ::Errno::ENAMETOOLONG
|
10
|
-
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.perform?
|
17
|
+
::LinkThumbnailer.page.config.image_stats
|
11
18
|
end
|
12
19
|
|
13
20
|
end
|
@@ -9,10 +9,10 @@ module LinkThumbnailer
|
|
9
9
|
|
10
10
|
attr_reader :src, :type, :size
|
11
11
|
|
12
|
-
def initialize(src)
|
12
|
+
def initialize(src, size = nil, type = nil)
|
13
13
|
@src = src
|
14
|
-
@size = parser.size(self)
|
15
|
-
@type = parser.type(self)
|
14
|
+
@size = size || parser.size(self)
|
15
|
+
@type = type || parser.type(self)
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_s
|
@@ -5,14 +5,14 @@ module LinkThumbnailer
|
|
5
5
|
module Default
|
6
6
|
class Description < ::LinkThumbnailer::Scrapers::Default::Base
|
7
7
|
|
8
|
-
private
|
9
|
-
|
10
8
|
def value
|
11
9
|
return model_from_meta.to_s if model_from_meta
|
12
10
|
return model_from_body.to_s if model_from_body
|
13
11
|
nil
|
14
12
|
end
|
15
13
|
|
14
|
+
private
|
15
|
+
|
16
16
|
def model_from_meta
|
17
17
|
modelize(node_from_meta, node_from_meta.attributes['content'].value) if node_from_meta
|
18
18
|
end
|
@@ -6,12 +6,12 @@ module LinkThumbnailer
|
|
6
6
|
module Default
|
7
7
|
class Images < ::LinkThumbnailer::Scrapers::Default::Base
|
8
8
|
|
9
|
-
private
|
10
|
-
|
11
9
|
def value
|
12
10
|
abs_urls.each_with_index.take_while { |_, i| i < config.image_limit }.map { |e| modelize(e.first) }
|
13
11
|
end
|
14
12
|
|
13
|
+
private
|
14
|
+
|
15
15
|
def urls
|
16
16
|
document.search('//img').map { |i| i['src'] }.compact
|
17
17
|
end
|
@@ -16,7 +16,7 @@ module LinkThumbnailer
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def modelize(node, text = nil)
|
19
|
-
model_class.new(text)
|
19
|
+
model_class.new(text, size)
|
20
20
|
end
|
21
21
|
|
22
22
|
def nodes
|
@@ -24,6 +24,46 @@ module LinkThumbnailer
|
|
24
24
|
nodes.empty? ? meta_xpaths(attribute: attribute, key: :name) : nodes
|
25
25
|
end
|
26
26
|
|
27
|
+
def size
|
28
|
+
[width.to_i, height.to_i] if width && height
|
29
|
+
end
|
30
|
+
|
31
|
+
def width
|
32
|
+
Width.new(document).value
|
33
|
+
end
|
34
|
+
|
35
|
+
def height
|
36
|
+
Height.new(document).value
|
37
|
+
end
|
38
|
+
|
39
|
+
class Width < ::LinkThumbnailer::Scrapers::Opengraph::Base
|
40
|
+
|
41
|
+
def value
|
42
|
+
node.attributes['content'].to_s if node
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def attribute
|
48
|
+
"og:image:width"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
class Height < ::LinkThumbnailer::Scrapers::Opengraph::Base
|
54
|
+
|
55
|
+
def value
|
56
|
+
node.attributes['content'].to_s if node
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def attribute
|
62
|
+
"og:image:height"
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
27
67
|
end
|
28
68
|
end
|
29
69
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -15,6 +15,7 @@ describe LinkThumbnailer::Configuration do
|
|
15
15
|
it { expect(instance.positive_regex).to_not be_nil }
|
16
16
|
it { expect(instance.negative_regex).to_not be_nil }
|
17
17
|
it { expect(instance.image_limit).to eq(5) }
|
18
|
+
it { expect(instance.image_stats).to eq(true) }
|
18
19
|
|
19
20
|
describe '.config' do
|
20
21
|
|
data/spec/fixture_spec.rb
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
<meta property="og:title" content="Title from og">
|
7
7
|
<meta property="og:description" content="Description from og">
|
8
8
|
<meta property="og:image" content="http://foo.com/foo.png">
|
9
|
+
<meta property="og:image:width" content="100">
|
10
|
+
<meta property="og:image:height" content="100">
|
9
11
|
<title>Title</title>
|
10
12
|
</head>
|
11
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link_thumbnailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre-Louis Gottfrois
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|