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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hyde-page-js.rb +39 -27
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17a523c022d3eb4883130d9b143285e028f4f83fcfe3011f614ab0ec25a05aef
4
- data.tar.gz: b9b674f5042f528004838ab8e73a6f8840e70ae0bdb675f7991de420d715ff6f
3
+ metadata.gz: eee9b1d2c569ffec0d14030836c846c6935df3f9631abf4743129774c9389e65
4
+ data.tar.gz: 7782118903c49b5f00696c5ad22d4e84738547710586fb70f2ffb49e485032d4
5
5
  SHA512:
6
- metadata.gz: 2e5799de5113ea965a1d638bf7a69eba7946fc7133d5f5d8cf4d37a13090902d7b97a703f226c749c2c44f3bb78f578cc1a514c8e11d31ceecf2dabc08bd041f
7
- data.tar.gz: 203b8c566d58cebc526c8627425d6638b722003a4022b3af4d91126f64eba90696d289e808d3913fd7212f5fdb9e4c285a20131b2b313cb5166e8d2b12b4b7a1
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, :pre_render do |page, payload|
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.0"
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
- 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?
72
+ js_groups = parent_layout_js(layout, js).reverse
73
+ return if js_groups.flatten.empty?
73
74
 
74
- data = concatenate_files(results)
75
- return if data == ""
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
- data = minify(data)
78
- return if data == ""
79
+ if cache_entry.nil?
80
+ data = concatenate_files(group)
81
+ break if data == ""
79
82
 
80
- generated_file = generate_file(results, data)
83
+ data = minify(data)
84
+ break if data == ""
81
85
 
82
- # file already exists, so skip writing out the data to disk
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
- # place file data into the new file
86
- generated_file.file_contents = data
88
+ # place file data into the new file
89
+ generated_file.file_contents = data
87
90
 
88
- # assign static file to list for jekyll to render
89
- @site.static_files << generated_file
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
- # assign to site.data.js_files for liquid output
92
- add_to_urls(generated_file.url)
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
- # add to cache
95
- @site.data['_hyde_pages_cache'][lookup_name] = data
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
- @site.data['js_files'] ||= []
106
- @site.data['js_files'].push(url)
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', []).reverse
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.uniq.compact
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.0
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-27 00:00:00.000000000 Z
11
+ date: 2023-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll