@@ -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 )
@@ -50,22 +50,26 @@ def generate(site)
5050 imgdir_destination = File . join ( site . dest , imgdir )
5151 FileUtils ::mkdir_p ( imgdir_destination )
5252 Jekyll . logger . info "WebP:" , "Processing #{ imgdir_source } "
53-
53+
5454 # handle only jpg, jpeg, png and gif
5555 for imgfile in Dir [ imgdir_source + "**/*.*" ]
5656 imgfile_relative_path = File . dirname ( imgfile . sub ( imgdir_source , "" ) )
57-
57+
5858 # Skip empty stuff
5959 file_ext = File . extname ( imgfile ) . downcase
6060
6161 # If the file is not one of the supported formats, exit early
6262 next if !@config [ 'formats' ] . include? file_ext
6363
6464 # TODO: Do an exclude check
65-
65+
6666 # Create the output file path
67- file_noext = File . basename ( imgfile , file_ext )
68- outfile_filename = file_noext + ".webp"
67+ outfile_filename = if @config [ 'append_ext' ]
68+ File . basename ( imgfile ) + '.webp'
69+ else
70+ file_noext = File . basename ( imgfile , file_ext )
71+ file_noext + ".webp"
72+ end
6973 FileUtils ::mkdir_p ( imgdir_destination + imgfile_relative_path )
7074 outfile_fullpath_webp = File . join ( imgdir_destination + imgfile_relative_path , outfile_filename )
7175
@@ -96,6 +100,6 @@ def generate(site)
96100 end #function generate
97101
98102 end #class WebPGenerator
99-
103+
100104 end #module Webp
101105end #module Jekyll
0 commit comments