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 @@
<h2>Statistics</h2> <h2>Statistics</h2>
<table> <table>
<tr><td>Published</td><td>{{.Published.Format "Jan 02, 2006 15:04:05 UTC"}}</td></tr> <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> <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> <tr><td>Views</td><td>{{.Views}}</td></tr>
</table> </table>
{{end}} {{end}}

1
server.go

@ -55,6 +55,7 @@ func main() {
e.GET("/:id/stats", func(c echo.Context) error { e.GET("/:id/stats", func(c echo.Context) error {
n, code := load(c, db) n, code := load(c, db)
n.prepare()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
e.Renderer.Render(buf, "Stats", n, c) e.Renderer.Render(buf, "Stats", n, c)
n.Content = template.HTML(buf.String()) n.Content = template.HTML(buf.String())

8
storage.go

@ -149,16 +149,14 @@ func load(c echo.Context, db *sql.DB) (Note, int) {
code := http.StatusNotFound code := http.StatusNotFound
return errPage(code), code return errPage(code), code
} }
var edited time.Time
if editedVal != nil {
edited = editedVal.(time.Time)
}
n := &Note{ n := &Note{
ID: id, ID: id,
Text: text, Text: text,
Views: views, Views: views,
Published: published, Published: published,
Edited: edited, }
if editedVal != nil {
n.Edited = editedVal.(time.Time)
} }
return *n, http.StatusOK return *n, http.StatusOK
} }

Loading…
Cancel
Save