jekyll-cloudinary 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/cloudinary/version.rb +1 -1
- data/lib/jekyll/cloudinary.rb +144 -36
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b39a1223962dd9160274863110e7e2ee8ea81612
|
4
|
+
data.tar.gz: 7018c136e38e0fb420e6a030966cc716d326ad71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ff002140b00a547835571eb2b23e092082c697b569fb739ab04b6031e45f5659f1bba7a682833f11c94313f8807f1515edb59a736877aa2149607d0794a5cd7
|
7
|
+
data.tar.gz: 6affb3055b891807a74ea205c37b7a9d07e87630ad2d5fbe38064800c0a3b3fd295f1b1fe6f41580555e0ee72ae32bf2d0fb460a2618f3b0e13fefae8bf9c246
|
data/lib/jekyll/cloudinary.rb
CHANGED
@@ -3,6 +3,7 @@ module Jekyll
|
|
3
3
|
|
4
4
|
class CloudinaryTag < Liquid::Tag
|
5
5
|
require "RMagick"
|
6
|
+
require "open-uri"
|
6
7
|
|
7
8
|
def initialize(tag_name, markup, tokens)
|
8
9
|
@markup = markup
|
@@ -19,7 +20,66 @@ module Jekyll
|
|
19
20
|
"sizes" => "100vw",
|
20
21
|
"figure" => "auto",
|
21
22
|
"attributes" => {},
|
22
|
-
"verbose" => false
|
23
|
+
"verbose" => false,
|
24
|
+
"width_height" => true,
|
25
|
+
# Cloudinary transformations
|
26
|
+
"height" => false,
|
27
|
+
"crop" => "limit",
|
28
|
+
"aspect_ratio" => false,
|
29
|
+
"gravity" => false,
|
30
|
+
"zoom" => false,
|
31
|
+
"x" => false,
|
32
|
+
"y" => false,
|
33
|
+
"format" => false,
|
34
|
+
"fetch_format" => "auto",
|
35
|
+
"quality" => "auto",
|
36
|
+
"radius" => false,
|
37
|
+
"angle" => false,
|
38
|
+
"effect" => false,
|
39
|
+
"opacity" => false,
|
40
|
+
"border" => false,
|
41
|
+
"background" => false,
|
42
|
+
"overlay" => false,
|
43
|
+
"underlay" => false,
|
44
|
+
"default_image" => false,
|
45
|
+
"delay" => false,
|
46
|
+
"color" => false,
|
47
|
+
"color_space" => false,
|
48
|
+
"dpr" => false,
|
49
|
+
"page" => false,
|
50
|
+
"density" => false,
|
51
|
+
"flags" => false,
|
52
|
+
"transformation" => false
|
53
|
+
}
|
54
|
+
|
55
|
+
# TODO: Add validation for this parameters
|
56
|
+
transformation_options = {
|
57
|
+
"height" => "h",
|
58
|
+
"crop" => "c", # can include add-on: imagga_scale
|
59
|
+
"aspect_ratio" => "ar",
|
60
|
+
"gravity" => "g",
|
61
|
+
"zoom" => "z",
|
62
|
+
"x" => "x",
|
63
|
+
"y" => "y",
|
64
|
+
"fetch_format" => "f",
|
65
|
+
"quality" => "q", # can include add-on: jpegmini
|
66
|
+
"radius" => "r",
|
67
|
+
"angle" => "a",
|
68
|
+
"effect" => "e", # can include add-on: viesus_correct
|
69
|
+
"opacity" => "o",
|
70
|
+
"border" => "bo",
|
71
|
+
"background" => "b",
|
72
|
+
"overlay" => "l",
|
73
|
+
"underlay" => "u",
|
74
|
+
"default_image" => "d",
|
75
|
+
"delay" => "dl",
|
76
|
+
"color" => "co",
|
77
|
+
"color_space" => "cs",
|
78
|
+
"dpr" => "dpr",
|
79
|
+
"page" => "pg",
|
80
|
+
"density" => "dn",
|
81
|
+
"flags" => "fl",
|
82
|
+
"transformation" => "t"
|
23
83
|
}
|
24
84
|
|
25
85
|
# Settings
|
@@ -56,24 +116,40 @@ module Jekyll
|
|
56
116
|
end
|
57
117
|
|
58
118
|
image_src = markup[:image_src]
|
59
|
-
|
119
|
+
|
120
|
+
# Dynamic image type
|
121
|
+
type = "fetch"
|
122
|
+
# TODO: URL2PNG requires signed URLs… need to investigate more
|
123
|
+
# if /^url2png\:/.match(image_src)
|
124
|
+
# type = "url2png"
|
125
|
+
# image_src.gsub! "url2png:", ""
|
126
|
+
# end
|
127
|
+
|
60
128
|
# Build source image URL
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
129
|
+
is_image_remote = /^https?/.match(image_src)
|
130
|
+
# It’s remote
|
131
|
+
if is_image_remote
|
132
|
+
image_path = image_src
|
133
|
+
image_url = image_src
|
134
|
+
# It’s local
|
65
135
|
else
|
66
|
-
|
67
|
-
|
68
|
-
File.
|
69
|
-
image_src
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
136
|
+
is_image_path_absolute = %r!^/.*$!.match(image_src)
|
137
|
+
if is_image_path_absolute
|
138
|
+
image_path = File.join(site.config["destination"], image_src)
|
139
|
+
image_url = File.join(url, baseurl, image_src)
|
140
|
+
else
|
141
|
+
image_path = File.join(
|
142
|
+
site.config["destination"],
|
143
|
+
File.dirname(context["page"]["url"]),
|
144
|
+
image_src
|
145
|
+
)
|
146
|
+
image_url = File.join(
|
147
|
+
url,
|
148
|
+
baseurl,
|
149
|
+
File.dirname(context["page"]["url"]),
|
150
|
+
image_src
|
151
|
+
)
|
152
|
+
end
|
77
153
|
end
|
78
154
|
|
79
155
|
if markup[:preset]
|
@@ -129,22 +205,54 @@ module Jekyll
|
|
129
205
|
|
130
206
|
attr_string = html_attr.map { |a, v| "#{a}=\"#{v}\"" }.join(" ")
|
131
207
|
|
208
|
+
# Figure out the Cloudinary transformations
|
209
|
+
transformations = []
|
210
|
+
transformations_string = ""
|
211
|
+
transformation_options.each do | key, shortcode |
|
212
|
+
if preset[key]
|
213
|
+
transformations << "#{shortcode}_#{preset[key]}"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
if transformations.length > 0
|
217
|
+
transformations_string = transformations.compact.reject(&:empty?).join(',') + ","
|
218
|
+
end
|
219
|
+
|
132
220
|
# Get source image natural width
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
221
|
+
image = false
|
222
|
+
fallback_url = "https://res.cloudinary.com/#{settings["cloud_name"]}/image/#{type}/#{transformations_string}w_#{preset["fallback_max_width"]}/#{image_url}"
|
223
|
+
natural_width = 100_000
|
224
|
+
width_height = ""
|
225
|
+
# Standard fetch
|
226
|
+
if type == "fetch"
|
227
|
+
# Trap format support issues from ImageMagick
|
228
|
+
begin
|
229
|
+
if is_image_remote
|
230
|
+
image = Magick::ImageList.new
|
231
|
+
urlimage = open(image_url) # Image Remote URL
|
232
|
+
image.from_blob(urlimage.read)
|
233
|
+
elsif File.exist?(image_path)
|
234
|
+
image = Magick::Image::read(image_path).first
|
235
|
+
end
|
236
|
+
rescue
|
237
|
+
image = false
|
238
|
+
end
|
239
|
+
if image
|
240
|
+
natural_width = image.columns
|
241
|
+
natural_height = image.rows
|
242
|
+
width_height = "width=\"#{natural_width}\" height=\"#{natural_height}\""
|
243
|
+
else
|
244
|
+
fallback_url = image_url
|
245
|
+
Jekyll.logger.warn(
|
246
|
+
"[Cloudinary]",
|
247
|
+
"Couldn't find this image to check its width: #{image_path}. \
|
248
|
+
Try to run Jekyll build a second time. If it still doesn’t work \
|
249
|
+
it could be that your ImageMagick install doesn’t support this format."
|
250
|
+
)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
if preset["width_height"] == false
|
141
255
|
width_height = ""
|
142
|
-
Jekyll.logger.warn(
|
143
|
-
"[Cloudinary]",
|
144
|
-
"Couldn't find this image to check its width: #{image_path}. \
|
145
|
-
Try to run Jekyll build a second time."
|
146
|
-
)
|
147
|
-
fallback_url = image_url
|
148
256
|
end
|
149
257
|
|
150
258
|
srcset = []
|
@@ -159,27 +267,27 @@ module Jekyll
|
|
159
267
|
Jekyll.logger.warn(
|
160
268
|
"[Cloudinary]",
|
161
269
|
"Width of source image '#{File.basename(image_src)}' (#{natural_width}px) \
|
162
|
-
in #{context["page"]
|
270
|
+
in #{context["page"]["path"]} not enough for ANY srcset version"
|
163
271
|
)
|
164
272
|
end
|
165
|
-
srcset << "https://res.cloudinary.com/#{settings["cloud_name"]}/image
|
273
|
+
srcset << "https://res.cloudinary.com/#{settings["cloud_name"]}/image/#{type}/#{transformations_string}w_#{natural_width}/#{image_url} #{natural_width}w"
|
166
274
|
else
|
167
275
|
missed_sizes = []
|
168
276
|
(1..steps).each do |factor|
|
169
277
|
width = min_width + (factor - 1) * step_width
|
170
278
|
if width <= natural_width
|
171
|
-
srcset << "https://res.cloudinary.com/#{settings["cloud_name"]}/image
|
279
|
+
srcset << "https://res.cloudinary.com/#{settings["cloud_name"]}/image/#{type}/#{transformations_string}w_#{width}/#{image_url} #{width}w"
|
172
280
|
else
|
173
281
|
missed_sizes.push(width)
|
174
282
|
end
|
175
283
|
end
|
176
284
|
unless missed_sizes.empty?
|
177
|
-
srcset << "https://res.cloudinary.com/#{settings["cloud_name"]}/image
|
285
|
+
srcset << "https://res.cloudinary.com/#{settings["cloud_name"]}/image/#{type}/#{transformations_string}w_#{natural_width}/#{image_url} #{natural_width}w"
|
178
286
|
if settings["verbose"]
|
179
287
|
Jekyll.logger.warn(
|
180
288
|
"[Cloudinary]",
|
181
289
|
"Width of source image '#{File.basename(image_src)}' (#{natural_width}px) \
|
182
|
-
in #{context["page"]
|
290
|
+
in #{context["page"]["path"]} not enough for #{missed_sizes.join("px, ")}px \
|
183
291
|
version#{missed_sizes.length > 1 ? "s" : ""}"
|
184
292
|
)
|
185
293
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-cloudinary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Hoizey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.6.
|
129
|
+
rubygems_version: 2.6.11
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: Liquid tag for Jekyll with Cloudinary
|