remove edited timestamp from stats if empty

This commit is contained in:
Christian Müller
2017-09-18 22:24:21 +02:00
parent 59aeab60c1
commit d838d0d3c9
3 changed files with 6 additions and 5 deletions
+2
View File
@@ -2,7 +2,9 @@
<h2>Statistics</h2>
<table>
<tr><td>Published</td><td>{{.Published.Format "Jan 02, 2006 15:04:05 UTC"}}</td></tr>
{{if not .Edited.IsZero}}
<tr><td>Edited</td><td>{{.Edited.Format "Jan 02, 2006 15:04:05 UTC"}}</td></tr>
{{end}}
<tr><td>Views</td><td>{{.Views}}</td></tr>
</table>
{{end}}
+1
View File
@@ -55,6 +55,7 @@ func main() {
e.GET("/:id/stats", func(c echo.Context) error {
n, code := load(c, db)
n.prepare()
buf := bytes.NewBuffer([]byte{})
e.Renderer.Render(buf, "Stats", n, c)
n.Content = template.HTML(buf.String())
+3 -5
View File
@@ -149,16 +149,14 @@ func load(c echo.Context, db *sql.DB) (Note, int) {
code := http.StatusNotFound
return errPage(code), code
}
var edited time.Time
if editedVal != nil {
edited = editedVal.(time.Time)
}
n := &Note{
ID: id,
Text: text,
Views: views,
Published: published,
Edited: edited,
}
if editedVal != nil {
n.Edited = editedVal.(time.Time)
}
return *n, http.StatusOK
}