jekyll-srcset 0.0.2 → 0.1.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: ae4b06042ffab7e4ffeb4848224eae527a0a5a47
4
- data.tar.gz: ec04ef409edcd2377d8363b22ef77cef32ee1d59
3
+ metadata.gz: 74e4d89dfd0daf04636020c81d779621b0dd6805
4
+ data.tar.gz: 836bc3fe5b51204eec502cc53902d2ff5d3aeb5d
5
5
  SHA512:
6
- metadata.gz: bbec4494a16ffbdd9761b7f4b8f7ed93e73ca1bce9db2766cfa8a27cae54f71deb8727d97796f8ed3bbb4ba0734c6a9297a240ffa78cf862d9838db5d99076f4
7
- data.tar.gz: cf0062c05384140e9b36f79c31dbfbd6be1f3d775851a88e687ec04eea7399287ad575d23a38aebaf9e9b722dd98b6da070ac6bb6ecd88c39db10857cf0eb9b7
6
+ metadata.gz: 50b14dec5105e4ac4646e469408f177a34d34536333b706340450d13f56069ba829fbc277f5cedd78c73d20a2607343bc2cf9603cc8de509a43b95f58377a992
7
+ data.tar.gz: ca2679922586949b654d1292e2b0bf1634a82460fef76f5bc82381abd94624303b832dfbddb524b7db87d429abf8865c6167a03c51e33ec79a66e550361a21ae
data/README.md CHANGED
@@ -59,10 +59,28 @@ To use variables for the image or the dimensions, simply leave out the quotes:
59
59
 
60
60
  ## Optipng
61
61
 
62
- If you have `optipng` installed and in your PATH, the plugin wil automatically run it on all generated png images.
62
+ If you have `optipng` installed and in your PATH, you can tell the plugin to run it on all generated png images.
63
+
64
+ Just add:
65
+
66
+ ```
67
+ srcset:
68
+ optipng: true
69
+ ```
70
+
71
+ To your \_config.yml
63
72
 
64
73
  Currently the plugin doesn't optimize other image formats, except for stripping color palettes.
65
74
 
75
+ ## Caching images
76
+
77
+ Optimizing and resizing can take a while for some images. You can specify a cache folder in your Jekyll config to let jekyll-srcset cache images between runs.
78
+
79
+ ```
80
+ srcset:
81
+ cache: "/tmp/images"
82
+ ```
83
+
66
84
  ## Contributing
67
85
 
68
86
  1. Fork it ( https://github.com/[my-github-username]/jekyll-srcset/fork )
@@ -70,3 +88,9 @@ Currently the plugin doesn't optimize other image formats, except for stripping
70
88
  3. Commit your changes (`git commit -am 'Add some feature'`)
71
89
  4. Push to the branch (`git push origin my-new-feature`)
72
90
  5. Create a new Pull Request
91
+
92
+ ## Host your Jekyll sites with netlify
93
+
94
+ This plugin is developed by netlify, [the premium hosting for static websites](https://www.netlify.com).
95
+
96
+ You can use netlify if you're using custom plugins with your Jekyll sites. When you push to git, netlify will build your Jekyll site and deploy the result to a global CDN, while handling asset fingerprinting, caching headers, bundling, minification and true instant cache invalidation. A 1-click operation with no other setup needed.
@@ -1,4 +1,5 @@
1
1
  require "RMagick"
2
+ require "digest/sha1"
2
3
 
3
4
  module Jekyll
4
5
  class SrcsetTag < Liquid::Tag
@@ -44,7 +45,31 @@ module Jekyll
44
45
  options
45
46
  end
46
47
 
48
+ def config(site)
49
+ site.config['srcset'] || {}
50
+ end
51
+
52
+ def optimize?(site)
53
+ config(site)['optipng']
54
+ end
55
+
56
+ def cache_dir(site)
57
+ config(site)['cache']
58
+ end
59
+
47
60
  def generate_image(site, src, attrs)
61
+ cache = cache_dir(site)
62
+ sha = cache && Digest::SHA1.hexdigest(attrs.sort.inspect + File.read(File.join(site.source, src)) + (optimize?(site) ? "optimize" : ""))
63
+ if sha
64
+ if File.exists?(File.join(cache, sha))
65
+ img_attrs = JSON.parse(File.read(File.join(cache,sha,"json")))
66
+ filename = img_attrs["src"].sub(/^\//, '')
67
+ dest = File.join(site.dest, filename)
68
+ FileUtils.cp(File.join(cache,sha,"img"), dest)
69
+ return img_attrs
70
+ end
71
+ end
72
+
48
73
  img = Image.read(File.join(site.source, src)).first
49
74
  img_attrs = {}
50
75
 
@@ -56,22 +81,33 @@ module Jekyll
56
81
  scale = attrs["factor"] || 1
57
82
  end
58
83
 
59
- img.scale!(scale) if scale <= 1
60
84
  img_attrs["height"] = attrs["height"] if attrs["height"]
61
85
  img_attrs["width"] = attrs["width"] if attrs["width"]
62
-
63
86
  img_attrs["src"] = src.sub(/(\.\w+)$/, "-#{img.columns}x#{img.rows}" + '\1')
87
+
64
88
  filename = img_attrs["src"].sub(/^\//, '')
65
89
  dest = File.join(site.dest, filename)
66
90
  FileUtils.mkdir_p(File.dirname(dest))
91
+
67
92
  unless File.exist?(dest)
93
+ puts "Resizing image #{dest}"
94
+ img.scale!(scale) if scale <= 1
68
95
  img.strip!
69
96
  img.write(dest)
70
- if dest.match(/\.png$/) && self.class.optipng?
97
+ if dest.match(/\.png$/) && optimize?(site) && self.class.optipng?
71
98
  `optipng #{dest}`
72
99
  end
73
100
  end
74
101
  site.config['keep_files'] << filename unless site.config['keep_files'].include?(filename)
102
+
103
+ if sha
104
+ FileUtils.mkdir_p(File.join(cache, sha))
105
+ FileUtils.cp(dest, File.join(cache, sha, "img"))
106
+ File.open(File.join(cache, sha, "json"), "w") do |f|
107
+ f.write(JSON.generate(img_attrs))
108
+ end
109
+ end
110
+
75
111
  img_attrs
76
112
  end
77
113
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Srcset
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-srcset
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Biilmann Christensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-19 00:00:00.000000000 Z
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -114,4 +114,3 @@ signing_key:
114
114
  specification_version: 4
115
115
  summary: This Jekyll plugin ads an image_tag that will generate responsive img tags
116
116
  test_files: []
117
- has_rdoc: