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("/") }
func GetHtmlHandler(rnd render.Render, r *http.Request) { md := r.FormValue("md") html := utils.ConvertMarkdownToHtml(md) rnd.JSON(200, map[string]interface{}{"html": html}) }