mirror of
https://github.com/arnaucube/md-live-server.git
synced 2026-02-07 03:46:40 +01:00
add page error when file don't exists
This commit is contained in:
@@ -14,6 +14,5 @@ And then go to the browser at `http://127.0.0.1:8080`
|
|||||||
- [x] server rendering .md files
|
- [x] server rendering .md files
|
||||||
- [x] live reload when .md file changes
|
- [x] live reload when .md file changes
|
||||||
- [x] directory files list on `/` endpoint
|
- [x] directory files list on `/` endpoint
|
||||||
- [ ] on error return error page, instead of panic server
|
|
||||||
- [ ] graphviz
|
- [ ] graphviz
|
||||||
- [ ] colour `<code>` with syntax highlighting
|
- [ ] colour `<code>` with syntax highlighting
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -60,6 +61,11 @@ func getPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
path = strings.Replace(path, "%", "/", -1)
|
path = strings.Replace(path, "%", "/", -1)
|
||||||
log.Println(path)
|
log.Println(path)
|
||||||
|
|
||||||
|
if len(strings.Split(path, ".")) < 2 {
|
||||||
|
fmt.Fprintf(w, errTemplate)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if strings.Split(path, ".")[1] != "md" {
|
if strings.Split(path, ".")[1] != "md" {
|
||||||
http.ServeFile(w, r, path)
|
http.ServeFile(w, r, path)
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
md-live-server
BIN
md-live-server
Binary file not shown.
@@ -74,3 +74,24 @@ h2:after{
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</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>
|
||||||
|
`
|
||||||
Reference in New Issue
Block a user