Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nested search #6

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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