Skip to content

Commit b01eda4

Browse files
committed
Fixing working path detection for executables and minor bugs
1 parent fdee843 commit b01eda4

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

lib/jekyll-webp/webpExec.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'os'
1+
require 'open3'
22

33
module Jekyll
44
module Webp
@@ -17,18 +17,23 @@ def self.run(quality, input_file, output_file)
1717
# What is the OS and architecture specific executable name?
1818
exe_name = WebpExec.exe_name
1919

20-
full_path = File.join(bin_path, exe_name)
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
25+
26+
# Construct the full path to the executable
27+
full_path = File.join(gem_root, bin_path, exe_name)
2128

2229
# Construct the full program call
2330
cmd = "\"#{full_path}\" -quiet -mt -q #{quality.to_s} \"#{input_file}\" -o \"#{output_file}\""
24-
25-
puts "Command: "+cmd
2631

2732
# Execute the command
28-
retValue = %x[ #{cmd} ]
33+
stdin, stdout, stderr = Open3.popen3(cmd)
2934

3035
# Return any captured return value
31-
return retValue
36+
return [stdin, stdout, stderr]
3237
end #function run
3338

3439
#
@@ -38,13 +43,13 @@ def self.exe_name
3843
if OS.mac?
3944
return "osx-cwebp"
4045
elsif OS.windows?
41-
if OS.32bit?
46+
if OS.x32?
4247
return "win-x86-cwebp.exe"
4348
else
4449
return "win-x64-cwebp.exe"
4550
end
4651
elsif OS.unix? || OS.linux?
47-
if OS.32bit?
52+
if OS.x32?
4853
return "linux-x86-cwebp"
4954
else
5055
return "linux-x64-cwebp"
@@ -75,11 +80,11 @@ def OS.linux?
7580
OS.unix? and not OS.mac?
7681
end
7782

78-
def OS.32bit?
83+
def OS.x32?
7984
return 1.size != 8
8085
end
8186

82-
def OS.64bit?
87+
def OS.x64?
8388
return 1.size == 8
8489
end
8590
end #module OS

lib/jekyll-webp/webpGenerator.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class WebpFile < StaticFile
1010
def write(dest)
1111
true # Recover from strange exception when starting server without --auto
1212
end
13-
end #class WebPImageFile
13+
end #class WebpFile
1414

1515
class WebpGenerator < Generator
1616
# This generator is safe from arbitrary code execution.
@@ -34,11 +34,14 @@ def generate(site)
3434
return
3535
end
3636

37-
Jekyll.logger.info "WebP:","Starting"
37+
Jekyll.logger.debug "WebP:","Starting"
3838

3939
# If the site destination directory has not yet been created then create it now. Otherwise, we cannot write our file there.
4040
Dir::mkdir(site.dest) if !File.directory? site.dest
4141

42+
# Counting the number of files generated
43+
file_count = 0
44+
4245
# Iterate through every image in each of the image folders and create a webp image
4346
# if one has not been created already for that image.
4447
for imgdir in @config['img_dir']
@@ -75,8 +78,6 @@ def generate(site)
7578
if( File.file?(outfile_fullpath_webp) &&
7679
File.mtime(outfile_fullpath_webp) <= File.mtime(infile_fullpath) )
7780
Jekyll.logger.info "WebP:", "Change to source image file #{imgfile} detected, regenerating WebP"
78-
#puts " WebP: "+File.mtime(outfile_fullpath_webp).strftime('%Y-%m-%d %H:%M:%S')
79-
#puts " Source: "+File.mtime(infile_fullpath).strftime('%Y-%m-%d %H:%M:%S')
8081
end
8182

8283
# Generate the file

0 commit comments

Comments
 (0)