hyde-page-js 0.3.0 → 0.3.2
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 +34 -26
- 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: 71202952cbb7a6f848efb35f52b2567e0f5e71ff4c2bd03cb7900b646f76baf4
|
4
|
+
data.tar.gz: 89a466f9500aab52b11934ba3a7d4983727b8932322bb26142dd36e18c981188
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15e8b455e09fc47ed4c174588c2bd53b3fd38eb83a79fdc94515f7af6737292f3d7be05349e8010cb312243fb76d309e62bdcfe5905265b796c1571f278eaa01
|
7
|
+
data.tar.gz: 3692c60d4d2a9b2511e19db565fc411281bf265465e1c5be0fd0c28d6a37ea2a64ccf61430ee455c47453b253307040cbec83687c2dbb2b80d0bc462bce11964
|
data/lib/hyde-page-js.rb
CHANGED
@@ -2,14 +2,14 @@ require 'terser'
|
|
2
2
|
require 'digest'
|
3
3
|
require 'jekyll'
|
4
4
|
|
5
|
-
Jekyll::Hooks.register :pages, :
|
6
|
-
Hyde::Page::Js.new(page).run
|
5
|
+
Jekyll::Hooks.register :pages, :post_init do |page, payload|
|
6
|
+
Hyde::Page::Js.new(page).run if page.instance_of? Jekyll::Page
|
7
7
|
end
|
8
8
|
|
9
9
|
module Hyde
|
10
10
|
module Page
|
11
11
|
class Js
|
12
|
-
VERSION = "0.3.
|
12
|
+
VERSION = "0.3.2"
|
13
13
|
end
|
14
14
|
|
15
15
|
class GeneratedJsFile < Jekyll::StaticFile
|
@@ -65,34 +65,42 @@ module Hyde
|
|
65
65
|
def run
|
66
66
|
js = fetch_js(@page)
|
67
67
|
layout = fetch_layout(fetch_layout_name(@page))
|
68
|
-
|
69
|
-
return if
|
68
|
+
js_groups = parent_layout_js(layout, js).reverse
|
69
|
+
return if js_groups.empty?
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
for group in js_groups
|
72
|
+
lookup_name = names_to_key(group)
|
73
|
+
cache_entry = @site.data['_hyde_pages_cache'].fetch(lookup_name, nil)
|
73
74
|
|
74
|
-
|
75
|
-
|
75
|
+
if cache_entry.nil?
|
76
|
+
data = concatenate_files(group)
|
77
|
+
return if data == ""
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
+
data = minify(data)
|
80
|
+
return if data == ""
|
79
81
|
|
80
|
-
|
82
|
+
generated_file = generate_file(group, data)
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
+
# file already exists, so skip writing out the data to disk
|
85
|
+
return unless @site.static_files.find { |static_file| static_file.name == generated_file.name }.nil?
|
84
86
|
|
85
|
-
|
86
|
-
|
87
|
+
# place file data into the new file
|
88
|
+
generated_file.file_contents = data
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
+
# assign static file to list for jekyll to render
|
91
|
+
@site.static_files << generated_file
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
+
# add to cache
|
94
|
+
cache_entry = {
|
95
|
+
"url": generated_file.url,
|
96
|
+
"data": data
|
97
|
+
}
|
98
|
+
@site.data['_hyde_pages_cache'][lookup_name] = cache_entry
|
99
|
+
end
|
93
100
|
|
94
|
-
|
95
|
-
|
101
|
+
# assign to site.data.js_files for liquid output
|
102
|
+
add_to_urls(cache_entry.fetch(:url, nil)).compact
|
103
|
+
end
|
96
104
|
end
|
97
105
|
|
98
106
|
private
|
@@ -102,8 +110,8 @@ module Hyde
|
|
102
110
|
end
|
103
111
|
|
104
112
|
def add_to_urls(url)
|
105
|
-
@
|
106
|
-
@
|
113
|
+
@page.data['js_files'] ||= []
|
114
|
+
@page.data['js_files'].push(url)
|
107
115
|
end
|
108
116
|
|
109
117
|
def fetch_config
|
@@ -139,7 +147,7 @@ module Hyde
|
|
139
147
|
end
|
140
148
|
|
141
149
|
def fetch_js(obj_with_data, default = [])
|
142
|
-
obj_with_data.data.fetch('js', [])
|
150
|
+
[obj_with_data.data.fetch('js', [])]
|
143
151
|
end
|
144
152
|
|
145
153
|
def fetch_layout(layout_name, default = nil)
|
@@ -156,7 +164,7 @@ module Hyde
|
|
156
164
|
|
157
165
|
def parent_layout_js(layout, js)
|
158
166
|
if layout.nil?
|
159
|
-
return js
|
167
|
+
return js
|
160
168
|
end
|
161
169
|
|
162
170
|
layout_name = fetch_layout_name(layout)
|