md-live-server/templates.go
templates.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{
42 padding: 5px;
43}
44pre>code {
45 color: #c0fffa;
46}
47h1:after{
48 content:' ';
49 display:block;
50 border:1px solid #cccccc;
51}
52h2:after{
53 content:' ';
54 display:block;
55 border:0.7px solid #cccccc;
56}
57th{
58 padding: 3px;
59 border: 1px solid #234b4f;
60 background-color: #143134;
61}
62td{
63 padding: 3px;
64 border: 1px solid #234b4f;
65}
66</style>
67<body>
68
69{{.Content}}
70
71<script>
72(function() {
73 var conn = new WebSocket("ws://127.0.0.1:8080/ws/{{.Title}}");
74 conn.onclose = function(evt) {
75 console.log('Connection closed');
76 alert('Connection closed');
77 }
78 conn.onmessage = function(evt) {
79 console.log('file updated');
80 // location.reload();
81 console.log("evt", evt);
82 document.getElementsByTagName("BODY")[0].innerHTML = evt.data;
83 }
84})();
85</script>
86</body>
87</html>
88`
89
90const errTemplate = `
91<!DOCTYPE html>
92<html>
93<title>{{.Title}}</title>
94<style>
95body {
96 font-family: Arial, Helvetica, sans-serif;
97 background:#000000;
98 color:#cccccc;
99}
100</style>
101<body>
102
103<h3>File doesn't exist</h3>
104<br><br>
105<a href="/">Back to dir menu</a>
106
107</body>
108</html>
109`