hyde-page-js 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hyde-page-js.rb +15 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17a523c022d3eb4883130d9b143285e028f4f83fcfe3011f614ab0ec25a05aef
|
4
|
+
data.tar.gz: b9b674f5042f528004838ab8e73a6f8840e70ae0bdb675f7991de420d715ff6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e5799de5113ea965a1d638bf7a69eba7946fc7133d5f5d8cf4d37a13090902d7b97a703f226c749c2c44f3bb78f578cc1a514c8e11d31ceecf2dabc08bd041f
|
7
|
+
data.tar.gz: 203b8c566d58cebc526c8627425d6638b722003a4022b3af4d91126f64eba90696d289e808d3913fd7212f5fdb9e4c285a20131b2b313cb5166e8d2b12b4b7a1
|
data/lib/hyde-page-js.rb
CHANGED
@@ -9,7 +9,7 @@ end
|
|
9
9
|
module Hyde
|
10
10
|
module Page
|
11
11
|
class Js
|
12
|
-
VERSION = "0.
|
12
|
+
VERSION = "0.3.0"
|
13
13
|
end
|
14
14
|
|
15
15
|
class GeneratedJsFile < Jekyll::StaticFile
|
@@ -55,6 +55,7 @@ module Hyde
|
|
55
55
|
@page = page
|
56
56
|
@site = page.site
|
57
57
|
@config = fetch_config
|
58
|
+
@site.data['_hyde_pages_cache'] ||= {}
|
58
59
|
|
59
60
|
if keep_files? && !dev_mode?
|
60
61
|
@site.config.fetch("keep_files").push(destination)
|
@@ -65,6 +66,10 @@ module Hyde
|
|
65
66
|
js = fetch_js(@page)
|
66
67
|
layout = fetch_layout(fetch_layout_name(@page))
|
67
68
|
results = parent_layout_js(layout, js).reverse
|
69
|
+
return if results.empty?
|
70
|
+
|
71
|
+
lookup_name = names_to_key(results)
|
72
|
+
return unless @site.data['_hyde_pages_cache'].fetch(lookup_name, nil).nil?
|
68
73
|
|
69
74
|
data = concatenate_files(results)
|
70
75
|
return if data == ""
|
@@ -85,10 +90,17 @@ module Hyde
|
|
85
90
|
|
86
91
|
# assign to site.data.js_files for liquid output
|
87
92
|
add_to_urls(generated_file.url)
|
93
|
+
|
94
|
+
# add to cache
|
95
|
+
@site.data['_hyde_pages_cache'][lookup_name] = data
|
88
96
|
end
|
89
97
|
|
90
98
|
private
|
91
99
|
|
100
|
+
def names_to_key(names)
|
101
|
+
names.join('-')
|
102
|
+
end
|
103
|
+
|
92
104
|
def add_to_urls(url)
|
93
105
|
@site.data['js_files'] ||= []
|
94
106
|
@site.data['js_files'].push(url)
|
@@ -172,6 +184,8 @@ module Hyde
|
|
172
184
|
end
|
173
185
|
|
174
186
|
def minify(data)
|
187
|
+
return data unless minify?
|
188
|
+
|
175
189
|
converter_config = {mangle: mangle?, output: {comments: :copyright}}
|
176
190
|
js_converter = Terser.new(converter_config)
|
177
191
|
js_converter.compile(data)
|