Skip to content

Commit 318fe64

Browse files
authored
Merge pull request #6 from Jetroid/master
Allow nested search
2 parents fbae458 + ae14f21 commit 318fe64

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ webp:
3535
# The quality of the webp conversion 0 to 100 (where 100 is least lossy)
3636
quality: 75
3737

38-
# List of directories containing images to optimize, nested directories will not be checked
38+
# List of directories containing images to optimize, nested directories will only be checked if `nested` is true
3939
# 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.
4040
img_dir: ["/img"]
4141

42+
# Whether to search in nested directories or not
43+
nested: false
44+
4245
# add ".gif" to the format list to generate webp for animated gifs as well
4346
formats: [".jpeg", ".jpg", ".png", ".tiff"]
4447

lib/jekyll-webp/defaults.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ module Webp
1313
# https://developers.google.com/speed/webp/docs/cwebp#options
1414
'flags' => "-m 4 -pass 4 -af",
1515

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

19+
# Whether to search in nested directories or not
20+
'nested' => false,
21+
1922
# add ".gif" to the format list to generate webp for animated gifs as well
2023
'formats' => [".jpeg", ".jpg", ".png", ".tiff"],
2124

lib/jekyll-webp/webpGenerator.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ def generate(site)
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
4242

43+
# If nesting is enabled, get all the nested directories too
44+
if @config['nested']
45+
newdir = []
46+
for imgdir in @config['img_dir']
47+
# Get every directory below (and including) imgdir, recursively
48+
newdir.concat(Dir.glob(imgdir + "/**/"))
49+
end
50+
@config['img_dir'] = newdir
51+
end
52+
4353
# Counting the number of files generated
4454
file_count = 0
4555

0 commit comments

Comments
 (0)