Made template prettier

Also more formatting for the output. This is now actually usable.
This commit is contained in:
kageru 2018-11-04 22:05:48 +01:00
parent f5534b62ff
commit 99d20cf1f6
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 44 additions and 8 deletions

2
db.go
View File

@ -41,7 +41,7 @@ func resultToBlogposts(res *sql.Rows) []BlogPost {
var content, author, title string
var timeInt int64
res.Scan(&content, &author, &title, &timeInt)
post := BlogPost{Content:content, Author:author, Title:title, Time:time.Unix(timeInt, 0)}
post := BlogPost{Content:content, Author:author, Title:title, FTime:time.Unix(timeInt, 0).Format("02.01.2006 - 15:04:05")}
entries = append(entries, post)
}
return entries

View File

@ -20,5 +20,6 @@ type BlogPost struct {
Author string `"author"`
Secret string `"secret"`
Time time.Time `"time"`
FTime string `"ftime"`
}

View File

@ -15,8 +15,8 @@ type OutputFormatter struct {
Content string
}
type Wrapper struct {
Post OutputFormatter
type Blog struct {
Posts []BlogPost
}
func startServer() {
@ -40,8 +40,7 @@ func get(w http.ResponseWriter, r *http.Request) {
}
*/
results := readBlogpostsFromDB()
err = t.ExecuteTemplate(w, "overview.html", OutputFormatter{Author: results[0].Author, Content: results[0].Content})
log.Println(err)
t.ExecuteTemplate(w, "overview.html", Blog{results})
}
func post(w http.ResponseWriter, r *http.Request) {

View File

@ -1,7 +1,43 @@
<html>
<body style="background-color: #333; color: #ccc;">
<div id="content" style="width: 70%; margin: auto; padding-top: 10%;">
{{.Author}} said: {{.Content}}
<style>
body {
background-color: #333;
color: #ccc;
font-family: monospace, "Helvetica Neue", "Helvetica", "Noto Sans", sans-serif;
}
#content {
width: 70%;
margin: auto;
padding-top: 2em;
}
td.first {
width: 20%;
}
td.second {
padding-top: 0;
margin-top: 0;
top: 0;
width: 80%;
}
</style>
<body>
<div id="content">
<h2 style="text-align: center">Random Thought Dump</h2>
<table>
{{range $i, $p := $.Posts -}}
<tr>
<td>
[{{$p.FTime}}] &lt;{{$p.Author}}&gt;
</td>
<td>
{{$p.Content}}
</td>
</tr>
{{- end}}
<table>
</div>
</body>
</html>