Browse Source

remove edited timestamp from stats if empty

master
Christian Müller 8 years ago
parent
commit
d838d0d3c9
  1. 2
      assets/templates/stats.html
  2. 1
      server.go
  3. 8
      storage.go

2
assets/templates/stats.html

@ -2,7 +2,9 @@ @@ -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
server.go

@ -55,6 +55,7 @@ func main() { @@ -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())

8
storage.go

@ -149,16 +149,14 @@ func load(c echo.Context, db *sql.DB) (Note, int) { @@ -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
}

Loading…
Cancel
Save