shi-jekyll-images 0.1.0.10 → 0.1.0.14

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: 7c77523027f7e9294ce8bc1fc00d49d0f6755c187b11ff1246c437733862c89c
4
- data.tar.gz: ff6c2ea236e24512af52445686fbabae4c97a29b88a312b35c09f4f7c76b4e72
3
+ metadata.gz: eac0cef4a9dcd2d9f3d8fdffdc0b5b9335f14a77eb9d0b56e87c19e814d398f7
4
+ data.tar.gz: 73afca035a829bcc8ad48b8911df13f842e5a4d2d8deb24be0f67b74ecc4ea97
5
5
  SHA512:
6
- metadata.gz: 7154cca878a8f39286d49ee5ae258792ce11dae99fdf89f8f17a23498226d0898147389a9bba4d9811fdeba54c2d8e4c9432be6fd4234b2a5faa919a6e2f67b5
7
- data.tar.gz: e99623acc24dfe627f10c4b199ed750d4668bc1c4ca5567bb293df2c3e54b8438c45be03a4a7c9a97478813d0f14791a7f4b469c944c27aadf878adc53a775fc
6
+ metadata.gz: e0e9e45b08f9f187e9b7aee1789cbf694f226d622c0aaec610ae96835f519b2a732340f2d617151fe2c6159faf9c049000d73c235ae9c695aedf3396c59ddf86
7
+ data.tar.gz: 24f498b6fd1ca1c903f8091d8b6b54d6c630e5dff54eae437d3118b140f3d325765e38620ea21a703c04646664e5e215d33bd48d3cf1d63a45cd4e79922fd522
@@ -13,7 +13,38 @@ module Shi::Jekyll::Images::File
13
13
  Shi::Jekyll::Images::WebPFile::create page, source, bounds, crop
14
14
  end
15
15
  end
16
+
17
+ # Восстанавливаем ранее сгенерированные файлы в site.static_files
18
+ def restore_generated_files(site)
19
+ target_root = site.config['shi_images']&.[]('target_root') || 'img'
20
+ generated_files_dir = File.join(site.dest, target_root)
21
+ return unless File.directory?(generated_files_dir)
22
+
23
+ Dir.glob(File.join(generated_files_dir, '**', '*.{webp,svg}')).each do |file_path|
24
+ relative_path = file_path.sub(/^#{site.dest}\//, '')
25
+ unless site.static_files.any? { |f| f.relative_path == relative_path }
26
+ # Создаём фиктивный StaticFile, чтобы Jekyll не удалял файл
27
+ source_file = site.static_files.find { |f| f.relative_path == File.basename(relative_path).sub(/\.webp$/, '') }
28
+ source_file ||= Jekyll::StaticFile.new(site, site.source, File.dirname(relative_path), File.basename(relative_path))
29
+
30
+ if File.extname(file_path).downcase == '.svg'
31
+ static_file = Shi::Jekyll::Images::SVGFile.new(relative_path, source_file)
32
+ else
33
+ # Для WebP используем dummy bounds/crop, так как точные значения неизвестны
34
+ static_file = Shi::Jekyll::Images::WebPFile.new(relative_path, source_file, nil, nil)
35
+ end
36
+ site.static_files << static_file unless site.static_files.include?(static_file)
37
+ end
38
+ end
39
+ end
40
+
16
41
  end
42
+
43
+ # Регистрируем хук для восстановления файлов после чтения сайта
44
+ Jekyll::Hooks.register :site, :post_read do |site|
45
+ Shi::Jekyll::Images::File.restore_generated_files(site)
46
+ end
47
+
17
48
  end
18
49
 
19
50
  class Shi::Jekyll::Images::WebPFile < Jekyll::StaticFile
@@ -62,7 +93,7 @@ class Shi::Jekyll::Images::WebPFile < Jekyll::StaticFile
62
93
  result
63
94
  end
64
95
 
65
- private :new
96
+ # private :new
66
97
  private :name_by_source, :path, :make_key, :default_bounds
67
98
  end
68
99
 
@@ -75,11 +106,14 @@ class Shi::Jekyll::Images::WebPFile < Jekyll::StaticFile
75
106
  end
76
107
 
77
108
  def modified?
78
- true
109
+ src_path = File.join(site.source, @wp_source.relative_path)
110
+ tgt_path = destination site.dest
111
+ return true unless File.exist?(tgt_path) && File.exist?(src_path)
112
+ File.mtime(src_path) > File.mtime(tgt_path)
79
113
  end
80
114
 
81
115
  def write?
82
- true
116
+ modified?
83
117
  end
84
118
 
85
119
  def cropping crop
@@ -119,9 +153,13 @@ class Shi::Jekyll::Images::WebPFile < Jekyll::StaticFile
119
153
  end
120
154
 
121
155
  def write dest
156
+ return true if !write?
157
+
122
158
  tgt_path = destination dest
123
159
  src_path = File::join site.source, @wp_source.relative_path
124
160
 
161
+ return false unless File.exist?(src_path)
162
+
125
163
  FileUtils::mkdir_p(File.dirname(tgt_path))
126
164
  FileUtils::rm(tgt_path) if File.exist?(tgt_path)
127
165
  cmd = "convert '#{src_path}' #{cropping(@wp_crop)} #{resizing(@wp_bounds)} #{qualiting} '#{tgt_path}'"
@@ -163,7 +201,7 @@ class Shi::Jekyll::Images::SVGFile < Jekyll::StaticFile
163
201
  result
164
202
  end
165
203
 
166
- private :new
204
+ # private :new
167
205
  private :path, :make_key
168
206
  end
169
207
 
@@ -174,17 +212,24 @@ class Shi::Jekyll::Images::SVGFile < Jekyll::StaticFile
174
212
  end
175
213
 
176
214
  def modified?
177
- true
215
+ src_path = File.join(site.source, @wp_source.relative_path)
216
+ tgt_path = destination site.dest
217
+ return true unless File.exist?(tgt_path) && File.exist?(src_path)
218
+ File.mtime(src_path) > File.mtime(tgt_path)
178
219
  end
179
220
 
180
221
  def write?
181
- true
222
+ modified?
182
223
  end
183
224
 
184
225
  def write dest
226
+ return true if !write?
227
+
185
228
  tgt_path = destination dest
186
229
  src_path = File::join site.source, @wp_source.relative_path
187
230
 
231
+ return false unless File.exist?(src_path)
232
+
188
233
  FileUtils::mkdir_p(File.dirname(tgt_path))
189
234
  FileUtils::rm(tgt_path) if File.exist?(tgt_path)
190
235
  FileUtils::cp(src_path, tgt_path)
@@ -11,7 +11,7 @@
11
11
  module Shi
12
12
  module Jekyll
13
13
  module Images
14
- VERSION = '0.1.0.10'
14
+ VERSION = '0.1.0.14'
15
15
  end
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shi-jekyll-images
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.10
4
+ version: 0.1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Shikhalev
@@ -91,7 +91,6 @@ executables: []
91
91
  extensions: []
92
92
  extra_rdoc_files: []
93
93
  files:
94
- - ".rufo"
95
94
  - Gemfile
96
95
  - Gemfile.lock
97
96
  - LICENSE.txt
@@ -125,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
124
  - !ruby/object:Gem::Version
126
125
  version: '0'
127
126
  requirements: []
128
- rubygems_version: 3.7.1
127
+ rubygems_version: 3.7.2
129
128
  specification_version: 4
130
129
  summary: Jekyll plugin for image manipulation
131
130
  test_files: []
data/.rufo DELETED
@@ -1,6 +0,0 @@
1
-
2
- align_case_when true
3
- parens_in_def :dynamic
4
- align_chained_calls true
5
- trailing_commas false
6
- quote_style :single