Store and save metadata in frontmatter
This commit is contained in:
parent
03b6bb12ca
commit
de66fb0b77
2 changed files with 81 additions and 7 deletions
|
|
@ -78,12 +78,16 @@ func edit(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func new(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value(middleware.ContextKey("user")).(string)
|
||||
|
||||
title := r.FormValue("title")
|
||||
if len(title) == 0 {
|
||||
title = "<New Note>"
|
||||
}
|
||||
|
||||
note := ¬es.Note{Title: title}
|
||||
note := ¬es.Note{Title: title, Owner: user}
|
||||
note.Save()
|
||||
notes.Notes.Add(note)
|
||||
|
||||
urlEdit := myurls.Reverse("edit", urls.Repl{"note": note.EncodedTitle()})
|
||||
http.Redirect(w, r, urlEdit, http.StatusFound)
|
||||
|
|
@ -105,13 +109,20 @@ func delete(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func save(w http.ResponseWriter, r *http.Request) {
|
||||
// user := r.Context().Value(middleware.ContextKey("user")).(string)
|
||||
|
||||
user := r.Context().Value(middleware.ContextKey("user")).(string)
|
||||
oldTitle := r.PathValue("note")
|
||||
note, ok := notes.Notes.GetOne(user, oldTitle)
|
||||
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
|
||||
title := r.FormValue("title")
|
||||
body := r.FormValue("body")
|
||||
|
||||
note := ¬es.Note{Title: title, Body: []byte(body)}
|
||||
log.Printf("About to save to note %+v", note)
|
||||
note.Title = title
|
||||
note.Body = []byte(body)
|
||||
note.Save()
|
||||
|
||||
if oldTitle != note.EncodedTitle() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue