Skip to content

Commit

Permalink
Merge pull request #6 from Jetroid/master
Browse files Browse the repository at this point in the history
Allow nested search
sverrirs authored Oct 28, 2019
2 parents fbae458 + ae14f21 commit 318fe64
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -35,10 +35,13 @@ webp:
# The quality of the webp conversion 0 to 100 (where 100 is least lossy)
quality: 75

# List of directories containing images to optimize, nested directories will not be checked
# List of directories containing images to optimize, nested directories will only be checked if `nested` is true
# By default the generator will search for a folder called `/img` under the site root and process all jpg, png and tiff image files found there.
img_dir: ["/img"]

# Whether to search in nested directories or not
nested: false

# add ".gif" to the format list to generate webp for animated gifs as well
formats: [".jpeg", ".jpg", ".png", ".tiff"]

5 changes: 4 additions & 1 deletion lib/jekyll-webp/defaults.rb
Original file line number Diff line number Diff line change
@@ -13,9 +13,12 @@ module Webp
# https://developers.google.com/speed/webp/docs/cwebp#options
'flags' => "-m 4 -pass 4 -af",

# List of directories containing images to optimize, Nested directories will not be checked
# List of directories containing images to optimize, Nested directories only be checked if `nested` is true
'img_dir' => ["/img"],

# Whether to search in nested directories or not
'nested' => false,

# add ".gif" to the format list to generate webp for animated gifs as well
'formats' => [".jpeg", ".jpg", ".png", ".tiff"],

10 changes: 10 additions & 0 deletions lib/jekyll-webp/webpGenerator.rb
Original file line number Diff line number Diff line change
@@ -40,6 +40,16 @@ def generate(site)
# If the site destination directory has not yet been created then create it now. Otherwise, we cannot write our file there.
Dir::mkdir(site.dest) if !File.directory? site.dest

# If nesting is enabled, get all the nested directories too
if @config['nested']
newdir = []
for imgdir in @config['img_dir']
# Get every directory below (and including) imgdir, recursively
newdir.concat(Dir.glob(imgdir + "/**/"))
end
@config['img_dir'] = newdir
end

# Counting the number of files generated
file_count = 0

0 comments on commit 318fe64

Please sign in to comment.