// SavePostHandler ... func SavePostHandler(s *session.Session, rnd render.Render, r *http.Request, db *mgo.Database) { if !s.IsAuthorized { rnd.Redirect("/") } id := r.FormValue("id") title := r.FormValue("title") contentMarkdown := r.FormValue("content") contentHTML := utils.ConvertMarkdownToHTML(contentMarkdown) postDocument := documents.PostDocument{id, title, contentHTML, contentMarkdown} postsCollection := db.C("posts") if id != "" { postsCollection.UpdateId(id, postDocument) } else { id = utils.GenerateID() postDocument.ID = id postsCollection.Insert(postDocument) } rnd.Redirect("/") }
// GetHTMLHandler ... func GetHTMLHandler(rnd render.Render, r *http.Request) { md := r.FormValue("md") html := utils.ConvertMarkdownToHTML(md) rnd.JSON(200, map[string]interface{}{"html": html}) }