From d838d0d3c9fc1bc9b584938121736722f3b32c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= Date: Mon, 18 Sep 2017 22:22:24 +0200 Subject: [PATCH] remove edited timestamp from stats if empty --- assets/templates/stats.html | 2 ++ server.go | 1 + storage.go | 8 +++----- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/assets/templates/stats.html b/assets/templates/stats.html index 1192ac1..c703d07 100644 --- a/assets/templates/stats.html +++ b/assets/templates/stats.html @@ -2,7 +2,9 @@

Statistics

+ {{if not .Edited.IsZero}} + {{end}}
Published{{.Published.Format "Jan 02, 2006 15:04:05 UTC"}}
Edited{{.Edited.Format "Jan 02, 2006 15:04:05 UTC"}}
Views{{.Views}}
{{end}} diff --git a/server.go b/server.go index 1cd5243..dca785e 100644 --- a/server.go +++ b/server.go @@ -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()) diff --git a/storage.go b/storage.go index d9fc57a..c4fd231 100644 --- a/storage.go +++ b/storage.go @@ -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 }