Store and save metadata in frontmatter

This commit is contained in:
Maximilian Friedersdorff 2025-08-08 21:10:10 +01:00
parent 03b6bb12ca
commit de66fb0b77
2 changed files with 81 additions and 7 deletions

View file

@ -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 := &notes.Note{Title: title}
note := &notes.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 := &notes.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() {