lib/jekyll/zopfli/compressor.rb in jekyll-zopfli-2.2.0 vs lib/jekyll/zopfli/compressor.rb in jekyll-zopfli-2.3.0

- old
+ new

@@ -23,11 +23,11 @@ # site files ready for compression. # # @return void def self.compress_site(site) site.each_site_file do |file| - compress_file(file.destination(site.dest), extensions: zippable_extensions(site)) + compress_file(file.destination(site.dest), extensions: zippable_extensions(site), replace_file: replace_files(site)) end end ## # Takes a directory path and maps over the files within compressing them @@ -42,12 +42,12 @@ # config. # # @return void def self.compress_directory(dir, site) extensions = zippable_extensions(site).join(',') - files = Dir.glob(dir + "**/*{#{extensions}}") - files.each { |file| compress_file(file, extensions: zippable_extensions(site)) } + files = Dir.glob(dir + "/**/*{#{extensions}}") + files.each { |file| compress_file(file, extensions: zippable_extensions(site), replace_file: replace_files(site)) } end ## # Takes a file name and an array of extensions. If the file name extension # matches one of the extensions in the array then the file is loaded and @@ -58,11 +58,11 @@ # Jekyll::Zopfli::Compressor.compress_file("~/blog/_site/index.html", ['.html') # # @param file_name [String] The file name of the file we want to compress # @param extensions [Array<String>] The extensions of files that will be # compressed. - # @param replace_file [Boolean] Whether the origina file should be + # @param replace_file [Boolean] Whether the original file should be # replaced or written alongside the original with a `.gz` extension # # @return void def self.compress_file(file_name, extensions: [], replace_file: false) return unless extensions.include?(File.extname(file_name)) @@ -77,8 +77,13 @@ private def self.zippable_extensions(site) site.config['zopfli'] && site.config['zopfli']['extensions'] || Jekyll::Zopfli::DEFAULT_CONFIG['extensions'] end + + def self.replace_files(site) + replace_files = site.config.dig('zopfli', 'replace_files') + replace_files.nil? ? Jekyll::Zopfli::DEFAULT_CONFIG['replace_files'] : replace_files + end end end -end \ No newline at end of file +end