jekyll-compress-images 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jekyll-compress-images.rb +48 -0
  3. metadata +74 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4c4cff00fac05c292b8cb7fa380b8b3389a8220dfe6dea65bf5f588bea669990
4
+ data.tar.gz: 1b7a6a147133f6b5cb755ef426cf63d0605adaea81a290d451b9b40bd987c0e3
5
+ SHA512:
6
+ metadata.gz: bcdefbf51e6e8c2dd7d9a0bd28128e2a9a292d11a2d9c8544ad60f6364a8eb36d14d1548038232628d75cfac9379e8962bcad869a4e77fc22b8456d9a5fec35c
7
+ data.tar.gz: eb42577965277ff900b1c551e318feee393dfacd4ce7227809c40b86ccc31b72df45acc477b1bbb2f99e34a7e22e078240e697dde2ea346ff6cc5f5b605dc7f8
@@ -0,0 +1,48 @@
1
+ require "image_optim"
2
+ require "image_optim_pack"
3
+ require 'yaml'
4
+
5
+ module Jekyll
6
+ class CompressImages < Generator
7
+ safe true
8
+
9
+ def generate(site)
10
+
11
+ config = YAML::load_file "_config.yml"
12
+
13
+ config = config["compress_images"] || {}
14
+
15
+ @config = default_options.merge! config
16
+
17
+ @image_optim = ImageOptim.new pngout: false, svgo: false, verbose: false
18
+
19
+ @last_update = YAML::load_file @config["cache_file"] if File.file? @config["cache_file"]
20
+ @last_update ||= {}
21
+
22
+ Dir.glob(@config["images_path"]) { |image| analyze image }
23
+
24
+ File.open(@config["cache_file"], "w") { |file| file.write @last_update.to_yaml }
25
+ end
26
+
27
+ def default_options
28
+ {
29
+ "cache_file" => "_compress_images_cache.yml",
30
+ "images_path" => "assets/img/**/*.{gif,png,jpg,jpeg}",
31
+ }
32
+ end
33
+
34
+ def analyze(image)
35
+ if @last_update.has_key? image
36
+ optimize image if @last_update[image] != File.basename(image)
37
+ else
38
+ optimize image
39
+ end
40
+ end
41
+
42
+ def optimize(image)
43
+ puts "Optimizing #{image}".green
44
+ @image_optim.optimize_image! image
45
+ @last_update[image] = File.basename image
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-compress-images
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Valerija Spasojevic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: image_optim
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: image_optim_pack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 'Plugin for compress/optimize images (jpg, png, gif, svg). If you are
42
+ struggle how to install more information you can find here: https://github.com/valerijaspasojevic/jekyll-compress-images'
43
+ email: spasojevic.valerija@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/jekyll-compress-images.rb
49
+ homepage: https://rubygems.org/gems/example
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ source_code_uri: https://github.com/valerijaspasojevic/jekyll-compress-images
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.7.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Jekyll plugin for compress/optimize images (jpg, png, gif, svg)
74
+ test_files: []