Skip to content

Commit

Permalink
Allow nested search with option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jetroid committed Sep 20, 2019
1 parent 22a08ec commit ae14f21
Show file tree
Hide file tree
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
Expand Up @@ -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"]

Expand Down
5 changes: 4 additions & 1 deletion lib/jekyll-webp/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"],

Expand Down
10 changes: 10 additions & 0 deletions lib/jekyll-webp/webpGenerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

1 comment on commit ae14f21

@nervewax
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this @Jetroid 🙌

Please sign in to comment.