Skip to content

Commit 728711e

Browse files
emmmilesverrirs
authored andcommitted
reverting changes after review
1 parent e436d88 commit 728711e

File tree

2 files changed

+54
-52
lines changed

2 files changed

+54
-52
lines changed

lib/jekyll-webp/webpExec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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-
# We need to locate the Gems bin path as we're currently running inside the
20+
# We need to locate the Gems bin path as we're currently running inside the
2121
# jekyll site working directory
2222
# http://stackoverflow.com/a/10083594/779521
2323
gem_spec = Gem::Specification.find_by_name("jekyll-webp")
@@ -27,8 +27,8 @@ def self.run(quality, input_file, output_file)
2727
full_path = File.join(gem_root, bin_path, exe_name)
2828

2929
# Construct the full program call
30-
cmd = "\"#{full_path}\" -quiet -mt -m 6 -pass 10 -q #{quality.to_s} \"#{input_file}\" -o \"#{output_file}\""
31-
30+
cmd = "\"#{full_path}\" -quiet -mt -q #{quality.to_s} \"#{input_file}\" -o \"#{output_file}\""
31+
3232
# Execute the command
3333
stdin, stdout, stderr = Open3.popen3(cmd)
3434

@@ -60,7 +60,7 @@ def self.exe_name
6060
end #function exe_name
6161

6262
end #class WebpExec
63-
63+
6464
end #module Webp
6565

6666
module OS
@@ -88,4 +88,4 @@ def OS.x64?
8888
return 1.size == 8
8989
end
9090
end #module OS
91-
end #module Jekyll
91+
end #module Jekyll

lib/jekyll-webp/webpGenerator.rb

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Jekyll
55
module Webp
66

77
#
8-
# A static file to hold the generated webp image after generation
8+
# A static file to hold the generated webp image after generation
99
# so that Jekyll will copy it into the site output directory
1010
class WebpFile < StaticFile
1111
def write(dest)
@@ -31,11 +31,11 @@ def generate(site)
3131

3232
# If disabled then simply quit
3333
if !@config['enabled']
34-
Jekyll.logger.info "WebP:", "Disabled in site.config."
34+
Jekyll.logger.info "WebP:","Disabled in site.config."
3535
return
3636
end
3737

38-
Jekyll.logger.debug "WebP:", "Starting"
38+
Jekyll.logger.debug "WebP:","Starting"
3939

4040
# If the site destination directory has not yet been created then create it now. Otherwise, we cannot write our file there.
4141
Dir::mkdir(site.dest) if !File.directory? site.dest
@@ -45,55 +45,57 @@ def generate(site)
4545

4646
# Iterate through every image in each of the image folders and create a webp image
4747
# if one has not been created already for that image.
48-
for source in @config['img_dir']
49-
source_full_path = File.join(site.source, source)
50-
destination_full_path = File.join(site.dest, source)
51-
FileUtils::mkdir_p destination_full_path
52-
Jekyll.logger.info "WebP:", "Processing #{source_full_path}"
53-
54-
for file_full_path in Dir[source_full_path + "/**/*.*"]
55-
file_relative_path = file_full_path.sub(source_full_path, "")
56-
57-
file_extension = File.extname(file_full_path).downcase
58-
59-
# If the file is not one of the supported formats, exit early
60-
next if !@config['formats'].include? file_extension
61-
62-
# TODO: Do an exclude check
63-
64-
# Create the output file path
65-
file_no_extension = File.basename(file_full_path, file_extension)
66-
relative_path = File.dirname(file_relative_path)
67-
FileUtils::mkdir_p(destination_full_path + relative_path)
68-
outfile_fullpath_webp = File.join(destination_full_path + relative_path, file_no_extension + ".webp")
69-
70-
# Check if the file already has a webp alternative?
71-
# If we're force rebuilding all webp files then ignore the check
72-
# also check the modified time on the files to ensure that the webp file
73-
# is newer than the source file, if not then regenerate
74-
next if !@config['regenerate'] && File.file?(outfile_fullpath_webp) &&
75-
File.mtime(outfile_fullpath_webp) > File.mtime(source_full_path)
76-
77-
if( File.file?(outfile_fullpath_webp) &&
78-
File.mtime(outfile_fullpath_webp) <= File.mtime(source_full_path) )
79-
Jekyll.logger.info "WebP:", "Change to source image file #{file} detected, regenerating WebP"
80-
end
81-
82-
Jekyll.logger.info "WebP:", "Generating #{outfile_fullpath_webp}"
83-
# Generate the file
84-
WebpExec.run(@config['quality'], file_full_path, outfile_fullpath_webp)
85-
86-
# Keep the webp file from being cleaned by Jekyll
87-
site.static_files << WebpFile.new(site, site.dest, source, outfile_fullpath_webp)
88-
file_count += 1
89-
end # file_full_path
48+
for imgdir in @config['img_dir']
49+
imgdir_source = File.join(site.source, imgdir)
50+
imgdir_destination = File.join(site.dest, imgdir)
51+
FileUtils::mkdir_p(imgdir_destination)
52+
Jekyll.logger.info "WebP:","Processing #{imgdir_source}"
53+
54+
# handle only jpg, jpeg, png and gif
55+
for imgfile in Dir[imgdir_source + "**/*.*"]
56+
imgfile_relative_path = File.dirname(imgfile.sub(imgdir_source, ""))
57+
58+
# Skip empty stuff
59+
file_ext = File.extname(imgfile).downcase
60+
61+
# If the file is not one of the supported formats, exit early
62+
next if !@config['formats'].include? file_ext
63+
64+
# TODO: Do an exclude check
65+
66+
# Create the output file path
67+
file_noext = File.basename(imgfile, file_ext)
68+
outfile_filename = file_noext+ ".webp"
69+
FileUtils::mkdir_p(imgdir_destination + imgfile_relative_path)
70+
outfile_fullpath_webp = File.join(imgdir_destination + imgfile_relative_path, outfile_filename)
71+
72+
# Check if the file already has a webp alternative?
73+
# If we're force rebuilding all webp files then ignore the check
74+
# also check the modified time on the files to ensure that the webp file
75+
# is newer than the source file, if not then regenerate
76+
next if !@config['regenerate'] && File.file?(outfile_fullpath_webp) &&
77+
File.mtime(outfile_fullpath_webp) > File.mtime(imgfile)
78+
79+
if( File.file?(outfile_fullpath_webp) &&
80+
File.mtime(outfile_fullpath_webp) <= File.mtime(imgfile) )
81+
Jekyll.logger.info "WebP:", "Change to source image file #{imgfile} detected, regenerating WebP"
82+
end
83+
84+
# Generate the file
85+
WebpExec.run(@config['quality'], imgfile, outfile_fullpath_webp)
86+
87+
# Keep the webp file from being cleaned by Jekyll
88+
site.static_files << WebpFile.new(site, site.dest, imgdir, outfile_fullpath_webp)
89+
file_count += 1
90+
91+
end # dir.foreach
9092
end # img_dir
9193

92-
Jekyll.logger.info "WebP:", "Generator Complete: #{file_count} file(s) generated"
94+
Jekyll.logger.info "WebP:","Generator Complete: #{file_count} file(s) generated"
9395

9496
end #function generate
9597

9698
end #class WebPGenerator
97-
99+
98100
end #module Webp
99101
end #module Jekyll

0 commit comments

Comments
 (0)