add page error when file don't exists

This commit is contained in:
arnaucube
2019-05-08 21:46:25 +02:00
parent a0b3d071e5
commit 1eec2da173
4 changed files with 27 additions and 1 deletions

97
templates.go Normal file
View File

@@ -0,0 +1,97 @@
package main
// html templates are here instead of an .html file to avoid depending on external files
// in this way, everything is inside the binary
const dirTemplate = `
<!DOCTYPE html>
<html>
<title>{{.Title}}</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background:#000000;
color:#cccccc;
}
</style>
<body>
{{.Content}}
</body>
</html>
`
const htmlTemplate = `
<!DOCTYPE html>
<html>
<title>{{.Title}}</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background:#000000;
color:#cccccc;
}
pre, code{
padding-left: 3px;
padding-right: 3px;
background: #333333;
border-radius: 3px;
}
pre>code {
color: #c0fffa;
}
h1:after{
content:' ';
display:block;
border:1px solid #cccccc;
}
h2:after{
content:' ';
display:block;
border:0.7px solid #cccccc;
}
</style>
<body>
{{.Content}}
<script>
(function() {
var conn = new WebSocket("ws://127.0.0.1:8080/ws/{{.Title}}");
conn.onclose = function(evt) {
console.log('Connection closed');
alert('Connection closed');
}
conn.onmessage = function(evt) {
console.log('file updated');
// location.reload();
console.log("evt", evt);
document.getElementsByTagName("BODY")[0].innerHTML = evt.data;
}
})();
</script>
</body>
</html>
`
const errTemplate = `
<!DOCTYPE html>
<html>
<title>{{.Title}}</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background:#000000;
color:#cccccc;
}
</style>
<body>
<h3>File doesn't exist</h3>
<br><br>
<a href="/">Back to dir menu</a>
</body>
</html>
`