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 +4 -4
- data/lib/shi/jekyll/images/files.rb +51 -6
- data/lib/shi/jekyll/images/version.rb +1 -1
- metadata +2 -3
- data/.rufo +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eac0cef4a9dcd2d9f3d8fdffdc0b5b9335f14a77eb9d0b56e87c19e814d398f7
|
4
|
+
data.tar.gz: 73afca035a829bcc8ad48b8911df13f842e5a4d2d8deb24be0f67b74ecc4ea97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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)
|
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.
|
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.
|
127
|
+
rubygems_version: 3.7.2
|
129
128
|
specification_version: 4
|
130
129
|
summary: Jekyll plugin for image manipulation
|
131
130
|
test_files: []
|