jekyll-picture-tag-ng 0.4.0 → 0.5.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 +4 -4
- data/README.md +19 -0
- data/lib/jekyll-picture-tag-ng/version.rb +1 -1
- data/lib/jekyll-picture-tag-ng.rb +57 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b13b667958ab46916ceda313a2dec27a6d824e9e567fc68faa369734cd56272
|
4
|
+
data.tar.gz: 390e2ab18a416bf1e3e3523d18d6fe5b94a1a2a5bbf7b05a2a6cec8fcbddb8b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39af2751eab33d119cb9f494e99bf387a542dd397bbc098ab346075100608263040412036f85618a8d5eca60a98fa6c584a3cd2acfb271d9b9e1e4a27f277790
|
7
|
+
data.tar.gz: ac269bf8ed4c504e7139b2b16eb6078ba3f3105c67a95a6d55371cda449f8a51f9c5bf7a9d061d69895bf66087bd6b81fbc5a7bdab7ee81008e658ab7ebe1eed
|
data/README.md
CHANGED
@@ -159,6 +159,25 @@ to the following HTML :
|
|
159
159
|
</picture>
|
160
160
|
```
|
161
161
|
|
162
|
+
#### Extra `convert` arguments
|
163
|
+
|
164
|
+
The `extra_convert_args` and `pre_extra_convert_args` options allow you to add any [`convert` argument](https://imagemagick.org/script/convert.php) to the image conversion processes. The `pre_extra_convert_args` will be added before the resize operation, and the `extra_convert_args` after the resize operation. These options must be either arrays of strings or a string that will be split on spaces. This can be used to add a watermark to all your pictures (see example below).
|
165
|
+
|
166
|
+
Additionally, you can set different values based on the version for both these options. In the example below, the `m` version of output pictures will be blurred :
|
167
|
+
|
168
|
+
```yaml
|
169
|
+
picture_tag_ng:
|
170
|
+
pre_extra_convert_args: ["-font", "DejaVu-Sans-Book", "-pointsize", "72",
|
171
|
+
"-fill", "black", "-annotate", "+25+75", "Watermark"] # Add watermark to all output pics
|
172
|
+
picture_versions:
|
173
|
+
m:
|
174
|
+
out_size: 700
|
175
|
+
extra_convert_args: ["-scale", "20%", "-blur", "0x2.5", "-resize", "500%"] # Blur `m` pics
|
176
|
+
s: 400
|
177
|
+
```
|
178
|
+
|
179
|
+
You can disable the default resize operation by setting `replace_convert_args: true` either at the plugin level or at the version level. If the, the version-specific value will override the plugin-global value.
|
180
|
+
|
162
181
|
## Development
|
163
182
|
|
164
183
|
After cloning the repo, you can run the following commands in a local Jekyll website's folder to start hacking on the code of `jekyll-picture-tag-ng` (you'll need to replace the path in the second command) :
|
@@ -16,7 +16,9 @@ module Jekyll
|
|
16
16
|
"s" => "400",
|
17
17
|
"m" => "700"
|
18
18
|
},
|
19
|
-
"background_color" => "FFFFFF"
|
19
|
+
"background_color" => "FFFFFF",
|
20
|
+
"extra_convert_args" => [],
|
21
|
+
"replace_convert_args" => false
|
20
22
|
}.freeze
|
21
23
|
|
22
24
|
class Error < StandardError; end
|
@@ -39,33 +41,75 @@ module Jekyll
|
|
39
41
|
@config ||= CONFIG.merge(@site.config["picture_tag_ng"] || {})
|
40
42
|
end
|
41
43
|
|
44
|
+
def replace_args
|
45
|
+
result = config["replace_convert_args"]
|
46
|
+
if picture_versions[@version].is_a?(Hash) &&
|
47
|
+
!picture_versions[@version]["replace_convert_args"].nil?
|
48
|
+
result = picture_versions[@version]["replace_convert_args"]
|
49
|
+
end
|
50
|
+
result
|
51
|
+
end
|
52
|
+
|
42
53
|
def picture_versions
|
43
54
|
config["picture_versions"]
|
44
55
|
end
|
45
56
|
|
57
|
+
def as_args(input)
|
58
|
+
if input.is_a?(Array)
|
59
|
+
input.clone
|
60
|
+
elsif input.is_a?(String)
|
61
|
+
input.split(" ")
|
62
|
+
else
|
63
|
+
raise(
|
64
|
+
TypeError,
|
65
|
+
"[jekyll-picture-tag-ng] `extra_convert_args` must be an array or a string"
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def convert_args
|
71
|
+
@convert_args ||= as_args(config["extra_convert_args"]).concat(
|
72
|
+
picture_versions[@version].is_a?(Hash) &&
|
73
|
+
picture_versions[@version]["extra_convert_args"] || []
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def pre_convert_args
|
78
|
+
@pre_convert_args ||= as_args(config["pre_extra_convert_args"]).concat(
|
79
|
+
picture_versions[@version].is_a?(Hash) &&
|
80
|
+
picture_versions[@version]["pre_extra_convert_args"] || []
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
46
84
|
def picture?
|
47
85
|
extname =~ /(\.jpg|\.jpeg|\.webp)$/i
|
48
86
|
end
|
49
87
|
|
50
88
|
def destination(dest)
|
51
89
|
output_dir = File.join("img", @version, @dir)
|
52
|
-
output_basename = @site.in_dest_dir(
|
90
|
+
output_basename = @site.in_dest_dir(
|
91
|
+
@site.dest,
|
92
|
+
File.join(output_dir, "#{basename}.#{@pictype}")
|
93
|
+
)
|
53
94
|
FileUtils.mkdir_p(File.dirname(output_dir))
|
54
95
|
@destination ||= {}
|
55
96
|
@destination[dest] ||= output_basename
|
56
97
|
end
|
57
98
|
|
58
99
|
def popen_args(dest_path)
|
59
|
-
args = ["convert", @path
|
100
|
+
args = ["convert", @path]
|
101
|
+
args.concat pre_convert_args
|
102
|
+
args.concat ["-resize", "#{@picture_dim}x>"] unless replace_args
|
60
103
|
if @pictype == "jpg"
|
61
104
|
args.concat ["-background", "##{@config["background_color"]}",
|
62
105
|
"-flatten", "-alpha", "off"]
|
63
106
|
end
|
107
|
+
args.concat convert_args
|
64
108
|
args.push dest_path
|
65
109
|
end
|
66
110
|
|
67
111
|
def copy_file(dest_path)
|
68
|
-
Jekyll.logger.debug "copy_file : #{path} -> #{dest_path}"
|
112
|
+
Jekyll.logger.debug "copy_file : #{path} -> #{dest_path} (#{popen_args(dest_path)})"
|
69
113
|
p = IO.popen(popen_args(dest_path))
|
70
114
|
p.close
|
71
115
|
File.utime(self.class.mtimes[path], self.class.mtimes[path], dest_path)
|
@@ -225,21 +269,17 @@ module Kramdown
|
|
225
269
|
end
|
226
270
|
|
227
271
|
def media_attribute(version)
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
"media=\"#{geometry["media"]}\""
|
235
|
-
elsif geometry["media"].is_a?(Integer)
|
236
|
-
"media=\"(max-width: #{geometry["media"]}px)\""
|
237
|
-
else
|
238
|
-
"media=\"(max-width: #{geometry["out_size"]}px)\""
|
239
|
-
end
|
272
|
+
geometry = picture_versions[version]
|
273
|
+
if geometry.is_a?(Hash)
|
274
|
+
if geometry["media"].is_a?(String)
|
275
|
+
"media=\"#{geometry["media"]}\""
|
276
|
+
elsif geometry["media"].is_a?(Integer)
|
277
|
+
"media=\"(max-width: #{geometry["media"]}px)\""
|
240
278
|
else
|
241
|
-
"media=\"(max-width: #{geometry}px)\""
|
279
|
+
"media=\"(max-width: #{geometry["out_size"]}px)\""
|
242
280
|
end
|
281
|
+
else
|
282
|
+
"media=\"(max-width: #{geometry}px)\""
|
243
283
|
end
|
244
284
|
end
|
245
285
|
|