Skip to content

Commit 162996d

Browse files
authored
Merge pull request #19 from rivsc/master
Add Support for custom CWEBP bin path
2 parents 318fe64 + f8e9038 commit 162996d

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ webp:
5353

5454
# Local path to the WebP utilities to use (relative or absolute)
5555
# Omit or leave as nil to use the utilities shipped with the gem, override only to use your local install
56+
# Eg : "/usr/local/bin/cwebp"
5657
webp_path: nil
5758

5859
# List of files or directories to exclude

lib/jekyll-webp/webpExec.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@ class WebpExec
99
# Runs the WebP executable for the given input parameters
1010
# the function detects the OS platform and architecture automatically
1111
#
12-
def self.run(quality, flags, input_file, output_file)
12+
def self.run(quality, flags, input_file, output_file, webp_bin_fullpath)
1313

14-
# What is the path to the execs inside the gem? perhaps just bin/?
15-
bin_path = "bin/"
14+
if webp_bin_fullpath
15+
full_path = webp_bin_fullpath
16+
else
17+
# What is the path to the execs inside the gem? perhaps just bin/?
18+
bin_path = "bin/"
1619

17-
# What is the OS and architecture specific executable name?
18-
exe_name = WebpExec.exe_name
20+
# What is the OS and architecture specific executable name?
21+
exe_name = WebpExec.exe_name
1922

20-
# We need to locate the Gems bin path as we're currently running inside the
21-
# jekyll site working directory
22-
# http://stackoverflow.com/a/10083594/779521
23-
gem_spec = Gem::Specification.find_by_name("jekyll-webp")
24-
gem_root = gem_spec.gem_dir
23+
# We need to locate the Gems bin path as we're currently running inside the
24+
# jekyll site working directory
25+
# http://stackoverflow.com/a/10083594/779521
26+
gem_spec = Gem::Specification.find_by_name("jekyll-webp")
27+
gem_root = gem_spec.gem_dir
2528

26-
# Construct the full path to the executable
27-
full_path = File.join(gem_root, bin_path, exe_name)
29+
# Construct the full path to the executable
30+
full_path = File.join(gem_root, bin_path, exe_name)
31+
end
2832

2933
# Construct the full program call
3034
cmd = "\"#{full_path}\" -quiet -mt -q #{quality.to_s} #{flags} \"#{input_file}\" -o \"#{output_file}\""

lib/jekyll-webp/webpGenerator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def generate(site)
9292
Jekyll.logger.info "WebP:", "Change to source image file #{imgfile} detected, regenerating WebP"
9393

9494
# Generate the file
95-
WebpExec.run(@config['quality'], @config['flags'], imgfile, outfile_fullpath_webp)
95+
WebpExec.run(@config['quality'], @config['flags'], imgfile, outfile_fullpath_webp, @config['webp_path'])
9696
file_count += 1
9797
end
9898
if File.file?(outfile_fullpath_webp)

0 commit comments

Comments
 (0)