hyde-page-js 0.3.0 → 0.3.3
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 +39 -27
- 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: eee9b1d2c569ffec0d14030836c846c6935df3f9631abf4743129774c9389e65
|
4
|
+
data.tar.gz: 7782118903c49b5f00696c5ad22d4e84738547710586fb70f2ffb49e485032d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5544c76ef9087c63bed5335d89f9a0184e650f473b7491f55bfe05ecee4e180392809f1b76c5a6c8225bb459375307c50737a8dd5f440651f0861d831adb8c7
|
7
|
+
data.tar.gz: dca9c39399445509288ce0144c277afaeacd3268fa2dc12043880e32a9fb4be548927d262cd0a46f1a50070b1aa51e8bcc635ca67253997403b2dcc8d3b0d93d
|
data/lib/hyde-page-js.rb
CHANGED
@@ -2,14 +2,18 @@ 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|
|
6
|
+
Hyde::Page::Js.new(page).run if page.instance_of? Jekyll::Page
|
7
|
+
end
|
8
|
+
|
9
|
+
Jekyll::Hooks.register :documents, :pre_render do |document|
|
10
|
+
Hyde::Page::Js.new(document).run if document.instance_of? Jekyll::Document
|
7
11
|
end
|
8
12
|
|
9
13
|
module Hyde
|
10
14
|
module Page
|
11
15
|
class Js
|
12
|
-
VERSION = "0.3.
|
16
|
+
VERSION = "0.3.3"
|
13
17
|
end
|
14
18
|
|
15
19
|
class GeneratedJsFile < Jekyll::StaticFile
|
@@ -65,34 +69,42 @@ module Hyde
|
|
65
69
|
def run
|
66
70
|
js = fetch_js(@page)
|
67
71
|
layout = fetch_layout(fetch_layout_name(@page))
|
68
|
-
|
69
|
-
return if
|
70
|
-
|
71
|
-
lookup_name = names_to_key(results)
|
72
|
-
return unless @site.data['_hyde_pages_cache'].fetch(lookup_name, nil).nil?
|
72
|
+
js_groups = parent_layout_js(layout, js).reverse
|
73
|
+
return if js_groups.flatten.empty?
|
73
74
|
|
74
|
-
|
75
|
-
|
75
|
+
for group in js_groups
|
76
|
+
lookup_name = names_to_key(group)
|
77
|
+
cache_entry = @site.data['_hyde_pages_cache'].fetch(lookup_name, nil)
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
+
if cache_entry.nil?
|
80
|
+
data = concatenate_files(group)
|
81
|
+
break if data == ""
|
79
82
|
|
80
|
-
|
83
|
+
data = minify(data)
|
84
|
+
break if data == ""
|
81
85
|
|
82
|
-
|
83
|
-
return unless @site.static_files.find { |static_file| static_file.name == generated_file.name }.nil?
|
86
|
+
generated_file = generate_file(group, data)
|
84
87
|
|
85
|
-
|
86
|
-
|
88
|
+
# place file data into the new file
|
89
|
+
generated_file.file_contents = data
|
87
90
|
|
88
|
-
|
89
|
-
|
91
|
+
# file doesn't exists, so skip writing out the data to disk
|
92
|
+
if @site.static_files.find { |static_file| static_file.name == generated_file.name }.nil?
|
93
|
+
# assign static file to list for jekyll to render
|
94
|
+
@site.static_files << generated_file
|
95
|
+
end
|
90
96
|
|
91
|
-
|
92
|
-
|
97
|
+
# add to cache
|
98
|
+
cache_entry = {
|
99
|
+
"url": generated_file.url,
|
100
|
+
"data": data
|
101
|
+
}
|
102
|
+
@site.data['_hyde_pages_cache'][lookup_name] = cache_entry
|
103
|
+
end
|
93
104
|
|
94
|
-
|
95
|
-
|
105
|
+
# assign to site.data.js_files for liquid output
|
106
|
+
add_to_urls(cache_entry&.fetch(:url, nil))
|
107
|
+
end
|
96
108
|
end
|
97
109
|
|
98
110
|
private
|
@@ -102,8 +114,8 @@ module Hyde
|
|
102
114
|
end
|
103
115
|
|
104
116
|
def add_to_urls(url)
|
105
|
-
@
|
106
|
-
@
|
117
|
+
@page.data['js_files'] ||= []
|
118
|
+
@page.data['js_files'].push(url)
|
107
119
|
end
|
108
120
|
|
109
121
|
def fetch_config
|
@@ -139,7 +151,7 @@ module Hyde
|
|
139
151
|
end
|
140
152
|
|
141
153
|
def fetch_js(obj_with_data, default = [])
|
142
|
-
obj_with_data.data.fetch('js', [])
|
154
|
+
[obj_with_data.data.fetch('js', [])]
|
143
155
|
end
|
144
156
|
|
145
157
|
def fetch_layout(layout_name, default = nil)
|
@@ -156,7 +168,7 @@ module Hyde
|
|
156
168
|
|
157
169
|
def parent_layout_js(layout, js)
|
158
170
|
if layout.nil?
|
159
|
-
return js
|
171
|
+
return js
|
160
172
|
end
|
161
173
|
|
162
174
|
layout_name = fetch_layout_name(layout)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyde-page-js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory Daynes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|