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 content, author, title string
|
||||||
var timeInt int64
|
var timeInt int64
|
||||||
res.Scan(&content, &author, &title, &timeInt)
|
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)
|
entries = append(entries, post)
|
||||||
}
|
}
|
||||||
return entries
|
return entries
|
||||||
|
|
1
main.go
1
main.go
|
@ -20,5 +20,6 @@ type BlogPost struct {
|
||||||
Author string `"author"`
|
Author string `"author"`
|
||||||
Secret string `"secret"`
|
Secret string `"secret"`
|
||||||
Time time.Time `"time"`
|
Time time.Time `"time"`
|
||||||
|
FTime string `"ftime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ type OutputFormatter struct {
|
||||||
Content string
|
Content string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Wrapper struct {
|
type Blog struct {
|
||||||
Post OutputFormatter
|
Posts []BlogPost
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer() {
|
func startServer() {
|
||||||
|
@ -40,8 +40,7 @@ func get(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
results := readBlogpostsFromDB()
|
results := readBlogpostsFromDB()
|
||||||
err = t.ExecuteTemplate(w, "overview.html", OutputFormatter{Author: results[0].Author, Content: results[0].Content})
|
t.ExecuteTemplate(w, "overview.html", Blog{results})
|
||||||
log.Println(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func post(w http.ResponseWriter, r *http.Request) {
|
func post(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -1,7 +1,43 @@
|
||||||
<html>
|
<html>
|
||||||
<body style="background-color: #333; color: #ccc;">
|
<style>
|
||||||
<div id="content" style="width: 70%; margin: auto; padding-top: 10%;">
|
body {
|
||||||
{{.Author}} said: {{.Content}}
|
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>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user