-
Notifications
You must be signed in to change notification settings - Fork 20
/
site.tmpl
182 lines (159 loc) · 6.87 KB
/
site.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
{{/* -*- mode: web; engine: go -*- */}}
{{ define "header" }}<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ if .Title }}{{ .Title }} - {{ end }}{{ .Site.Other.Title }}</title>
<meta property="og:type" content="website">
<meta property="og:url" content="{{ .Site.Other.Url }}/{{ .Url }}">
<meta property="og:title" content="{{ if .Title }}{{ .Title }} - {{ end }}{{ .Site.Other.Title }}">
<meta property="og:description" content="Declarative enhancement for HTML: simple, composable, lean.">
<meta property="og:image" content="{{ .Site.Other.Url }}{{ version . "static/favicon.png" | absurl .Url }}">
<meta property="og:image:width" content="197">
<meta property="og:image:height" content="256">
<link rel="stylesheet" type="text/css" href="{{ version . "vendor/spectre.min.css" }}">
<link rel="stylesheet" type="text/css" href="{{ version . "static/custom.css" }}">
<script src="{{ version . "vendor/xhr-mock.js" }}"></script>
<link rel="stylesheet" href="{{ version . "vendor/highlight-foundation.min.css" }}">
<script src="{{ version . "vendor/highlight.min.js" }}"></script>
<link rel="icon" href="{{ version . "static/favicon.png" }}" type="image/png" />
<script src="{{ version . "static/twinspark.js" }}" data-timeout="5000" data-history="3"></script>
<script src="{{ version . "vendor/tinytest.js" }}"></script>
<script src="{{ version . "static/examples.js" }}"></script>
</head>
<body>
<header class="navbar my-2 container grid-70">
<section class="navbar-section">
<a href="{{ .Rel "/" }}"><img src="{{ version . "static/twinspark-logo.svg" }}" alt="TwinSpark" style="aspect-ratio: 238 / 56; height: 30px"></a>
</section>
<section class="navbar-section">
<a href="{{ .Rel "/api/" }}" class="btn btn-link">API</a>
<a href="{{ .Rel "/usecases/" }}" class="btn btn-link">Use Cases</a>
<!-- <a href="{{ .Rel "/examples/" }}" class="btn btn-link">Examples</a> -->
</section>
</header>
{{ end }}
{{ define "footer" }}
<footer class="footer container grid-70">
<div class="columns">
<p class="col-8 col-md-6">
<a href="https://github.com/piranha/twinspark-js">GitHub</a>
·
<a href="https://twitter.com/asolovyov">Twitter</a>
</p>
<p class="col-4 col-md-6">Made by <a href="https://solovyov.net/">Alexander Solovyov</a>, licensed under <a href="https://github.com/piranha/twinspark-js/blob/master/LICENSE">MIT license</a>.</p>
</div>
<hr>
<aside>If you found an error, or want to add something, please <a href="https://github.com/piranha/twinspark-js/blob/master/www/{{ .Source }}">edit the file on Github</a> and submit a pull request.</aside>
</footer>
<script>hljs.highlightAll()</script>
</body>
</html>
{{ end }}
{{ define "page" }}{{ template "header" . }}
<main class="container grid-70">{{ .Content }}</main>
{{ template "network" . }}
{{ template "footer" . }}{{ end }}
{{ define "network" }}
<style>
#debug-requests {
position: fixed;
bottom: 0; left: 0; right: 0;
padding: 0.5em;
width: 100vw;
height: 64px;
background-color: whitesmoke;
border-top: 2px solid gray;
transition: height .2s ease-in-out;
z-index: 10;
}
#debug-requests.show {
height: 45vh;
overflow: scroll;
}
#debug-requests ol, #debug-requests li { margin: 0; }
.show .show_show, .show_hide { display: none; }
.show .show_hide { display: inline; }
</style>
<div id="debug-requests" style="display: none;">
Server Requests
<a class="show_show" href="#" ts-action="prevent, target #debug-requests, class^ show">↑ Show</a>
<a class="show_hide" href="#" ts-action="prevent, target #debug-requests, class- show">↓ Hide</a>
<div class="columns">
<ol id="debug-timeline" class="column col-3" reversed>
</ol>
<div id="debug-details" class="column col-9">
<div class="d-hide">
</div>
</div>
</div>
<script>
function switchResponse(id) {
var active = window['debug-timeline'].querySelector('.active');
active && active.classList.remove('active');
var shown = window['debug-details'].querySelector(':scope > :not(.d-hide)');
shown && shown.classList.add('d-hide');
document.querySelector(`[rel="${id}"]`).classList.add('active');
document.getElementById(id).classList.remove('d-hide');
}
(() => {
var i = 0;
const origSend = XMLHttpRequest.prototype.send;
const origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.send = function(body) {
this.requestBody = body;
origSend.apply(this, arguments);
};
XMLHttpRequest.prototype.open = function(method, url) {
this.addEventListener('load', function() {
window['debug-requests'].style.display = '';
document.querySelector('footer').style.paddingBottom = '40vh';
var id = `debug${i++}`;
window['debug-timeline'].insertAdjacentHTML(
'afterbegin',
// this uses concat instead of single string to avoid whitespace
// between tags - and this causes a spacing in the underline
`<li><a style="cursor:pointer" rel="${id}" onclick="switchResponse('${id}')">` +
`<code><b>${method}</b> ${url}</code>` +
`</a></li>`
);
var headers = '';
for (let k in this.res._headers) {
headers += `<tr><td><code>${k}</code></td> <td><code>${this.res._headers[k]}</code></td></tr>`
}
headers && (headers = `<div><b>Headers:</b> <table class=table>${headers}</table></div>`);
var body = this.requestBody && `<div><b>Body:</b> <pre><code>${escape(dedent(decode(this.requestBody)))}</code></pre></div>`;
window['debug-details'].insertAdjacentHTML(
'afterbegin',
`<div id="${id}" class="d-hide">
<div><code>${this.status} <b>${method}</b> ${url} (${new Date().toTimeString().split(' ')[0]})</code></div>
${headers || ''}
${body || ''}
<div><b>Response</b></div>
<pre style="margin-top:0" class="xml"><code>${escape(dedent(this.responseText))}</code></pre>
</div>`
);
hljs.highlightElement(document.querySelector(`#${id} pre code`));
document.querySelector(`[rel="${id}"]`).click();
});
origOpen.apply(this, arguments);
};
})();
</script>
</div>
{{ end }}
{{ define "example" }}
<h3 id="{{ .Other.Id }}" class="hover-group">
{{ .Title }}
{{ if .Has "Tag" "advanced" }} <small class="text-muted">(advanced)</small>{{ end -}}
<a class="hover-hide" href="#{{ .Other.Id }}">#</a>
</h3>
{{ .Content }}
{{ end }}
{{ define "examples" }}
<h2>Examples</h2>
{{ range .Site.Pages.WithTag .Title | abcsort }}
{{ .Process.Content | cut "<main.*?>" "</main>" }}
{{ end }}
{{ end }}