Skip to content

Commit

Permalink
Merge pull request #19 from rivsc/master
Browse files Browse the repository at this point in the history
Add Support for custom CWEBP bin path
  • Loading branch information
sverrirs authored Jul 28, 2022
2 parents 318fe64 + f8e9038 commit 162996d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ webp:

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

# List of files or directories to exclude
Expand Down
28 changes: 16 additions & 12 deletions lib/jekyll-webp/webpExec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ class WebpExec
# Runs the WebP executable for the given input parameters
# the function detects the OS platform and architecture automatically
#
def self.run(quality, flags, input_file, output_file)
def self.run(quality, flags, input_file, output_file, webp_bin_fullpath)

# What is the path to the execs inside the gem? perhaps just bin/?
bin_path = "bin/"
if webp_bin_fullpath
full_path = webp_bin_fullpath
else
# What is the path to the execs inside the gem? perhaps just bin/?
bin_path = "bin/"

# What is the OS and architecture specific executable name?
exe_name = WebpExec.exe_name
# What is the OS and architecture specific executable name?
exe_name = WebpExec.exe_name

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

# Construct the full path to the executable
full_path = File.join(gem_root, bin_path, exe_name)
# Construct the full path to the executable
full_path = File.join(gem_root, bin_path, exe_name)
end

# Construct the full program call
cmd = "\"#{full_path}\" -quiet -mt -q #{quality.to_s} #{flags} \"#{input_file}\" -o \"#{output_file}\""
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-webp/webpGenerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def generate(site)
Jekyll.logger.info "WebP:", "Change to source image file #{imgfile} detected, regenerating WebP"

# Generate the file
WebpExec.run(@config['quality'], @config['flags'], imgfile, outfile_fullpath_webp)
WebpExec.run(@config['quality'], @config['flags'], imgfile, outfile_fullpath_webp, @config['webp_path'])
file_count += 1
end
if File.file?(outfile_fullpath_webp)
Expand Down

0 comments on commit 162996d

Please sign in to comment.