jekyll-webp-resize 1.0.4 → 1.0.5
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/bin/linux-x64-cwebp +0 -0
- data/bin/osx-cwebp +0 -0
- data/jekyll-webp-resize.gemspec +1 -0
- data/lib/jekyll-webp-resize/defaults.rb +1 -0
- data/lib/jekyll-webp-resize/version.rb +1 -1
- data/lib/jekyll-webp-resize/webpExec.rb +14 -3
- data/lib/jekyll-webp-resize/webpGenerator.rb +38 -18
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e9dff223f4761869e7f5402374348a5e827837d
|
4
|
+
data.tar.gz: 35c2334fb968df5c8ef1149057e07673c8025525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b65563476de4a21ecedea13cf14ad690b2284ea8328344e49571fb4bb302ebb900b733ca74346473e88ef9117b7e763c37762625d152e865c18cde39239615ad
|
7
|
+
data.tar.gz: ac5fe30d7ad575b259f7cf3f10bbd7d3d9d93f19d2303bd27e46986e2496e6baaca44c9b56d97795fcbb650d906e7c97fcb2533a5cb56fd6a925a14cbfc8700c
|
data/bin/linux-x64-cwebp
CHANGED
Binary file
|
data/bin/osx-cwebp
CHANGED
Binary file
|
data/jekyll-webp-resize.gemspec
CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.5"
|
24
24
|
spec.add_development_dependency "rake", "~> 1.5"
|
25
25
|
spec.add_development_dependency "minitest", '~> 5.4', '>= 5.4.3'
|
26
|
+
spec.add_development_dependency "fastimage", '~> 2.1'
|
26
27
|
end
|
@@ -19,6 +19,7 @@ module Jekyll
|
|
19
19
|
# List of directories containing images to optimize, Nested directories will not be checked
|
20
20
|
'img_dir' => ["/img"],
|
21
21
|
|
22
|
+
'resize' => [1024, 512, 256],
|
22
23
|
# add ".gif" to the format list to generate webp for animated gifs as well
|
23
24
|
'formats' => [".jpeg", ".jpg", ".png", ".tiff"],
|
24
25
|
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'open3'
|
2
|
+
require 'fastimage'
|
2
3
|
|
3
4
|
module Jekyll
|
4
5
|
module Webp
|
5
6
|
class WebpExec
|
6
7
|
# Runs the WebP executable for the given input parameters
|
7
8
|
# the function detects the OS platform and architecture automatically
|
8
|
-
def self.run(
|
9
|
+
def self.run(input_file, output_file, flags, size)
|
10
|
+
width, height = FastImage.size(input_file)
|
11
|
+
|
9
12
|
# What is the path to the execs inside the gem? perhaps just bin/?
|
10
13
|
bin_path = "bin/"
|
11
14
|
|
@@ -21,9 +24,17 @@ module Jekyll
|
|
21
24
|
# Construct the full path to the executable
|
22
25
|
full_path = File.join(gem_root, bin_path, exe_name)
|
23
26
|
|
24
|
-
Jekyll.logger.info("Webp:", "
|
27
|
+
Jekyll.logger.info("Webp:", "Generating #{output_file}")
|
25
28
|
# Construct the full program call
|
26
|
-
cmd = "\"#{full_path}\" -quiet -mt #{flags} \"#{input_file}\"
|
29
|
+
cmd = "\"#{full_path}\" -quiet -mt #{flags} \"#{input_file}\" "
|
30
|
+
if size != 0
|
31
|
+
if width > height
|
32
|
+
cmd += "-resize #{size.to_s} 0 "
|
33
|
+
else
|
34
|
+
cmd += "-resize 0 #{size.to_s} "
|
35
|
+
end
|
36
|
+
end
|
37
|
+
cmd += "-o \"#{output_file}\""
|
27
38
|
|
28
39
|
# Execute the command
|
29
40
|
exit_code = 0
|
@@ -18,6 +18,24 @@ module Jekyll
|
|
18
18
|
# This generator should be passive with regard to its execution
|
19
19
|
priority :lowest
|
20
20
|
|
21
|
+
# Return a map {size -> filename}
|
22
|
+
def compute_file_resizes(output_file, resize=@config['resize'])
|
23
|
+
output = {0 => output_file}
|
24
|
+
if resize.length == 0
|
25
|
+
return output
|
26
|
+
end
|
27
|
+
|
28
|
+
for resize_entry in resize
|
29
|
+
dirname = File.dirname(output_file)
|
30
|
+
extension = File.extname(output_file)
|
31
|
+
basename = File.basename(output_file, extension)
|
32
|
+
new_output_file = dirname + "/" + basename + "-" + resize_entry.to_s + extension
|
33
|
+
output[resize_entry] = new_output_file
|
34
|
+
end
|
35
|
+
|
36
|
+
return output
|
37
|
+
end
|
38
|
+
|
21
39
|
def generate(site)
|
22
40
|
# Retrieve and merge the configuration from the site yml file
|
23
41
|
@config = DEFAULT.merge(site.config['webp'] || {})
|
@@ -54,25 +72,27 @@ module Jekyll
|
|
54
72
|
FileUtils::mkdir_p(destination_directory + prefix)
|
55
73
|
output_full_path = File.join(destination_directory + prefix, filename)
|
56
74
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
75
|
+
compute_file_resizes(output_full_path).each do |size, output|
|
76
|
+
# Check if the file already has a webp alternative?
|
77
|
+
# If we're force rebuilding all webp files then ignore the check
|
78
|
+
# also check the modified time on the files to ensure that the webp file
|
79
|
+
# is newer than the source file, if not then regenerate
|
80
|
+
if !File.file?(output) ||
|
81
|
+
(File.mtime(output) <= File.mtime(file))
|
82
|
+
# Jekyll.logger.info("WebP:", "Change to image file #{file} detected, regenerating WebP")
|
83
|
+
|
84
|
+
# Generate the file
|
85
|
+
WebpExec.run(file, output, @config['flags'], size)
|
86
|
+
files_generated += 1
|
87
|
+
end
|
88
|
+
if File.file?(output)
|
89
|
+
# Keep the webp file from being cleaned by Jekyll
|
90
|
+
site.static_files << WebpFile.new(site,
|
91
|
+
site.dest,
|
92
|
+
File.join(imgdir, prefix),
|
93
|
+
File.basename(output))
|
94
|
+
end
|
71
95
|
end
|
72
|
-
|
73
|
-
# Generate the file
|
74
|
-
WebpExec.run(@config['flags'], file, output_full_path)
|
75
|
-
files_generated += 1
|
76
96
|
end # dir.foreach
|
77
97
|
end # img_dir
|
78
98
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-webp-resize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sverrir Sigmundarson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|
@@ -73,6 +73,20 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 5.4.3
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: fastimage
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.1'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.1'
|
76
90
|
description: WebP Image Generator for Jekyll 3 Sites that automatically generate WebP
|
77
91
|
images for all images on your static site and serves them when possible.
|
78
92
|
email:
|