jekyll-webp 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80ba6286b2216fafd1e971367ba4b31ac867d03c
4
- data.tar.gz: e2df650ac6d08f7801ec9bb23fa1e62011161a55
3
+ metadata.gz: f9566892837b2ba7870b279d0381dc8c8e9158d5
4
+ data.tar.gz: 2e8aeb32f03eb687a7c1bb28c0fdd954623bf254
5
5
  SHA512:
6
- metadata.gz: baa7c2aaacdd3e6715087566dc1136adccb928bf5b914194fb88bdda4160393c1d91bd57489f4b3c5e6c3f182aa0851323cb6a3f3dc33403ffda59fd719de162
7
- data.tar.gz: d962aa0179ac79b319555f498eedb7b7c432f051d8490ba6f940d5cc88cc480a0f40be48bb0108ea4d548881b6c7c132e10db292966b4a4ef588a48cf8188077
6
+ metadata.gz: b3cacb25d5b0ffc941f026246c37e92fc43b31188e5c6f5e1fade6c86be3adb9de69d027faee878981713e88eadc16dff337e0263c0ed9101488e5e06466cce4
7
+ data.tar.gz: ee976ec33274355dd4378d77a5c30c639e32536d96ed51acf75e6b6c5d8a62e652d9dda62d0ccc2aa30321acbf85651a32c612b7e17c9718200a8c979729efd2
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  # WebP Generator for Jekyll
3
- WebP Image Generator for Jekyll Sites can automatically generate WebP images for all images on your static site and serve them when possible.
3
+ WebP Image Generator for Jekyll Sites can automatically generate WebP images for all images on your static site and serve them when possible. View on [rubygems.org](https://rubygems.org/gems/jekyll-webp).
4
+
4
5
  > Read more about this tool on my blog at <a href="https://blog.sverrirs.com/2016/06/webp-generator-for-jekyll-sites.html" target="_blank">blog.sverrirs.com</a>
5
6
 
6
7
  ## Installation
@@ -11,7 +12,7 @@ gem install jekyll-webp
11
12
 
12
13
  The release includes all necessary files to run, including the WebP redistributable executable files.
13
14
 
14
- > Currently the release includes the v0.5.1 version of the WebP utilities for Windows, Linux and Mac OS X 10.9 (Mountain Lion). Other versions and releases can be downloaded directly from <a href="https://developers.google.com/speed/webp/docs/precompiled" target="_blank">the Google page</a>.
15
+ > Currently the release includes the v0.6.1 version of the WebP utilities for Windows, Linux and Mac OS X 10.9 (Mountain Lion). Other versions and releases can be downloaded directly from <a href="https://developers.google.com/speed/webp/docs/precompiled" target="_blank">the Google page</a>.
15
16
 
16
17
  Add the gem to your `Gemfile` and to Jekyll's `_config.yml` then run `jekyll serve` again and you should see the generator run during site generation.
17
18
 
@@ -62,7 +63,7 @@ In case you don't have control over your webserver then using the `<picture>` el
62
63
  ```
63
64
 
64
65
  ## Advanced use: Webserver Configuration
65
- If you can then configuring your webserver to serve your new _.webp_ files to clients that support the format is probably the least problematic approach. This way you don't need to make any changes to your HTML files as your webserver will automatically serve WebP images when the client supports them.
66
+ If you can, then configuring your webserver to serve your new _.webp_ files to clients that support the format is probably the least problematic approach. This way you don't need to make any changes to your HTML files as your webserver will automatically serve WebP images when the client supports them.
66
67
 
67
68
  Below is an example for a .htaccess configuration section in an Apache web-server. It will redirect users to webp images whenever possible.
68
69
 
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.license = "MIT"
13
13
 
14
14
  spec.summary = %q{WebP image generator for Jekyll 3 websites}
15
- spec.description = %q{WebP Image Generator for Jekyll 3 Sites that automatically generate WebP images for all images on your static site and serves them when possible.}
15
+ spec.description = %q{WebP Image Generator for Jekyll 3 Sites that automatically generate WebP images for all images on your static site and serves them when possible. Includes the v0.6.1 version of the WebP utilities for Windows, Linux and Mac OS X 10.9 (Mountain Lion)}
16
16
 
17
17
  spec.files = Dir['CODE_OF_CONDUCT.md', 'README.md', 'LICENSE', 'Rakefile', '*.gemspec', 'Gemfile', 'lib/**/*', 'spec/**/*', 'bin/**/*']
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -9,6 +9,10 @@ module Jekyll
9
9
  # The quality of the webp conversion 0 to 100 (where 100 is least lossy)
10
10
  'quality' => 75,
11
11
 
12
+ # Other flags to pass to the webp binary. For a list of valid parameters check here:
13
+ # https://developers.google.com/speed/webp/docs/cwebp#options
14
+ 'flags' => "-m 4 -pass 4 -af",
15
+
12
16
  # List of directories containing images to optimize, Nested directories will not be checked
13
17
  'img_dir' => ["/img"],
14
18
 
@@ -35,4 +39,4 @@ module Jekyll
35
39
  }
36
40
 
37
41
  end # module Webp
38
- end # module Jekyll
42
+ end # module Jekyll
@@ -1,8 +1,8 @@
1
1
  module Jekyll
2
2
  module Webp
3
- VERSION = "0.1.0"
3
+ VERSION = "1.0.0"
4
4
  # When modifying remember to issue a new tag command in git before committing, then push the new tag
5
- # git tag -a v0.1.0 -m "Gem v0.1.0"
5
+ # git tag -a v1.0.0 -m "Gem v1.0.0"
6
6
  # git push origin --tags
7
7
  end #module Webp
8
- end #module Jekyll
8
+ end #module Jekyll
@@ -9,7 +9,7 @@ module Jekyll
9
9
  # Runs the WebP executable for the given input parameters
10
10
  # the function detects the OS platform and architecture automatically
11
11
  #
12
- def self.run(quality, input_file, output_file)
12
+ def self.run(quality, flags, input_file, output_file)
13
13
 
14
14
  # What is the path to the execs inside the gem? perhaps just bin/?
15
15
  bin_path = "bin/"
@@ -27,13 +27,26 @@ module Jekyll
27
27
  full_path = File.join(gem_root, bin_path, exe_name)
28
28
 
29
29
  # Construct the full program call
30
- cmd = "\"#{full_path}\" -quiet -mt -q #{quality.to_s} \"#{input_file}\" -o \"#{output_file}\""
30
+ cmd = "\"#{full_path}\" -quiet -mt -q #{quality.to_s} #{flags} \"#{input_file}\" -o \"#{output_file}\""
31
31
 
32
32
  # Execute the command
33
- stdin, stdout, stderr = Open3.popen3(cmd)
33
+ exit_code = 0
34
+ error = ""
35
+ output = ""
36
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
37
+ stdin.close # we don't pass any input to the process
38
+ output = stdout.gets
39
+ error = stderr.gets
40
+ exit_code = wait_thr.value
41
+ end
42
+
43
+ if exit_code != 0
44
+ Jekyll.logger.error("WebP:","Conversion for image #{input_file} failed, no webp version could be created for this image")
45
+ Jekyll.logger.debug("WebP:","cwebp returned #{exit_code} with error #{error}")
46
+ end
34
47
 
35
48
  # Return any captured return value
36
- return [stdin, stdout, stderr]
49
+ return [output, error]
37
50
  end #function run
38
51
 
39
52
  #
@@ -88,4 +101,4 @@ module Jekyll
88
101
  return 1.size == 8
89
102
  end
90
103
  end #module OS
91
- end #module Jekyll
104
+ end #module Jekyll
@@ -1,4 +1,5 @@
1
1
  require 'jekyll/document'
2
+ require 'fileutils'
2
3
 
3
4
  module Jekyll
4
5
  module Webp
@@ -10,7 +11,7 @@ module Jekyll
10
11
  def write(dest)
11
12
  true # Recover from strange exception when starting server without --auto
12
13
  end
13
- end #class WebPImageFile
14
+ end #class WebpFile
14
15
 
15
16
  class WebpGenerator < Generator
16
17
  # This generator is safe from arbitrary code execution.
@@ -34,25 +35,27 @@ module Jekyll
34
35
  return
35
36
  end
36
37
 
37
- Jekyll.logger.info "WebP:","Starting"
38
+ Jekyll.logger.debug "WebP:","Starting"
38
39
 
39
40
  # If the site destination directory has not yet been created then create it now. Otherwise, we cannot write our file there.
40
41
  Dir::mkdir(site.dest) if !File.directory? site.dest
41
42
 
42
43
  # Counting the number of files generated
43
44
  file_count = 0
44
-
45
+
45
46
  # Iterate through every image in each of the image folders and create a webp image
46
47
  # if one has not been created already for that image.
47
48
  for imgdir in @config['img_dir']
48
49
  imgdir_source = File.join(site.source, imgdir)
50
+ imgdir_destination = File.join(site.dest, imgdir)
51
+ FileUtils::mkdir_p(imgdir_destination)
49
52
  Jekyll.logger.info "WebP:","Processing #{imgdir_source}"
50
53
 
51
54
  # handle only jpg, jpeg, png and gif
52
- Dir.foreach(imgdir_source) do |imgfile|
55
+ for imgfile in Dir[imgdir_source + "**/*.*"]
56
+ imgfile_relative_path = File.dirname(imgfile.sub(imgdir_source, ""))
53
57
 
54
58
  # Skip empty stuff
55
- next if imgfile == '.' or imgfile == '..'
56
59
  file_ext = File.extname(imgfile).downcase
57
60
 
58
61
  # If the file is not one of the supported formats, exit early
@@ -63,32 +66,28 @@ module Jekyll
63
66
  # Create the output file path
64
67
  file_noext = File.basename(imgfile, file_ext)
65
68
  outfile_filename = file_noext+ ".webp"
66
- outfile_fullpath_webp = File.join(imgdir_source, outfile_filename)
69
+ FileUtils::mkdir_p(imgdir_destination + imgfile_relative_path)
70
+ outfile_fullpath_webp = File.join(imgdir_destination + imgfile_relative_path, outfile_filename)
67
71
 
68
- # Create the full input file name
69
- infile_fullpath = File.join(imgdir_source, imgfile)
70
-
71
72
  # Check if the file already has a webp alternative?
72
73
  # If we're force rebuilding all webp files then ignore the check
73
74
  # also check the modified time on the files to ensure that the webp file
74
75
  # is newer than the source file, if not then regenerate
75
- next if !@config['regenerate'] && File.file?(outfile_fullpath_webp) &&
76
- File.mtime(outfile_fullpath_webp) > File.mtime(infile_fullpath)
77
-
78
- if( File.file?(outfile_fullpath_webp) &&
79
- File.mtime(outfile_fullpath_webp) <= File.mtime(infile_fullpath) )
76
+ if @config['regenerate'] || !File.file?(outfile_fullpath_webp) ||
77
+ File.mtime(outfile_fullpath_webp) <= File.mtime(imgfile)
80
78
  Jekyll.logger.info "WebP:", "Change to source image file #{imgfile} detected, regenerating WebP"
81
- #puts " WebP: "+File.mtime(outfile_fullpath_webp).strftime('%Y-%m-%d %H:%M:%S')
82
- #puts " Source: "+File.mtime(infile_fullpath).strftime('%Y-%m-%d %H:%M:%S')
83
- end
84
79
 
85
- # Generate the file
86
- WebpExec.run(@config['quality'], infile_fullpath, outfile_fullpath_webp)
87
-
88
- # Keep the webp file from being cleaned by Jekyll
89
- site.static_files << WebpFile.new(site, site.dest, imgdir, outfile_filename)
90
- file_count += 1
91
-
80
+ # Generate the file
81
+ WebpExec.run(@config['quality'], @config['flags'], imgfile, outfile_fullpath_webp)
82
+ file_count += 1
83
+ end
84
+ if File.file?(outfile_fullpath_webp)
85
+ # Keep the webp file from being cleaned by Jekyll
86
+ site.static_files << WebpFile.new(site,
87
+ site.dest,
88
+ File.join(imgdir, imgfile_relative_path),
89
+ outfile_filename)
90
+ end
92
91
  end # dir.foreach
93
92
  end # img_dir
94
93
 
@@ -99,4 +98,4 @@ module Jekyll
99
98
  end #class WebPGenerator
100
99
 
101
100
  end #module Webp
102
- end #module Jekyll
101
+ end #module Jekyll
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-webp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sverrir Sigmundarson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-02 00:00:00.000000000 Z
11
+ date: 2018-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -73,7 +73,9 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: 5.4.3
75
75
  description: WebP Image Generator for Jekyll 3 Sites that automatically generate WebP
76
- images for all images on your static site and serves them when possible.
76
+ images for all images on your static site and serves them when possible. Includes
77
+ the v0.6.1 version of the WebP utilities for Windows, Linux and Mac OS X 10.9 (Mountain
78
+ Lion)
77
79
  email:
78
80
  - jekyll@sverrirs.com
79
81
  executables: