Change / logic

This commit is contained in:
Alex Myasoedov 2018-01-18 20:15:44 -05:00
parent a2c5c788d2
commit d844211d22
No known key found for this signature in database
GPG key ID: D261413C245982F0

20
main.go
View file

@ -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,
})
})