jekyll-zopfli 2.3.0 → 2.4.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
  SHA256:
3
- metadata.gz: ede348b4764fd1471a53a10ecd1d58f21659d79762b760b58effd80aa5a26ab3
4
- data.tar.gz: b7a82496a951c065a587803a44968b871723064971ec6ac8b7298c7b4a81fb9c
3
+ metadata.gz: 598d8766f62cc79eef124048f583dd598d191c57fc3cb37a789a80a3befc082d
4
+ data.tar.gz: 17fcb3e576cfc2293c3061866b5e0f967b9f0b7bd13fdfa6ce6d1ea0bd29791a
5
5
  SHA512:
6
- metadata.gz: 42ab91d962c4ce463d5a269df96945cc5a2e82be848c872fb9fb57d061e4b72633d462b607a239e78e91ccbbdd91894f69ca5df5764f88ecd5a28b2b3695c454
7
- data.tar.gz: e3c70b64606a4095f4b0c5e11098b76f0b37019de30ae8ecf0a99cd2ac011722a4bf7155cd29ef1e0832d325d5e233d418d40269df72ba7e1ccda293e0367ba5
6
+ metadata.gz: e1141cadc3376282a85943ec57ac5b881e8fb46cd7f9728e77db5aa904ff6d83cd463f151bf457562f3e0acbf12671ed51873f25bf801b5ab006f3cf8e28edb8
7
+ data.tar.gz: 51656771722d6a3fc4b6dc582324a4b9dbbe2fe69eceaf017f9dad7a68f750f34f8e82c2121049cf9057998e2ba73fe7d8228e3a547e904a21cea22bef15b8b1
@@ -1,9 +1,15 @@
1
1
  # Changelog
2
2
 
3
- ## Ongoing [☰](https://github.com/philnash/jekyll-gzip/compare/v2.2.0...master)
3
+ ## Ongoing [☰](https://github.com/philnash/jekyll-gzip/compare/v2.4.0...master)
4
4
 
5
5
  ...
6
6
 
7
+ ## 2.4.0 (2019-12-31) [☰](https://github.com/philnash/jekyll-zopfli/compare/v2.3.0...v2.4.0)
8
+
9
+ ### Changed
10
+
11
+ - Doesn't regenerate files that haven't changed in incremental builds.
12
+
7
13
  ## 2.3.0 (2019-10-23) [☰](https://github.com/philnash/jekyll-zopfli/compare/v2.2.0...v2.3.0)
8
14
 
9
15
  ### Changed
@@ -25,7 +25,13 @@ module Jekyll
25
25
  # @return void
26
26
  def self.compress_site(site)
27
27
  site.each_site_file do |file|
28
- compress_file(file.destination(site.dest), extensions: zippable_extensions(site), replace_file: replace_files(site))
28
+ next unless regenerate? file.destination(site.dest), site
29
+
30
+ compress_file(
31
+ file.destination(site.dest),
32
+ extensions: zippable_extensions(site),
33
+ replace_file: replace_files(site)
34
+ )
29
35
  end
30
36
  end
31
37
 
@@ -45,7 +51,15 @@ module Jekyll
45
51
  def self.compress_directory(dir, site)
46
52
  extensions = zippable_extensions(site).join(',')
47
53
  files = Dir.glob(dir + "/**/*{#{extensions}}")
48
- files.each { |file| compress_file(file, extensions: zippable_extensions(site), replace_file: replace_files(site)) }
54
+ files.each do |file|
55
+ next unless regenerate? file, site
56
+
57
+ compress_file(
58
+ file,
59
+ extensions: zippable_extensions(site),
60
+ replace_file: replace_files(site)
61
+ )
62
+ end
49
63
  end
50
64
 
51
65
  ##
@@ -67,7 +81,7 @@ module Jekyll
67
81
  def self.compress_file(file_name, extensions: [], replace_file: false)
68
82
  return unless extensions.include?(File.extname(file_name))
69
83
  zipped = replace_file ? file_name : "#{file_name}.gz"
70
- contents = ::Zopfli.deflate(File.read(file_name), format: :gzip)
84
+ contents = ::Zopfli.deflate(File.binread(file_name), format: :gzip)
71
85
  File.open(zipped, "w+") do |file|
72
86
  file << contents
73
87
  end
@@ -84,6 +98,32 @@ module Jekyll
84
98
  replace_files = site.config.dig('zopfli', 'replace_files')
85
99
  replace_files.nil? ? Jekyll::Zopfli::DEFAULT_CONFIG['replace_files'] : replace_files
86
100
  end
101
+
102
+ def self.zipped(file_name, replace_file)
103
+ replace_file ? file_name : "#{file_name}.gz"
104
+ end
105
+
106
+ # Compresses the file if the site is built incrementally and the
107
+ # source was modified or the compressed file doesn't exist
108
+ def self.regenerate?(file, site)
109
+ zipped = zipped(file, replace_files(site))
110
+
111
+ # Definitely generate the file if it doesn't exist yet.
112
+ return true unless File.exist? zipped
113
+ # If we are replacing files and this file is not a gzip file, then it
114
+ # has been edited so we need to re-gzip it in place.
115
+ return !is_already_gzipped?(file) if replace_files(site)
116
+
117
+ # If the modified time of the new file is greater than the modified time
118
+ # of the old file, then we need to regenerate.
119
+ File.mtime(file) > File.mtime(zipped)
120
+ end
121
+
122
+ # First two bytes of a gzipped file are 1f and 8b. This tests for those
123
+ # bytes.
124
+ def self.is_already_gzipped?(file)
125
+ ["1f", "8b"] == File.read(file, 2).unpack("H2H2")
126
+ end
87
127
  end
88
128
  end
89
129
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Zopfli
5
- VERSION = "2.3.0"
5
+ VERSION = "2.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-zopfli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Nash
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2019-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.0.3
153
+ rubygems_version: 3.0.1
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Generate gzipped assets and files for your Jekyll site at build time using