jekyll-imgflow 0.3.0 → 0.3.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: d37c208e7250fe6da8291bfab933d5df7391347d0ce95492e32e1d94e54df7a8
4
- data.tar.gz: cd222c0e6dbdcffe168ec0919a12d53c57324a277cb9efeecb5173a98c4c5b04
3
+ metadata.gz: 2f902d95441ebd7a1c3a98200b140c2bf109343a79cf43700221a6cfec2902df
4
+ data.tar.gz: c89e222e5f37bb795f44ec7b6e3ecc865ca3fb66fefac0481ea31211f8fa7dfb
5
5
  SHA512:
6
- metadata.gz: 2f566b0e2d70993a209a5353cf1b91d54e3b3f3143397146f58bbbcf19428eab9797ed5def60efdd3d8f926f214fa2ec6670d47ccfd6c000fe2f9c35b2bac00c
7
- data.tar.gz: 0b601aea8c16d71133816f034b4277e399e6108569af169c0984416ef6e5d90edc30490d17af254f736f2897eae5c6b55d515888a4b71af35dd8020b63f37a88
6
+ metadata.gz: cfc171eb11a3f533033671d2b8d8bfdc90bd3a9790bc9b764cf1ada4e58817179261419c80af2cd0eb2bc8c6bc1c130d754f31a0415664bd4262c43f0c3adb49
7
+ data.tar.gz: 1f92eb5e21c373a01e570bcaa843a51ccfd093655c46a64a4ae21248c9d4862d8cd6acac84830e2f1d023a8de4a8b8b2662bfbfe44e83c0a6a633c6eb23cc6d1
@@ -60,7 +60,8 @@ module Jekyll
60
60
  # Combine image path with preset markup. Keep the path quoted because
61
61
  # filenames may contain spaces.
62
62
  image_markup = if image_path.include?(" ")
63
- "\"#{image_path.gsub('"', '\\"')}\""
63
+ escaped_path = image_path.gsub("\\") { "\\\\" }.gsub('"', '\\"')
64
+ "\"#{escaped_path}\""
64
65
  else
65
66
  image_path
66
67
  end
@@ -42,11 +42,11 @@ module JekyllImgFlow
42
42
  # @param picture_markup [String] Picture Tag markup like "{% picture hero image.jpg 16:9 --alt Text %}"
43
43
  # @return [Hash] Translation result with markup and attributes
44
44
  def translate_to_imgflow(picture_markup)
45
- # Extract content between {% picture ... %}
46
- match = picture_markup.match(/\{%\s*picture\s+(.+?)%\}/)
47
- return { markup: "", attributes: {} } unless match
45
+ # Extract content between {% picture ... %} without a backtracking regex
46
+ content = extract_picture_content(picture_markup)
47
+ return { markup: "", attributes: {} } unless content
48
48
 
49
- content = match[1].strip
49
+ content = content.strip
50
50
  return { markup: "", attributes: {} } if content.empty?
51
51
 
52
52
  # Parse arguments
@@ -75,6 +75,32 @@ module JekyllImgFlow
75
75
 
76
76
  private
77
77
 
78
+ def extract_picture_content(markup)
79
+ offset = 0
80
+ while (opening = markup.index("{%", offset))
81
+ cursor = skip_whitespace(markup, opening + 2)
82
+ if markup[cursor, 7] == "picture"
83
+ cursor += 7
84
+ if cursor < markup.length && whitespace?(markup[cursor])
85
+ cursor = skip_whitespace(markup, cursor)
86
+ closing = markup.index("%}", cursor)
87
+ return markup[cursor...closing] if closing
88
+ end
89
+ end
90
+ offset = opening + 2
91
+ end
92
+ nil
93
+ end
94
+
95
+ def skip_whitespace(markup, cursor)
96
+ cursor += 1 while cursor < markup.length && whitespace?(markup[cursor])
97
+ cursor
98
+ end
99
+
100
+ def whitespace?(character)
101
+ [" ", "\t", "\r", "\n"].include?(character)
102
+ end
103
+
78
104
  # Parse arguments handling quoted paths and attributes
79
105
  # @param content [String] Raw content
80
106
  # @return [Array] Parsed arguments
@@ -79,7 +79,7 @@ module JekyllImgFlow
79
79
 
80
80
  format_op = @operations.find { |op| op[:type] == :format }
81
81
  quality_op = @operations.find { |op| op[:type] == :quality }
82
- command_parts += ["-f", format_op[:format]] if format_op
82
+ command_parts += ["-f", sharp_format(format_op[:format])] if format_op
83
83
  command_parts += ["-q#{quality_op[:quality]}"] if quality_op
84
84
 
85
85
  if opacity && opacity < 1.0
@@ -142,7 +142,7 @@ module JekyllImgFlow
142
142
  quality_op = @operations.find { |op| op[:type] == :quality }
143
143
  alpha_op = @operations.find { |op| op[:type] == :alpha_opacity }
144
144
 
145
- command_parts += ["-f", format_op[:format]] if format_op
145
+ command_parts += ["-f", sharp_format(format_op[:format])] if format_op
146
146
  command_parts += ["-q#{quality_op[:quality]}"] if quality_op
147
147
  if alpha_op
148
148
  alpha_value = (alpha_op[:opacity] * 255).round
@@ -200,7 +200,7 @@ module JekyllImgFlow
200
200
  quality_op = @operations.find { |op| op[:type] == :quality }
201
201
  alpha_op = @operations.find { |op| op[:type] == :alpha_opacity }
202
202
 
203
- command_parts += ["-f", format_op[:format]] if format_op
203
+ command_parts += ["-f", sharp_format(format_op[:format])] if format_op
204
204
  command_parts += ["-q#{quality_op[:quality]}"] if quality_op
205
205
  if alpha_op
206
206
  alpha_value = (alpha_op[:opacity] * 255).round
@@ -209,6 +209,12 @@ module JekyllImgFlow
209
209
 
210
210
  command_parts.join(" ")
211
211
  end
212
+
213
+ # Sharp CLI calls JPEG "jpeg", while ImgFlow uses the standard "jpg"
214
+ # extension in generated filenames and public configuration.
215
+ def sharp_format(format)
216
+ format.to_s == "jpg" ? "jpeg" : format
217
+ end
212
218
  end
213
219
  end
214
220
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllImgFlow
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-imgflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svend Gundestrup