arnaucube
arnaucube/md-live-serverPublic Self-hosted repository
md-live-server/template.go
template.goRaw
 1package main
 2
 3// html templates are here instead of an .html file to avoid depending on external files
 4// in this way, everything is inside the binary
 5
 6const dirTemplate = `
 7<!DOCTYPE html>
 8<html>
 9<title>{{.Title}}</title>
10<style>
11body {
12    font-family: Arial, Helvetica, sans-serif;
13    background:#000000;
14    color:#cccccc;
15}
16</style>
17<body>
18
19{{.Content}}
20
21</body>
22</html>
23`
24
25const htmlTemplate = `
26<!DOCTYPE html>
27<html>
28<title>{{.Title}}</title>
29<style>
30body {
31    font-family: Arial, Helvetica, sans-serif;
32    background:#000000;
33    color:#cccccc;
34}
35pre, code{
36    padding-left: 3px;
37    padding-right: 3px;
38    background: #333333;
39    border-radius: 3px;
40}
41pre>code {
42    color: #c0fffa;
43}
44h1:after{
45    content:' ';
46    display:block;
47    border:1px solid #cccccc;
48}
49h2:after{
50    content:' ';
51    display:block;
52    border:0.7px solid #cccccc;
53}
54</style>
55<body>
56
57{{.Content}}
58
59<script>
60(function() {
61	var conn = new WebSocket("ws://127.0.0.1:8080/ws/{{.Title}}");
62	conn.onclose = function(evt) {
63	    console.log('Connection closed');
64	    alert('Connection closed');
65	}
66	conn.onmessage = function(evt) {
67	    console.log('file updated');
68	    // location.reload();
69	    console.log("evt", evt);
70	    document.getElementsByTagName("BODY")[0].innerHTML = evt.data;
71	}
72})();
73</script>
74</body>
75</html>
76`