jekyll-brotli 1.0.0 → 2.3.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: dd14849e1f513842567d342b744f99ace866d1dcdaa41a599b24158f0c3fc802
4
- data.tar.gz: e51a6bdc41376a8f74e82bf4375fb34e87a1c46c68e1ba6c9fe21282f9ebb8fd
3
+ metadata.gz: 33b59dc1c8f31a07b8775952290fb96e5685595adf2cd66fd49ace40ef8651f6
4
+ data.tar.gz: 3de63515bffa570a09dc045c9395309f6b38dab6021694aafbdc007599a883a2
5
5
  SHA512:
6
- metadata.gz: cef9b2cb82419a5731176fb20ee9a0a9b653908c798dda732998b8af90598e2e946589a911151487130abe70a28d80abe19b83fa4db3a595d082ceb336d7f3d3
7
- data.tar.gz: 37e61722a6497d82c7c37cd172251331ac308486142f1604e7577f4194e2d8014d681d6991040d9b2053d1c31c029b63f31dcc4582d229e11028f12d2d31181d
6
+ metadata.gz: 61fcaa61cc32ed1fa008ea36752ddb3a0d86be1353e60c79c4812fad81d06d33bda20f57aa4052d37cfcd901ec866af36367ed38fec1af06a284e6bd1e2a87ea
7
+ data.tar.gz: 4c2b873ed1072ab6d2aa693fc1ec7ef77860acc68ca2a985e17407b0e2b72c82b71494b6e0f1702c4d62930b6278e6be29a5196e6522c8c14b8cf3123829b638
@@ -0,0 +1 @@
1
+ github: philnash
@@ -0,0 +1,25 @@
1
+ name: tests
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: [2.5, 2.6, 2.7, 3.0, head]
12
+ jekyll: ["3.0", "4.0"]
13
+ continue-on-error: ${{ endsWith(matrix.ruby, 'head') }}
14
+ env:
15
+ JEKYLL_VERSION: ~> ${{ matrix.jekyll }}
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby ${{ matrix.ruby }}
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - name: "Install dependencies"
23
+ run: bundle install
24
+ - name: Run tests
25
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -7,9 +7,9 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  Gemfile.lock
10
- spec
11
10
 
12
11
  # rspec failure tracking
13
12
  .rspec_status
14
13
 
15
- .sass-cache/
14
+ .sass-cache/
15
+ .jekyll-cache/
data/CHANGELOG.md CHANGED
@@ -1,8 +1,54 @@
1
1
  # Changelog
2
2
 
3
- ## 1.0.0 / 2018-01-03
3
+ ## Ongoing [☰](https://github.com/philnash/jekyll-brotli/compare/v2.3.0...main)
4
+
5
+ ...
6
+
7
+ ## 2.3.0 (2021-02-13) [☰](https://github.com/philnash/jekyll-brotli/compare/v2.2.1...v2.3.0)
8
+
9
+ ### Fixed
10
+
11
+ - Stop overwriting Jekyll config, which invalidates the Jekyll cache (see https://github.com/jekyll/jekyll/issues/8551)
12
+
13
+ ### Changed
14
+
15
+ - Added JSON files to compressable extensions
16
+ - Moved from Travis CI to GitHub Actions
17
+
18
+ ## 2.2.1 (2020-01-30) [☰](https://github.com/philnash/jekyll-brotli/compare/v2.2.0...v2.2.1)
19
+
20
+ ### Changed
21
+
22
+ - Fixes the path handed to `Dir.glob` by using `File.join` instead of string concatenation
23
+
24
+ ## 2.2.0 (2019-12-31) [☰](https://github.com/philnash/jekyll-brotli/compare/v2.1.0...v2.2.0)
25
+
26
+ ### Changed
27
+
28
+ - - Doesn't regenerate files that haven't changed in incremental builds (thanks [@fauno](https://github.com/fauno))
29
+
30
+ ## 2.1.0 (2019-08-26) [☰](https://github.com/philnash/jekyll-brotli/compare/v2.0.0...v2.1.0)
31
+
32
+ ### Changed
33
+
34
+ - Opens up version support for Jekyll 4 (thanks [@thedanbob](https://github.com/thedanbob))
35
+
36
+ ## 2.0.0 (2018-11-24) [☰](https://github.com/philnash/jekyll-brotli/compare/v1.0.0...v2.0.0)
37
+
38
+ ### Added
39
+
40
+ - Adds frozen string literal comments
41
+ - Tries to hook into Jekyll::Assets if available
42
+
43
+ ### Changed
44
+
45
+ - Uses built in `Jekyll.env` instead of `ENV["JEKYLL_ENV"]`
46
+ - Changes `Jekyll::Brotli::Compressor` to a module and implements a `compress_directory` method
47
+ - Moves Jekyll::Brotli::COMPRESSABLE_EXTENSIONS into plugin config that can overwritten in the site config
48
+
49
+ ## 1.0.0 (2018-01-03) [☰](https://github.com/philnash/jekyll-brotli/commits/v1.0.0)
4
50
 
5
51
  ### Added
6
52
 
7
- * Methods to Gzip compress text files throughout a Jekyll site using Brotli
8
- * Site post write hook to trigger compression
53
+ - Methods to Gzip compress text files throughout a Jekyll site using Brotli
54
+ - Site post write hook to trigger compression
data/Gemfile CHANGED
@@ -4,3 +4,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in jekyll-brotli.gemspec
6
6
  gemspec
7
+
8
+ jekyll_version = ENV["JEKYLL_VERSION"] || "~> 4.0"
9
+
10
+ gem "jekyll", jekyll_version
data/README.md CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  Generate compressed assets and files for your Jekyll site at build time using [Brotli](https://github.com/google/brotli) compression.
4
4
 
5
- [![Build Status](https://travis-ci.org/philnash/jekyll-brotli.svg?branch=master)](https://travis-ci.org/philnash/jekyll-brotli)
5
+ [![Gem Version](https://badge.fury.io/rb/jekyll-brotli.svg)](https://rubygems.org/gems/jekyll-brotli) [![Build status](https://github.com/philnash/jekyll-brotli/workflows/tests/badge.svg)](https://github.com/philnash/jekyll-brotli/actions) [![Maintainability](https://api.codeclimate.com/v1/badges/9deb43d992a0c47a55e4/maintainability)](https://codeclimate.com/github/philnash/jekyll-brotli/maintainability) [![Inline docs](https://inch-ci.org/github/philnash/jekyll-brotli.svg?branch=main)](https://inch-ci.org/github/philnash/jekyll-brotli)
6
+
7
+ [API docs](http://www.rubydoc.info/gems/jekyll-brotli/) | [GitHub repo](https://github.com/philnash/jekyll-brotli)
8
+
9
+ ## Why?
6
10
 
7
11
  Performance in web applications is important. You know that, which is why you have created a static site using Jekyll. But you want a bit more performance. You're serving your assets and files gzipped, but could it be better?
8
12
 
@@ -34,6 +38,34 @@ Once you have the gem installed, run `JEKYLL_ENV=production bundle exec jekyll b
34
38
 
35
39
  Jekyll::Brotli only runs when the environment variable `JEKYLL_ENV` is set to `production` as dealing with compressing files is unnecessary in development mode and just slows down the site build.
36
40
 
41
+ ### Configuration
42
+
43
+ #### Extensions
44
+
45
+ By default, `Jekyll::Brotli` will compress all files with the following extensions:
46
+
47
+ - '.html'
48
+ - '.css'
49
+ - '.js'
50
+ - '.json'
51
+ - '.txt'
52
+ - '.ttf'
53
+ - '.atom'
54
+ - '.stl'
55
+ - '.xml'
56
+ - '.svg'
57
+ - '.eot'
58
+
59
+ You can supply your own extensions by adding a `brotli` key to your site's `_config.yml` listing the extensions that you want to compress. For example to only compress HTML, CSS and JavaScript files, add the following to `_config.yml`:
60
+
61
+ ```yml
62
+ brotli:
63
+ extensions:
64
+ - '.html'
65
+ - '.css'
66
+ - '.js
67
+ ```
68
+
37
69
  ### Serving pre-compiled gzip files
38
70
 
39
71
  You will likely need to adjust your web server config to serve these precomputed gzip files. See below for common server configurations:
@@ -64,4 +96,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
64
96
 
65
97
  ## Code of Conduct
66
98
 
67
- Everyone interacting in the Jekyll::Brotli project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/philnash/jekyll-gzip/blob/master/CODE_OF_CONDUCT.md).
99
+ Everyone interacting in the Jekyll::Brotli project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/philnash/jekyll-gzip/blob/main/CODE_OF_CONDUCT.md).
@@ -20,12 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.bindir = "exe"
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
-
24
- spec.add_dependency "jekyll", "~> 3.0"
23
+
24
+ spec.add_dependency "jekyll", ">= 3.0", "< 5.0"
25
25
  spec.add_dependency "brotli", "~> 0.2.0"
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.16"
28
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "bundler", ">= 1.16", "< 3.0"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  spec.add_development_dependency "simplecov", "~> 0.15.1"
31
31
  end
data/lib/jekyll/brotli.rb CHANGED
@@ -1,5 +1,9 @@
1
- require "jekyll/brotli/version"
2
- require "jekyll/brotli/compressor"
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/brotli/version'
4
+ require 'jekyll/brotli/config'
5
+ require 'jekyll/brotli/compressor'
6
+ require 'pathname'
3
7
 
4
8
  module Jekyll
5
9
  module Brotli
@@ -7,7 +11,25 @@ module Jekyll
7
11
  end
8
12
 
9
13
  Jekyll::Hooks.register :site, :post_write do |site|
10
- if ENV["JEKYLL_ENV"] == "production"
11
- Jekyll::Brotli::Compressor.new(site).compress
14
+ Jekyll::Brotli::Compressor.compress_site(site) if Jekyll.env == 'production'
15
+ end
16
+
17
+ Jekyll::Hooks.register :clean, :on_obsolete do |obsolete|
18
+ obsolete.delete_if do |path|
19
+ path.end_with? '.br'
20
+ end
21
+ end
22
+
23
+ begin
24
+ require 'jekyll-assets'
25
+
26
+ Jekyll::Assets::Hook.register :env, :after_write do |env|
27
+ if Jekyll.env == 'production'
28
+ path = Pathname.new("#{env.jekyll.config['destination']}#{env.prefix_url}")
29
+ Jekyll::Brotli::Compressor.compress_directory(path, env.jekyll)
30
+ end
12
31
  end
13
- end
32
+ rescue LoadError
33
+ # The Jekyll site doesn't use Jekyll::Assets, so no need to compress those
34
+ # files.
35
+ end
@@ -1,42 +1,108 @@
1
- require "brotli"
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/brotli/config'
4
+ require 'brotli'
2
5
 
3
6
  module Jekyll
7
+ ##
8
+ # The main namespace for +Jekyll::Brotli+. Includes the +Compressor+ module
9
+ # which is used to map over files, either using an instance of +Jekyll::Site+
10
+ # or a directory path, and compress them using Brotli.
4
11
  module Brotli
5
- class Compressor
6
- COMPRESSABLE_EXTENSIONS = [
7
- '.html',
8
- '.css',
9
- '.js',
10
- '.txt',
11
- '.ttf',
12
- '.atom',
13
- '.stl',
14
- '.xml',
15
- '.svg',
16
- '.eot'
17
- ]
18
-
19
- attr_reader :site
20
-
21
- def initialize(site)
22
- @site = site
12
+ ##
13
+ # The module that does the compressing using Brotli.
14
+ module Compressor
15
+ ##
16
+ # Takes an instance of +Jekyll::Site+ and maps over the site files,
17
+ # compressing them in the destination directory.
18
+ # @example
19
+ # site = Jekyll::Site.new(site_config)
20
+ # Jekyll::Brotli::Compressor.compress_site(site)
21
+ #
22
+ # @param site [Jekyll::Site] A Jekyll::Site object that has generated its
23
+ # site files ready for compression.
24
+ #
25
+ # @return void
26
+ def self.compress_site(site)
27
+ site.each_site_file do |file|
28
+ next unless regenerate? file.destination(site.dest), site
29
+
30
+ compress_file(
31
+ file.destination(site.dest),
32
+ compressable_extensions(site)
33
+ )
34
+ end
35
+ end
36
+
37
+ ##
38
+ # Takes a directory path and maps over the files within compressing them
39
+ # in place.
40
+ #
41
+ # @example
42
+ # Jekyll::Brotli::Compressor.compress_directory("~/blog/_site", site)
43
+ #
44
+ # @param dir [Pathname, String] The path to a directory of files ready for
45
+ # compression.
46
+ # @param site [Jekyll::Site] An instance of the `Jekyll::Site` used for
47
+ # config.
48
+ #
49
+ # @return void
50
+ def self.compress_directory(dir, site)
51
+ extensions = compressable_extensions(site).join(',')
52
+ files = Dir.glob(File.join(dir, "**", "*{#{extensions}}"))
53
+ files.each do |file|
54
+ next unless regenerate? file, site
55
+
56
+ compress_file(file, compressable_extensions(site))
57
+ end
23
58
  end
24
59
 
25
- def compress_file(file_name)
26
- return unless COMPRESSABLE_EXTENSIONS.include?(File.extname(file_name))
27
- compressed = "#{file_name}.br"
60
+ ##
61
+ # Takes a file name and an array of extensions. If the file name extension
62
+ # matches one of the extensions in the array then the file is loaded and
63
+ # compressed using Brotli, outputting the compressed file under the name
64
+ # of the original file with an extra .br extension.
65
+ #
66
+ # @example
67
+ # Jekyll::Brotli::Compressor.compress_file("~/blog/_site/index.html")
68
+ #
69
+ # @param file_name [String] The file name of the file we want to compress
70
+ # @param extensions [Array<String>] The extensions of files that will be
71
+ # compressed.
72
+ #
73
+ # @return void
74
+ def self.compress_file(file_name, extensions)
75
+ return unless extensions.include?(File.extname(file_name))
76
+ compressed = compressed(file_name)
28
77
  contents = ::Brotli.deflate(File.read(file_name), quality: 11)
78
+
79
+ Jekyll.logger.debug "Brotli: #{compressed}"
80
+
29
81
  File.open(compressed, "w+") do |file|
30
82
  file << contents
31
83
  end
32
84
  File.utime(File.atime(file_name), File.mtime(file_name), compressed)
33
85
  end
34
86
 
35
- def compress
36
- site.each_site_file do |file|
37
- compress_file(file.destination(site.dest))
38
- end
87
+ private
88
+
89
+ def self.compressed(file_name)
90
+ "#{file_name}.br"
91
+ end
92
+
93
+ def self.compressable_extensions(site)
94
+ site.config.dig("brotli", "extensions") || Jekyll::Brotli::DEFAULT_CONFIG.fetch("extensions")
95
+ end
96
+
97
+ # Compresses the file if the site is built incrementally and the
98
+ # source was modified or the compressed file doesn't exist
99
+ def self.regenerate?(file, site)
100
+ compressed = compressed(file)
101
+
102
+ return true unless File.exist? compressed
103
+
104
+ File.mtime(file) > File.mtime(compressed)
39
105
  end
40
106
  end
41
107
  end
42
- end
108
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Brotli
5
+ DEFAULT_CONFIG = {
6
+ 'extensions' => [
7
+ '.html',
8
+ '.css',
9
+ '.js',
10
+ '.json',
11
+ '.txt',
12
+ '.ttf',
13
+ '.atom',
14
+ '.stl',
15
+ '.xml',
16
+ '.svg',
17
+ '.eot'
18
+ ].freeze
19
+ }.freeze
20
+ end
21
+ end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Brotli
3
- VERSION = "1.0.0"
5
+ VERSION = "2.3.0"
4
6
  end
5
7
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-brotli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Nash
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2021-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: brotli
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -42,30 +48,36 @@ dependencies:
42
48
  name: bundler
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "~>"
51
+ - - ">="
46
52
  - !ruby/object:Gem::Version
47
53
  version: '1.16'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '3.0'
48
57
  type: :development
49
58
  prerelease: false
50
59
  version_requirements: !ruby/object:Gem::Requirement
51
60
  requirements:
52
- - - "~>"
61
+ - - ">="
53
62
  - !ruby/object:Gem::Version
54
63
  version: '1.16'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.0'
55
67
  - !ruby/object:Gem::Dependency
56
68
  name: rake
57
69
  requirement: !ruby/object:Gem::Requirement
58
70
  requirements:
59
71
  - - "~>"
60
72
  - !ruby/object:Gem::Version
61
- version: '10.0'
73
+ version: '13.0'
62
74
  type: :development
63
75
  prerelease: false
64
76
  version_requirements: !ruby/object:Gem::Requirement
65
77
  requirements:
66
78
  - - "~>"
67
79
  - !ruby/object:Gem::Version
68
- version: '10.0'
80
+ version: '13.0'
69
81
  - !ruby/object:Gem::Dependency
70
82
  name: rspec
71
83
  requirement: !ruby/object:Gem::Requirement
@@ -102,9 +114,10 @@ executables: []
102
114
  extensions: []
103
115
  extra_rdoc_files: []
104
116
  files:
117
+ - ".github/FUNDING.yml"
118
+ - ".github/workflows/tests.yml"
105
119
  - ".gitignore"
106
120
  - ".rspec"
107
- - ".travis.yml"
108
121
  - CHANGELOG.md
109
122
  - CODE_OF_CONDUCT.md
110
123
  - Gemfile
@@ -117,12 +130,13 @@ files:
117
130
  - lib/jekyll-brotli.rb
118
131
  - lib/jekyll/brotli.rb
119
132
  - lib/jekyll/brotli/compressor.rb
133
+ - lib/jekyll/brotli/config.rb
120
134
  - lib/jekyll/brotli/version.rb
121
135
  homepage: https://github.com/philnash/jekyll-brotli
122
136
  licenses:
123
137
  - MIT
124
138
  metadata: {}
125
- post_install_message:
139
+ post_install_message:
126
140
  rdoc_options: []
127
141
  require_paths:
128
142
  - lib
@@ -137,9 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
153
  requirements: []
140
- rubyforge_project:
141
- rubygems_version: 2.7.4
142
- signing_key:
154
+ rubygems_version: 3.1.4
155
+ signing_key:
143
156
  specification_version: 4
144
157
  summary: Generate brotli compressed assets and files for your Jekyll site at build
145
158
  time.
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5
5
- - 2.4
6
- - 2.3
7
- - 2.2
8
- before_install: gem install bundler -v 1.16.1
9
- script: bundle exec rake