jekyll-simple-assets 0.1.0 → 0.2.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 +23 -3
- data/lib/jekyll-simple-assets.rb +58 -35
- data/lib/jekyll-simple-assets/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbe1fbd068c7784ca4ed4d4ea3777ef10c45a6ed3b960d9fcfdcb843bdff8a1d
|
4
|
+
data.tar.gz: 44b828531c73f697e539740ee38389626d8aa7560316c2fdff63c663b3a26592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7749e0e9835f7891e154438f8dddff62be167d2d1ac1102a6c1c999485f653a1b4b7ef057b7983bd630605306d75245c66e9f0b7667b19be178d09079c353c29
|
7
|
+
data.tar.gz: 447cfa3bb7e120ae5c9626e25124202932c6e7c66e8fbeb948d2ab749225850391a346aeb25919e69fd702fbc250f1c06548fc2292e2937f28d3170bd6aadcac
|
data/README.md
CHANGED
@@ -12,11 +12,11 @@ webpack.
|
|
12
12
|
|
13
13
|
#### contenthash
|
14
14
|
|
15
|
-
Returns
|
15
|
+
Returns a base64 encoded md5 hash based on the contents of the path given.
|
16
16
|
|
17
17
|
```liquid
|
18
18
|
{% contenthash assets/js/app.js %}
|
19
|
-
//
|
19
|
+
// Mpz5BzLfDInvj7C36UFv4w==
|
20
20
|
```
|
21
21
|
|
22
22
|
#### asset
|
@@ -26,7 +26,7 @@ the file as a query string.
|
|
26
26
|
|
27
27
|
```liquid
|
28
28
|
{% asset assets/js/app.js %}
|
29
|
-
// /assets/js/app.js?v=
|
29
|
+
// /assets/js/app.js?v=Mpz5BzLfDInvj7C36UFv4w==
|
30
30
|
```
|
31
31
|
|
32
32
|
#### bundle
|
@@ -64,3 +64,23 @@ How the content hashes work is by generating a placeholder string that is
|
|
64
64
|
passed to the template. Once all of the sites files and pages have been
|
65
65
|
processed and copied over, the content hashes are worked out, and the
|
66
66
|
placeholder string in the pages output is replaced with the hash.
|
67
|
+
|
68
|
+
Because of this you need to be careful with using capture tags around or trying
|
69
|
+
to manipulate the output of the contenthash or asset tags.
|
70
|
+
|
71
|
+
By default the generation of content hashes is only enabled for production
|
72
|
+
builds (if JEKYLL_ENV is set to 'production').
|
73
|
+
|
74
|
+
## Configuration
|
75
|
+
|
76
|
+
```
|
77
|
+
simple_assets:
|
78
|
+
# If set to true generation of content hashes will be enabled, even in a non
|
79
|
+
# production build.
|
80
|
+
# default: false
|
81
|
+
hashing_enabled: true
|
82
|
+
|
83
|
+
# The length of the content hashes generated.
|
84
|
+
# default: 16
|
85
|
+
hash_length: 8
|
86
|
+
```
|
data/lib/jekyll-simple-assets.rb
CHANGED
@@ -5,6 +5,22 @@ require 'pathname'
|
|
5
5
|
|
6
6
|
module Jekyll
|
7
7
|
module SimpleAssets
|
8
|
+
def self.site (site)
|
9
|
+
@@site ||= site
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
@@config ||= @@site.config['simple_assets']
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.hash_length
|
17
|
+
config['hash_length'] || 16
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.hashing_enabled?
|
21
|
+
config['hashing_enabled'] || ENV['JEKYLL_ENV'] == 'production'
|
22
|
+
end
|
23
|
+
|
8
24
|
module SimpleAssetsFilters
|
9
25
|
def md5 (input)
|
10
26
|
Digest::MD5.hexdigest(input)
|
@@ -13,13 +29,13 @@ module Jekyll
|
|
13
29
|
|
14
30
|
class BundleTag < Jekyll::Tags::IncludeTag
|
15
31
|
def tag_includes_dirs(context)
|
16
|
-
[ "_js", "_assets" ].freeze
|
32
|
+
[ "_js", "_javascript", "_assets" ].freeze
|
17
33
|
end
|
18
34
|
end
|
19
35
|
|
20
36
|
class BundleRawTag < Jekyll::Tags::IncludeTag
|
21
37
|
def tag_includes_dirs(context)
|
22
|
-
[ "_js", "_assets" ].freeze
|
38
|
+
[ "_js", "_javascript", "_assets" ].freeze
|
23
39
|
end
|
24
40
|
|
25
41
|
def render(context)
|
@@ -35,9 +51,7 @@ module Jekyll
|
|
35
51
|
|
36
52
|
return unless File.file? path
|
37
53
|
|
38
|
-
|
39
|
-
content = File.read path
|
40
|
-
end
|
54
|
+
content = File.read path
|
41
55
|
|
42
56
|
content
|
43
57
|
end
|
@@ -56,11 +70,11 @@ module Jekyll
|
|
56
70
|
end
|
57
71
|
|
58
72
|
def self.get_placeholder (asset_path)
|
59
|
-
asset_placeholder_map[asset_path] ||= Digest::MD5.
|
73
|
+
asset_placeholder_map[asset_path] ||= Digest::MD5.base64digest(asset_path)
|
60
74
|
end
|
61
75
|
|
62
|
-
def self.relative_url (
|
63
|
-
"#{ site.config['baseurl'] }/#{ path }".gsub(%r{/{2,}}, '/')
|
76
|
+
def self.relative_url (path)
|
77
|
+
"#{ @@site.config['baseurl'] || '' }/#{ path }".gsub(%r{/{2,}}, '/')
|
64
78
|
end
|
65
79
|
|
66
80
|
class AssetTag < Liquid::Tag
|
@@ -91,7 +105,8 @@ module Jekyll
|
|
91
105
|
end
|
92
106
|
|
93
107
|
def render (context)
|
94
|
-
site = context.registers[:site]
|
108
|
+
site = SimpleAssets::site(context.registers[:site])
|
109
|
+
|
95
110
|
page = context.environments.first['page']
|
96
111
|
|
97
112
|
args = Shellwords.split(@text)
|
@@ -100,18 +115,24 @@ module Jekyll
|
|
100
115
|
|
101
116
|
asset_path = get_value(context, args[0]).sub(/^\//, '')
|
102
117
|
|
103
|
-
if
|
118
|
+
if SimpleAssets::hashing_enabled?
|
104
119
|
SimpleAssets::page_assets_map[page_path] ||= {}
|
105
120
|
SimpleAssets::page_assets_map[page_path][asset_path] ||= {}
|
106
121
|
SimpleAssets::page_assets_map[page_path][asset_path][@type] ||= []
|
107
122
|
|
108
123
|
placeholder = SimpleAssets::get_placeholder(asset_path)
|
109
124
|
|
110
|
-
SimpleAssets::page_assets_map[page_path][asset_path][@type]
|
125
|
+
unless SimpleAssets::page_assets_map[page_path][asset_path][@type].include? placeholder
|
126
|
+
SimpleAssets::page_assets_map[page_path][asset_path][@type] << placeholder
|
127
|
+
end
|
111
128
|
|
112
129
|
"#{ @type }::#{ placeholder }"
|
113
130
|
else
|
114
|
-
|
131
|
+
if @type == 'path'
|
132
|
+
SimpleAssets::relative_url(asset_path)
|
133
|
+
else
|
134
|
+
placeholder[0, SimpleAssets::hash_length]
|
135
|
+
end
|
115
136
|
end
|
116
137
|
end
|
117
138
|
end
|
@@ -161,7 +182,11 @@ module Jekyll
|
|
161
182
|
Jekyll.logger.warn "SimpleAssets", "#{ asset_path } has no content"
|
162
183
|
end
|
163
184
|
|
164
|
-
|
185
|
+
base64hash = Digest::MD5.base64digest(content)
|
186
|
+
|
187
|
+
hash = base64hash[0, SimpleAssets::hash_length]
|
188
|
+
|
189
|
+
SimpleAssets::asset_contenthash_map[asset_path] = hash
|
165
190
|
end
|
166
191
|
|
167
192
|
def self.replace_placeholders_for_asset (doc, site)
|
@@ -181,16 +206,12 @@ module Jekyll
|
|
181
206
|
if type == 'path'
|
182
207
|
replacement = "#{ asset_path }?v=#{ replacement }"
|
183
208
|
|
184
|
-
replacement = SimpleAssets::relative_url(
|
209
|
+
replacement = SimpleAssets::relative_url(replacement)
|
185
210
|
end
|
186
211
|
|
187
212
|
placeholder = "#{ type }::#{ SimpleAssets::asset_placeholder_map[asset_path] }"
|
188
213
|
|
189
|
-
|
190
|
-
doc.output = doc.output.gsub(placeholder, replacement)
|
191
|
-
else
|
192
|
-
doc.output = doc.output.sub(placeholder, replacement)
|
193
|
-
end
|
214
|
+
doc.output = doc.output.gsub(placeholder, replacement)
|
194
215
|
end
|
195
216
|
end
|
196
217
|
end
|
@@ -205,27 +226,29 @@ Liquid::Template.register_tag('bundle_raw', Jekyll::SimpleAssets::BundleRawTag)
|
|
205
226
|
|
206
227
|
Liquid::Template.register_filter(Jekyll::SimpleAssets::SimpleAssetsFilters)
|
207
228
|
|
208
|
-
|
209
|
-
Jekyll::
|
210
|
-
potential_assets = []
|
229
|
+
Jekyll::Hooks.register :site, :post_render do |site, payload|
|
230
|
+
Jekyll::SimpleAssets::site(site)
|
211
231
|
|
212
|
-
|
213
|
-
potential_assets += site.static_files
|
232
|
+
return unless Jekyll::SimpleAssets::hashing_enabled?
|
214
233
|
|
215
|
-
|
216
|
-
Jekyll::SimpleAssets::resolve_asset_content_hashes(asset, site)
|
217
|
-
end
|
234
|
+
potential_assets = []
|
218
235
|
|
219
|
-
|
236
|
+
potential_assets += site.pages
|
237
|
+
potential_assets += site.static_files
|
220
238
|
|
221
|
-
|
222
|
-
|
223
|
-
|
239
|
+
potential_assets.each do |asset|
|
240
|
+
Jekyll::SimpleAssets::resolve_asset_content_hashes(asset, site)
|
241
|
+
end
|
224
242
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
243
|
+
docs = []
|
244
|
+
|
245
|
+
site.pages.each do |doc|
|
246
|
+
Jekyll::SimpleAssets::replace_placeholders_for_asset(doc, site)
|
247
|
+
end
|
248
|
+
|
249
|
+
site.collections.each do |collection_name, collection|
|
250
|
+
collection.docs.each do |doc|
|
251
|
+
Jekyll::SimpleAssets::replace_placeholders_for_asset(doc, site)
|
229
252
|
end
|
230
253
|
end
|
231
254
|
end
|
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.2.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-05-
|
11
|
+
date: 2020-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|