Added an error page.
This commit is contained in:
parent
c5ffe37c52
commit
4657319d52
@ -37,6 +37,7 @@ func (h *FilesHandlers) Index(w http.ResponseWriter, r *http.Request) {
|
|||||||
entries, stats, err := files.ScanDirectory(h.directoryPath+path, path)
|
entries, stats, err := files.ScanDirectory(h.directoryPath+path, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
Error(w, http.StatusNotFound, "", "", r.Referer())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,3 +57,8 @@ func RobotsTxt(w http.ResponseWriter, r *http.Request) {
|
|||||||
fc, _ := web.AssetsGetFile("robots.txt")
|
fc, _ := web.AssetsGetFile("robots.txt")
|
||||||
w.Write(fc)
|
w.Write(fc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Error(w http.ResponseWriter, code int, reason, message, referer string) {
|
||||||
|
w.WriteHeader(code)
|
||||||
|
web.ErrorXXX("/ "+http.StatusText(code), reason, message, referer, code, w)
|
||||||
|
}
|
||||||
|
7
web/assets/css/error.css
Normal file
7
web/assets/css/error.css
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#error {
|
||||||
|
font-size: 3.5rem;
|
||||||
|
line-height: 5rem;
|
||||||
|
text-align: center;
|
||||||
|
margin: 6rem 0; }
|
||||||
|
|
||||||
|
#error h1 { font-size: 8rem; }
|
24
web/templates/errorXXX.jade
Normal file
24
web/templates/errorXXX.jade
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
extends base.jade
|
||||||
|
|
||||||
|
block meta_description
|
||||||
|
meta(name='description' content=http.StatusText(code))
|
||||||
|
|
||||||
|
block append head
|
||||||
|
link(href='/assets/css/error.css' rel='stylesheet')
|
||||||
|
|
||||||
|
block nav
|
||||||
|
a(href='/') Back to index page
|
||||||
|
h1 #{http.StatusText(code)}
|
||||||
|
|
||||||
|
block content
|
||||||
|
:go:func ErrorXXX(title, reason, message, referer string, code int)
|
||||||
|
section#error
|
||||||
|
h1 #{code}
|
||||||
|
| #{http.StatusText(code)}
|
||||||
|
if reason != ""
|
||||||
|
p #{reason}
|
||||||
|
if message != ""
|
||||||
|
p #{message}
|
||||||
|
if referer != ""
|
||||||
|
section
|
||||||
|
h2 #[a(href=referer) Go back]
|
@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//go:generate $GOPATH/bin/jade -pkg=web -stdbuf -writer templates/index.jade
|
//go:generate $GOPATH/bin/jade -pkg=web -stdbuf -writer templates/index.jade
|
||||||
|
//go:generate $GOPATH/bin/jade -pkg=web -stdbuf -writer templates/errorXXX.jade
|
||||||
|
|
||||||
//go:embed assets
|
//go:embed assets
|
||||||
var assetsDir embed.FS
|
var assetsDir embed.FS
|
||||||
|
Loading…
Reference in New Issue
Block a user