jekyll-simple-assets 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/jekyll-simple-assets.gemspec +1 -0
- data/lib/jekyll-simple-assets.rb +8 -1
- data/lib/jekyll-simple-assets/critical.rb +17 -9
- data/lib/jekyll-simple-assets/uglify.rb +105 -0
- data/lib/jekyll-simple-assets/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33de2b5bfcba3d41e98a6b9563c8991bc91a84b29b3bccfde8db15fce364a73b
|
4
|
+
data.tar.gz: 955d21f9c5f563afa9fe1ac125844fc3ade01f4bf8ed3314963402b2f7eb10c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45cd69ba7ef27c6660e6e6b4b46d148e6b19f0f7d3f0ee5b0cbfec6bba6e90a39b36c932cda1d668c03881e0a200adbf701cbb6e4cacec4332c96a173479b516
|
7
|
+
data.tar.gz: 8c6905fd79f86ce0fed4828bc9258f0952992a316a88ae5364b636a0dcf841515be2edf3d9d6816c94e69cdda52c66e001dd0491cea2973874709f10f11000c5
|
data/README.md
CHANGED
@@ -109,6 +109,14 @@ esbuild_flags: --target=es5 # pass any flags to esbuild for this file
|
|
109
109
|
To bundle javascript [esbuild](https://github.com/evanw/esbuild) must be
|
110
110
|
installed.
|
111
111
|
|
112
|
+
## Javascript minification
|
113
|
+
|
114
|
+
The uglifier package is also included and will minify files if `uglifier_enabled`
|
115
|
+
is set to true in config.yml, or if JEKYLL_ENV is set to production. Any
|
116
|
+
options can be passed to uglifier under the `uglifer` key in config.yml
|
117
|
+
(see configuration for example). Additionally you can set uglifier settings in
|
118
|
+
the liquid frontmatter of a js file in the same manner as in config.yml.
|
119
|
+
|
112
120
|
## Configuration
|
113
121
|
|
114
122
|
```
|
@@ -145,4 +153,11 @@ simple_assets:
|
|
145
153
|
# Options for bundling javascript/typescript with the `esbuild` npm module
|
146
154
|
# Set to true to enable
|
147
155
|
bundle: true
|
156
|
+
|
157
|
+
# Options for javascript minification with uglifier
|
158
|
+
uglifier:
|
159
|
+
# any options for uglifier can be put here and will be passed to it
|
160
|
+
harmony: true
|
161
|
+
output:
|
162
|
+
ascii_only: true
|
148
163
|
```
|
data/lib/jekyll-simple-assets.rb
CHANGED
@@ -8,11 +8,14 @@ require 'shellwords'
|
|
8
8
|
require 'jekyll-simple-assets/content-hash'
|
9
9
|
require 'jekyll-simple-assets/critical'
|
10
10
|
require 'jekyll-simple-assets/esbuild'
|
11
|
+
require 'jekyll-simple-assets/uglify'
|
11
12
|
|
12
13
|
module Jekyll
|
13
14
|
module SimpleAssets
|
14
15
|
def self.site (site = nil)
|
15
|
-
@@site
|
16
|
+
@@site = site if site
|
17
|
+
|
18
|
+
@@site
|
16
19
|
end
|
17
20
|
|
18
21
|
def self.config
|
@@ -35,6 +38,10 @@ module Jekyll
|
|
35
38
|
@@esbuild_config_file ||= file
|
36
39
|
end
|
37
40
|
|
41
|
+
def self.uglifier_enabled?
|
42
|
+
config['uglifier_enabled'] || ENV['JEKYLL_ENV'] == 'production'
|
43
|
+
end
|
44
|
+
|
38
45
|
module SimpleAssetsFilters
|
39
46
|
def md5 (input)
|
40
47
|
Digest::MD5.hexdigest(input)
|
@@ -7,19 +7,21 @@ module Jekyll
|
|
7
7
|
module SimpleAssets
|
8
8
|
|
9
9
|
|
10
|
-
def self.critical_css_source_files
|
11
|
-
@@critical_css_source_files ||=
|
10
|
+
def self.critical_css_source_files ()
|
11
|
+
@@critical_css_source_files ||= {}
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.make_temp_css_files_for_critical (asset)
|
15
15
|
SimpleAssets::config['critical_css']['css_files'].each do |path|
|
16
16
|
next unless asset.path == path || asset.path == path.sub(/\.css$/, '.scss')
|
17
17
|
|
18
|
-
f = Tempfile.new('css-source')
|
18
|
+
f = Tempfile.new([ 'css-source', '.css' ])
|
19
19
|
f.write asset.output
|
20
20
|
f.close
|
21
21
|
|
22
|
-
SimpleAssets
|
22
|
+
Jekyll.logger.debug("SimpleAssets:", "Created new temp file for css: #{ asset.path } at: #{ f.path }")
|
23
|
+
|
24
|
+
SimpleAssets::critical_css_source_files[path] = { 'file' => f, 'page' => asset }
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -40,7 +42,7 @@ end
|
|
40
42
|
def self.generate_critical_css (site)
|
41
43
|
css_files_str = ''
|
42
44
|
|
43
|
-
SimpleAssets::critical_css_source_files.each do |f|
|
45
|
+
SimpleAssets::critical_css_source_files.each do |_, f|
|
44
46
|
css_files_str += "--css #{ f['file'].path } "
|
45
47
|
|
46
48
|
f['css'] = CssParser::Parser.new
|
@@ -91,7 +93,7 @@ def self.generate_critical_css (site)
|
|
91
93
|
|
92
94
|
critical_css.load_string! critical_css_str
|
93
95
|
|
94
|
-
SimpleAssets::critical_css_source_files.each do |f|
|
96
|
+
SimpleAssets::critical_css_source_files.each do |_, f|
|
95
97
|
f['css'].each_rule_set do |source_rule_set, source_media_type|
|
96
98
|
critical_css.each_rule_set do |critical_rule_set, critical_media_type|
|
97
99
|
if critical_rule_set.selectors.join(',') == source_rule_set.selectors.join(',')
|
@@ -107,13 +109,19 @@ def self.generate_critical_css (site)
|
|
107
109
|
end
|
108
110
|
end
|
109
111
|
|
110
|
-
SimpleAssets::critical_css_source_files.each do |f|
|
111
|
-
|
112
|
+
SimpleAssets::critical_css_source_files.each do |_, f|
|
113
|
+
leftover_css = f['css'].to_s if f['extract']
|
114
|
+
|
115
|
+
# css_parser leaves blank keyframes so fix them
|
116
|
+
keyframes = f['page'].output.scan(/@keyframes\s+(?:.*?)\s*{(?:\s*\S*?\s*{.*?}\s*)+}/m)
|
117
|
+
keyframes.each { |keyframe| leftover_css += keyframe }
|
118
|
+
|
119
|
+
f['page'].output
|
112
120
|
end
|
113
121
|
end
|
114
122
|
|
115
123
|
def self.resolve_critical_css_content_hashes (site)
|
116
|
-
SimpleAssets::critical_css_source_files.each do |source_file|
|
124
|
+
SimpleAssets::critical_css_source_files.each do |_, source_file|
|
117
125
|
page = source_file['page']
|
118
126
|
page_path = page.path.sub("#{ site.config['source'] }/", '')
|
119
127
|
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'uglifier'
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
|
5
|
+
module SimpleAssets
|
6
|
+
def self.symbolize_keys (hash)
|
7
|
+
return {} if hash.nil?
|
8
|
+
|
9
|
+
hash.inject({}) do |result, (key, value)|
|
10
|
+
|
11
|
+
new_key = case key
|
12
|
+
when String then key.to_sym
|
13
|
+
else key
|
14
|
+
end
|
15
|
+
new_value = case value
|
16
|
+
when Hash then symbolize_keys(value)
|
17
|
+
else value
|
18
|
+
end
|
19
|
+
|
20
|
+
if new_value.is_a?(String) and new_value.match(/^\/.*\/$/)
|
21
|
+
new_value = /#{ Regexp.quote(new_value[1..-2]) }/
|
22
|
+
end
|
23
|
+
|
24
|
+
result[new_key] = new_value
|
25
|
+
|
26
|
+
result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module UglifyFilter
|
31
|
+
def uglify (input)
|
32
|
+
return if input.nil?
|
33
|
+
|
34
|
+
return input.split('\n').join('\\\n') unless SimpleAssets::uglifier_enabled?
|
35
|
+
|
36
|
+
config = @context.registers[:site].config['simple_assets']
|
37
|
+
|
38
|
+
uglifier_config = SimpleAssets::symbolize_keys(config['uglifier'])
|
39
|
+
|
40
|
+
Uglifier.new(uglifier_config).compile input
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Converters
|
46
|
+
|
47
|
+
class SimpleAssetsUglify < Converter
|
48
|
+
safe true
|
49
|
+
priority :lowest
|
50
|
+
|
51
|
+
def initialize (config={})
|
52
|
+
super(config)
|
53
|
+
|
54
|
+
@config = SimpleAssets::symbolize_keys(config['simple_assets']['uglifier'])
|
55
|
+
|
56
|
+
Jekyll::Hooks.register :pages, :pre_render do |page|
|
57
|
+
ext = '.' + page.path.split('.').last
|
58
|
+
|
59
|
+
if matches(ext)
|
60
|
+
@meta = SimpleAssets::symbolize_keys(page.data['uglifier'])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Jekyll::Hooks.register :pages, :post_render do |page|
|
65
|
+
ext = '.' + page.path.split('.').last
|
66
|
+
|
67
|
+
if matches(ext)
|
68
|
+
@meta = nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def merge_recursively(a, b)
|
74
|
+
a.merge(b) {|key, a_item, b_item| merge_recursively(a_item, b_item) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_config ()
|
78
|
+
merge_recursively(@config || {}, @meta || {})
|
79
|
+
end
|
80
|
+
|
81
|
+
def matches (ext)
|
82
|
+
return nil unless ext
|
83
|
+
|
84
|
+
ext.downcase == '.js'
|
85
|
+
end
|
86
|
+
|
87
|
+
def output_ext (ext)
|
88
|
+
'.js'
|
89
|
+
end
|
90
|
+
|
91
|
+
def convert (content)
|
92
|
+
return content unless SimpleAssets::uglifier_enabled?
|
93
|
+
|
94
|
+
config = get_config
|
95
|
+
|
96
|
+
return content if config[:do_not_compress] == true
|
97
|
+
|
98
|
+
Uglifier.new(config).compile content
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
Liquid::Template.register_filter(Jekyll::SimpleAssets::UglifyFilter)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-simple-assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sophie Askew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: uglifier
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,6 +83,7 @@ files:
|
|
69
83
|
- lib/jekyll-simple-assets/content-hash.rb
|
70
84
|
- lib/jekyll-simple-assets/critical.rb
|
71
85
|
- lib/jekyll-simple-assets/esbuild.rb
|
86
|
+
- lib/jekyll-simple-assets/uglify.rb
|
72
87
|
- lib/jekyll-simple-assets/version.rb
|
73
88
|
homepage: https://github.com/syldexiahime/jekyll-simple-assets
|
74
89
|
licenses:
|