79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/weaver/page_types/page.rb', line 79
def generate(back_folders, options = {})
if @options[:cache_file]
expired = @options[:cache_expired]
cache_exist = File.exist?("cache/cachedpage#{@options[:cache_file]}")
if cache_exist && !expired
puts "Weaver Hit cache for file: #{@options[:cache_file]}"
puts "- expired: #{expired}"
puts "- cache_exist: #{cache_exist}"
return File.read("cache/cachedpage#{@options[:cache_file]}")
end
puts "Weaver Miss cache for file: #{@options[:cache_file]}"
puts "- expired: #{expired}"
puts "- cache_exist: #{cache_exist}"
end
scripts = @scripts.join("\n")
mod = '../' * back_folders
style = <<-ENDSTYLE
<link href="#{mod}css/style.css" rel="stylesheet">
ENDSTYLE
if !@options[:theme].nil?
style = <<-ENDSTYLE
<link href="#{mod}css/style-#{@options[:theme]}.css" rel="stylesheet">
ENDSTYLE
end
style = '' if options[:style] == :empty
body_tag = '<body>'
body_tag = "<body class='#{@body_class}'>" if @body_class
loading_bar = ''
if @loading_bar_visible
loading_bar = "<script src='#{mod}js/plugins/pace/pace.min.js'></script>"
end
= @requested_scripts.map do |key, _value|
<<-SCRIPT_DECL
<script src="#{mod}#{key}"></script>
SCRIPT_DECL
end.join "\n"
= @requested_css.map do |key, _value|
<<-STYLESHEET_DECL
<link href="#{mod}#{key}" rel="stylesheet">
STYLESHEET_DECL
end.join "\n"
= @scripts_once.map do |key, _value|
<<~SCRIPT_DECL
#{key}
SCRIPT_DECL
end.join "\n"
onload_scripts = @onload_scripts.map do |value|
<<~SCRIPT_DECL
#{value}
SCRIPT_DECL
end.join "\n"
= ''
if @global_settings[:mixpanel_token]
+= '<!-- start Mixpanel --><script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn4.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn4.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn4.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init("' + @global_settings[:mixpanel_token] + '");</script><!-- end Mixpanel -->'
end
if @global_settings[:google_tracking_code]
+= <<~GOOGLE
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=#{@global_settings[:google_tracking_code]}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '#{@global_settings[:google_tracking_code]}');
</script>
GOOGLE
end
favicon_filename = @favicon_name || 'favicon.ico'
favicon_mimetype = @favicon_type || 'image/x-icon'
result = <<~SKELETON
<!DOCTYPE html>
<html>
<!-- Generated using weaver: https://github.com/davidsiaw/weaver -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#{@title}</title>
<link href="#{mod}css/bootstrap.min.css" rel="stylesheet">
<link href="#{mod}font-awesome/css/font-awesome.css" rel="stylesheet">
<link href="#{mod}css/plugins/iCheck/custom.css" rel="stylesheet">
<link rel="icon" href="#{favicon_filename}" type="#{favicon_mimetype}" />
#{style}
<link href="#{mod}css/animate.css" rel="stylesheet">
#{}
#{}
</head>
#{body_tag}
<div id="background" style="z-index: -999; position:absolute; left:0px; right:0px; width:100%; height:100%">
#{@background.generate}
</div>
<div id="content" style="z-index: 0">
#{@top_content}
#{@content}
</div>
<!-- Mainly scripts -->
<script src="#{mod}js/jquery-3.1.1.min.js"></script>
<script src="#{mod}js/jquery-ui-1.10.4.min.js"></script>
<script src="#{mod}js/bootstrap.min.js"></script>
<script src="#{mod}js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="#{mod}js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
asciimath2jax: {
delimiters: [['$$$MATH$$$','$$$ENDMATH$$$']]
}
});
</script>
<script src="#{mod}js/MathJax/MathJax.js?config=AM_HTMLorMML-full" async></script>
#{}
<!-- Custom and plugin javascript -->
<script src="#{mod}js/weaver.js"></script>
#{loading_bar}
<script>
#{scripts}
#{}
$( document ).ready(function() {
#{onload_scripts}
});
</script>
</body>
</html>
SKELETON
if @options[:cache_file]
FileUtils.mkdir_p 'cache'
File.write("cache/cachedpage#{@options[:cache_file]}", result)
end
result
end
|