jekyll-picture-tag-ng 0.4.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cd5f67823462661b93520b765668c3da82794480e4e58a7fb6657b41920c893
4
- data.tar.gz: f76fc204106a3dc79fa40dbbb371ac988dcf6f2043a3089d2ab79b24cc6d94c7
3
+ metadata.gz: 8c023d8fa0eeb80434e5a7b0765ef2f5ae23d4b9cb042dfd11fc378113bb4796
4
+ data.tar.gz: d533e604e583d1003db2f5a6837d5fe5dc0906812e426221239332577b141b13
5
5
  SHA512:
6
- metadata.gz: 5ea82a06e9626494f78b35a962733ff979f4c9b9c956e56a120290cc9c24930c10b7db29d409c0ec73741100341e5fce63be1d92b86fa54907847975dc4b0f0a
7
- data.tar.gz: d967db3c36973c4eb29cca8c45a39b16c8cb9ece0003663c3ac2c11dd24435421d3b87248c15eca243a6cd333b820c7c591ec077e1c3de365efed46e2dd427f5
6
+ metadata.gz: 794f56c96b166b376951c77b27a22dd9d285f03626dbcd3127a58f60b601a316c48d60f42bba1e6733e4517f82c1826fc40e611d467ccdbfd3261b35ec0571b2
7
+ data.tar.gz: 6b854e35c9ca6d7acba69b938f3c14d7622e7c3b39b1743541031a641f2b3ba9aaab7f52752d93f1bf86fc85d1ef47b6d85badeb9e72d1eb1bed9ae3ac3ce4ac
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) :
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module PictureTag
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.1"
6
6
  end
7
7
  end
@@ -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,77 @@ 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.nil?
59
+ []
60
+ elsif input.is_a?(Array)
61
+ input.clone
62
+ elsif input.is_a?(String)
63
+ input.split(" ")
64
+ else
65
+ raise(
66
+ TypeError,
67
+ "[jekyll-picture-tag-ng] `extra_convert_args` must be an array or a string (#{input})"
68
+ )
69
+ end
70
+ end
71
+
72
+ def convert_args
73
+ @convert_args ||= as_args(config["extra_convert_args"]).concat(
74
+ picture_versions[@version].is_a?(Hash) &&
75
+ picture_versions[@version]["extra_convert_args"] || []
76
+ )
77
+ end
78
+
79
+ def pre_convert_args
80
+ @pre_convert_args ||= as_args(config["pre_extra_convert_args"]).concat(
81
+ picture_versions[@version].is_a?(Hash) &&
82
+ picture_versions[@version]["pre_extra_convert_args"] || []
83
+ )
84
+ end
85
+
46
86
  def picture?
47
87
  extname =~ /(\.jpg|\.jpeg|\.webp)$/i
48
88
  end
49
89
 
50
90
  def destination(dest)
51
91
  output_dir = File.join("img", @version, @dir)
52
- output_basename = @site.in_dest_dir(@site.dest, File.join(output_dir, "#{basename}.#{@pictype}"))
92
+ output_basename = @site.in_dest_dir(
93
+ @site.dest,
94
+ File.join(output_dir, "#{basename}.#{@pictype}")
95
+ )
53
96
  FileUtils.mkdir_p(File.dirname(output_dir))
54
97
  @destination ||= {}
55
98
  @destination[dest] ||= output_basename
56
99
  end
57
100
 
58
101
  def popen_args(dest_path)
59
- args = ["convert", @path, "-resize", "#{@picture_dim}x>"]
102
+ args = ["convert", @path]
103
+ args.concat pre_convert_args
104
+ args.concat ["-resize", "#{@picture_dim}x>"] unless replace_args
60
105
  if @pictype == "jpg"
61
106
  args.concat ["-background", "##{@config["background_color"]}",
62
107
  "-flatten", "-alpha", "off"]
63
108
  end
109
+ args.concat convert_args
64
110
  args.push dest_path
65
111
  end
66
112
 
67
113
  def copy_file(dest_path)
68
- Jekyll.logger.debug "copy_file : #{path} -> #{dest_path}"
114
+ Jekyll.logger.debug "copy_file : #{path} -> #{dest_path} (#{popen_args(dest_path)})"
69
115
  p = IO.popen(popen_args(dest_path))
70
116
  p.close
71
117
  File.utime(self.class.mtimes[path], self.class.mtimes[path], dest_path)
@@ -225,21 +271,17 @@ module Kramdown
225
271
  end
226
272
 
227
273
  def media_attribute(version)
228
- if version == default_pic_version
229
- ""
230
- else
231
- geometry = picture_versions[version]
232
- if geometry.is_a?(Hash)
233
- if geometry["media"].is_a?(String)
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
274
+ geometry = picture_versions[version]
275
+ if geometry.is_a?(Hash)
276
+ if geometry["media"].is_a?(String)
277
+ "media=\"#{geometry["media"]}\""
278
+ elsif geometry["media"].is_a?(Integer)
279
+ "media=\"(max-width: #{geometry["media"]}px)\""
240
280
  else
241
- "media=\"(max-width: #{geometry}px)\""
281
+ "media=\"(max-width: #{geometry["out_size"]}px)\""
242
282
  end
283
+ else
284
+ "media=\"(max-width: #{geometry}px)\""
243
285
  end
244
286
  end
245
287
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-picture-tag-ng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pcouy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-28 00:00:00.000000000 Z
11
+ date: 2023-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll