Merge pull request #65 from wildlyinaccurate/jericbryledy-master
Add save_to_source option
This commit is contained in:
commit
66b0f3fce9
|
@ -71,6 +71,10 @@ responsive_image:
|
|||
#
|
||||
output_path_format: assets/resized/%{width}/%{basename}
|
||||
|
||||
# [Optional, Default: true]
|
||||
# Whether or not to save the generated assets into the source folder.
|
||||
save_to_source: false
|
||||
|
||||
# [Optional, Default: []]
|
||||
# By default, only images referenced by the responsive_image and responsive_image_block
|
||||
# tags are resized. Here you can set a list of paths or path globs to resize other
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
Feature: Save to source
|
||||
Scenario: Resized images are saved to the source directory by default
|
||||
Given I have a responsive_image configuration with:
|
||||
"""
|
||||
sizes:
|
||||
- width: 100
|
||||
extra_images:
|
||||
- assets/everybody-loves-jalapeño-pineapple-cornbread.png
|
||||
"""
|
||||
And I have a file "index.html" with "Hello, world!"
|
||||
When I run Jekyll
|
||||
Then the file "assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png" should exist
|
||||
And the file "_site/assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png" should exist
|
||||
|
||||
Scenario: Resized images can be saved to the destination directory only with save_to_source: false
|
||||
Given I have a responsive_image configuration with:
|
||||
"""
|
||||
save_to_source: false
|
||||
sizes:
|
||||
- width: 100
|
||||
extra_images:
|
||||
- assets/everybody-loves-jalapeño-pineapple-cornbread.png
|
||||
- assets/*.jpeg
|
||||
"""
|
||||
And I have a file "index.html" with "Hello, world!"
|
||||
When I run Jekyll
|
||||
Then the file "assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png" should not exist
|
||||
But the file "_site/assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png" should exist
|
|
@ -7,7 +7,8 @@ module Jekyll
|
|||
'output_path_format' => 'assets/resized/%{filename}-%{width}x%{height}.%{extension}',
|
||||
'sizes' => [],
|
||||
'extra_images' => [],
|
||||
'auto_rotate' => false
|
||||
'auto_rotate' => false,
|
||||
'save_to_source' => true
|
||||
}
|
||||
|
||||
def initialize(site)
|
||||
|
|
|
@ -22,23 +22,31 @@ module Jekyll
|
|||
site_source_filepath = File.expand_path(filepath, config[:site_source])
|
||||
site_dest_filepath = File.expand_path(filepath, config[:site_dest])
|
||||
|
||||
# Don't resize images more than once
|
||||
next if File.exist?(site_source_filepath)
|
||||
if config['save_to_source']
|
||||
target_filepath = site_source_filepath
|
||||
else
|
||||
target_filepath = site_dest_filepath
|
||||
end
|
||||
|
||||
ensure_output_dir_exists!(site_source_filepath)
|
||||
# Don't resize images more than once
|
||||
next if File.exist?(target_filepath)
|
||||
|
||||
ensure_output_dir_exists!(target_filepath)
|
||||
ensure_output_dir_exists!(site_dest_filepath)
|
||||
|
||||
Jekyll.logger.info "Generating #{site_source_filepath}"
|
||||
Jekyll.logger.info "Generating #{target_filepath}"
|
||||
|
||||
i = img.scale(ratio)
|
||||
i.write(site_source_filepath) do |f|
|
||||
i.write(target_filepath) do |f|
|
||||
f.interlace = i.interlace
|
||||
f.quality = size['quality'] || config['default_quality']
|
||||
end
|
||||
|
||||
# Ensure the generated file is copied to the _site directory
|
||||
Jekyll.logger.info "Copying resized image to #{site_dest_filepath}"
|
||||
FileUtils.copy_file(site_source_filepath, site_dest_filepath)
|
||||
if config['save_to_source']
|
||||
# Ensure the generated file is copied to the _site directory
|
||||
Jekyll.logger.info "Copying resized image to #{site_dest_filepath}"
|
||||
FileUtils.copy_file(site_source_filepath, site_dest_filepath)
|
||||
end
|
||||
|
||||
i.destroy!
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue