From d844211d220f0a9a254d5c5eb13dac7f5e693df0 Mon Sep 17 00:00:00 2001 From: Alex Myasoedov Date: Thu, 18 Jan 2018 20:15:44 -0500 Subject: [PATCH] Change / logic --- main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 1ff7682..92acc86 100644 --- a/main.go +++ b/main.go @@ -75,23 +75,22 @@ func NewApp() *gin.Engine { r.Static("/static", "./static") r.GET("/", func(c *gin.Context) { - + isNew := c.Query("new") latest := files.LatestFileIn("slides") log.WithFields(log.Fields{ - "name": latest, + "name": latest, + "isNew": isNew, }).Info("Restoring latest point") - var path string - if latest == "" { + var path, name string + if latest == "" || isNew != "" { haikunator := haikunator.New() haikunator.TokenLength = 0 - name := haikunator.Haikunate() - path = fmt.Sprintf("slides/%s.md", name) + name = haikunator.Haikunate() } else { - name := latest - path = fmt.Sprintf("slides/%s", name) - + name = strings.Replace(latest, ".md", "", 1) } + path = fmt.Sprintf("slides/%s.md", name) log.WithFields(log.Fields{ "path": path, @@ -100,7 +99,8 @@ func NewApp() *gin.Engine { session.Set("name", path) session.Save() - c.HTML(200, "index.tmpl", gin.H{ + c.Writer.Header().Set("Location", fmt.Sprintf("/stash/edit/%s", name)) + c.HTML(302, "index.tmpl", gin.H{ "pubTo": path, }) })