Made template prettier
Also more formatting for the output. This is now actually usable.
This commit is contained in:
parent
f5534b62ff
commit
99d20cf1f6
2
db.go
2
db.go
@ -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
|
||||
|
1
main.go
1
main.go
@ -20,5 +20,6 @@ type BlogPost struct {
|
||||
Author string `"author"`
|
||||
Secret string `"secret"`
|
||||
Time time.Time `"time"`
|
||||
FTime string `"ftime"`
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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}}] <{{$p.Author}}>
|
||||
</td>
|
||||
<td>
|
||||
{{$p.Content}}
|
||||
</td>
|
||||
</tr>
|
||||
{{- end}}
|
||||
<table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user