Browse Source

Add error page and favicon

pull/2/head
Tovi Jaeschke-Rogers 3 years ago
parent
commit
3909ea714b
14 changed files with 82 additions and 20 deletions
  1. +25
    -2
      Webserver/Index.go
  2. +16
    -9
      Webserver/Post.go
  3. +11
    -6
      Webserver/ServeFile.go
  4. +2
    -0
      Webserver/Webserver.go
  5. +3
    -1
      web/css/main.css
  6. +3
    -0
      web/html/error.gohtml
  7. +1
    -1
      web/html/header.gohtml
  8. +8
    -0
      web/html/index-links.gohtml
  9. +7
    -0
      web/html/index.gohtml
  10. +6
    -1
      web/html/post.gohtml
  11. BIN
      web/static/1622082948272.jpg
  12. BIN
      web/static/favicon-16x16.png
  13. BIN
      web/static/favicon-32x32.png
  14. BIN
      web/static/favicon.ico

+ 25
- 2
Webserver/Index.go View File

@ -1,6 +1,7 @@
package Webserver package Webserver
import ( import (
"log"
"net/http" "net/http"
"PersonalWebsite/Database" "PersonalWebsite/Database"
@ -15,9 +16,31 @@ func ViewIndex(w http.ResponseWriter, r *http.Request) {
v["PageView"] = "index-intro.gohtml" v["PageView"] = "index-intro.gohtml"
v["Posts"], e = Database.GetPostsList(5, 0) v["Posts"], e = Database.GetPostsList(5, 0)
if e != nil { if e != nil {
// TODO: Handle this
http.Error(w, "Error", http.StatusInternalServerError)
log.Println(e)
http.Redirect(w, r, "/error", 302)
} }
ServeTemplate(w, r, "html/index.gohtml", v) ServeTemplate(w, r, "html/index.gohtml", v)
} }
func ViewLinks(w http.ResponseWriter, r *http.Request) {
var (
v = make(map[string]interface{})
)
v["PageView"] = "index-links.gohtml"
ServeTemplate(w, r, "html/index.gohtml", v)
}
func ViewError(w http.ResponseWriter, r *http.Request) {
var (
v = make(map[string]interface{})
)
v["PageView"] = "error.gohtml"
ServeTemplate(w, r, "html/index.gohtml", v)
}

+ 16
- 9
Webserver/Post.go View File

@ -6,6 +6,7 @@ import (
"strconv" "strconv"
"PersonalWebsite/Database" "PersonalWebsite/Database"
"PersonalWebsite/Helper"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -22,9 +23,15 @@ func ViewPost(w http.ResponseWriter, r *http.Request) {
post, e = Database.GetPostById(urlParams["id"]) post, e = Database.GetPostById(urlParams["id"])
if e != nil { if e != nil {
// TODO: Forward 404
log.Println("Could not get post")
http.Error(w, "Error", http.StatusInternalServerError)
log.Println(e)
http.Redirect(w, r, "/error", 302)
return
}
post.Body, e = Helper.GetFileContents(post.HtmlPath)
if e != nil {
log.Println(e)
http.Redirect(w, r, "/error", 302)
return return
} }
@ -58,8 +65,8 @@ func ViewPostList(w http.ResponseWriter, r *http.Request, subject string) {
} else { } else {
page, e = strconv.Atoi(keys[0]) page, e = strconv.Atoi(keys[0])
if e != nil { if e != nil {
// TODO: Handle this
http.Error(w, "Error", http.StatusInternalServerError)
log.Println(e)
http.Redirect(w, r, "/error", 302)
return return
} }
} }
@ -68,15 +75,15 @@ func ViewPostList(w http.ResponseWriter, r *http.Request, subject string) {
posts, e = Database.GetPostsListBySubject(limit, offset, subject) posts, e = Database.GetPostsListBySubject(limit, offset, subject)
if e != nil { if e != nil {
// TODO: Handle this
http.Error(w, "Error", http.StatusInternalServerError)
log.Println(e)
http.Redirect(w, r, "/error", 302)
return return
} }
postsCount, e = Database.GetPostCountBySubject(subject) postsCount, e = Database.GetPostCountBySubject(subject)
if e != nil { if e != nil {
// TODO: Handle this
http.Error(w, "Error", http.StatusInternalServerError)
log.Println(e)
http.Redirect(w, r, "/error", 302)
return return
} }


+ 11
- 6
Webserver/ServeFile.go View File

@ -1,6 +1,7 @@
package Webserver package Webserver
import ( import (
"log"
"net/http" "net/http"
"path" "path"
"text/template" "text/template"
@ -18,9 +19,11 @@ var (
"html/header.gohtml", "html/header.gohtml",
"html/sidebar.gohtml", "html/sidebar.gohtml",
"html/index-intro.gohtml", "html/index-intro.gohtml",
"html/index-links.gohtml",
"html/index-post-list.gohtml", "html/index-post-list.gohtml",
"html/post-list.gohtml", "html/post-list.gohtml",
"html/post.gohtml", "html/post.gohtml",
"html/error.gohtml",
} }
) )
@ -42,8 +45,9 @@ func ServeTemplate(w http.ResponseWriter, r *http.Request, mainFile string, v ma
v["SidebarLinks"], e = Database.GetAllSidebarLinks() v["SidebarLinks"], e = Database.GetAllSidebarLinks()
if e != nil { if e != nil {
// TODO: Handle
panic(e)
log.Println(e)
http.Redirect(w, r, "/error", 302)
return
} }
files = []string{webRootJoin(mainFile)} files = []string{webRootJoin(mainFile)}
@ -64,14 +68,15 @@ func ServeTemplate(w http.ResponseWriter, r *http.Request, mainFile string, v ma
}, },
).ParseFiles(files...) ).ParseFiles(files...)
if e != nil { if e != nil {
// TODO: Handle this
panic(e)
log.Println(e)
http.Redirect(w, r, "/error", 302)
} }
w.Header().Set("Content-type", "text/html") w.Header().Set("Content-type", "text/html")
e = tpl.Execute(w, v) e = tpl.Execute(w, v)
if e != nil { if e != nil {
// TODO: Handle this
panic(e)
log.Println(e)
http.Redirect(w, r, "/error", 302)
return
} }
} }

+ 2
- 0
Webserver/Webserver.go View File

@ -58,9 +58,11 @@ func Start() error {
// Interface endpoints // Interface endpoints
r.HandleFunc("/", ViewIndex) r.HandleFunc("/", ViewIndex)
r.HandleFunc("/links", ViewLinks)
r.HandleFunc("/programming", ViewPostListProgramming) r.HandleFunc("/programming", ViewPostListProgramming)
r.HandleFunc("/pentesting", ViewPostListPentesting) r.HandleFunc("/pentesting", ViewPostListPentesting)
r.HandleFunc("/post/{id}", ViewPost) r.HandleFunc("/post/{id}", ViewPost)
r.HandleFunc("/error", ViewError)
// Administration // Administration
r.HandleFunc("/admin", AdminView) r.HandleFunc("/admin", AdminView)


+ 3
- 1
web/css/main.css View File

@ -243,7 +243,9 @@ pre::-webkit-scrollbar-color {
} }
.post-icon { .post-icon {
max-width: 200px !important;
max-width: 50% !important;
max-height: 20em !important;
padding-bottom: 2em;
} }
.icon-div { .icon-div {


+ 3
- 0
web/html/error.gohtml View File

@ -0,0 +1,3 @@
<h2>Whoops! It looks like you've run into an error!</h2>
<p>Please click <a href="/">here</a> to go back to the home screen</p>

+ 1
- 1
web/html/header.gohtml View File

@ -7,7 +7,7 @@
<ul> <ul>
<a href="/pentesting?page=0"><li class="{{ if eq .Subject "Pentesting" }}active{{ end }}">Pentesting</li></a> <a href="/pentesting?page=0"><li class="{{ if eq .Subject "Pentesting" }}active{{ end }}">Pentesting</li></a>
<a href="/programming?page=0"><li class="{{ if eq .Subject "Programming" }}active{{ end }}">Programming</li></a> <a href="/programming?page=0"><li class="{{ if eq .Subject "Programming" }}active{{ end }}">Programming</li></a>
<a href="/links.html"><li>Links</li></a>
<a href="/links"><li>Links</li></a>
</ul> </ul>
</div> </div>
<ul class="pc-links"> <ul class="pc-links">


+ 8
- 0
web/html/index-links.gohtml View File

@ -0,0 +1,8 @@
<h2>Links</h2>
<div class="main-links">
<ul>
{{ range $link := .SidebarLinks }}
<a href="{{ $link.Link }}"><li>{{ $link.Name }}</li></a>
{{ end }}
</ul>
</div>

+ 7
- 0
web/html/index.gohtml View File

@ -1,8 +1,11 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tovi Jaeschke's Homepage</title> <title>Tovi Jaeschke's Homepage</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico"/>
<link rel="stylesheet" type="text/css" href="/css/main.css"> <link rel="stylesheet" type="text/css" href="/css/main.css">
<link href='https://fonts.googleapis.com/css?family=Average|Montserrat' rel='stylesheet' type='text/css'> <link href='https://fonts.googleapis.com/css?family=Average|Montserrat' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/prism.css"> <link rel="stylesheet" href="/css/prism.css">
@ -21,6 +24,10 @@
{{ template "post-list.gohtml" . }} {{ template "post-list.gohtml" . }}
{{ else if eq .PageView "post.gohtml" }} {{ else if eq .PageView "post.gohtml" }}
{{ template "post.gohtml" . }} {{ template "post.gohtml" . }}
{{ else if eq .PageView "index-links.gohtml" }}
{{ template "index-links.gohtml" . }}
{{ else if eq .PageView "error.gohtml" }}
{{ template "error.gohtml" . }}
{{ end }} {{ end }}
</div> </div>
</div> </div>


+ 6
- 1
web/html/post.gohtml View File

@ -1,8 +1,13 @@
<h3 class='post-title'>{{ .Post.Title }}</h2> <h3 class='post-title'>{{ .Post.Title }}</h2>
{{ if .Post.MainImage }} {{ if .Post.MainImage }}
<div class='icon-div'> <div class='icon-div'>
<img class='post-icon' src='{{ .Post.MainImage }}' />
<img class='post-icon' src='/static/{{ .Post.MainImage }}' />
</div> </div>
{{ end }} {{ end }}
<div>
{{ .Post.Intro }} {{ .Post.Intro }}
</div>
<br/>
<div>
{{ .Post.Body }} {{ .Post.Body }}
</div>

BIN
web/static/1622082948272.jpg View File

Before After
Width: 3240  |  Height: 2102  |  Size: 631 KiB

BIN
web/static/favicon-16x16.png View File

Before After
Width: 16  |  Height: 16  |  Size: 183 B

BIN
web/static/favicon-32x32.png View File

Before After
Width: 32  |  Height: 32  |  Size: 310 B

BIN
web/static/favicon.ico View File

Before After

Loading…
Cancel
Save