Store title in frontmatter, make fname uid only
This commit is contained in:
parent
de66fb0b77
commit
bb775ec55f
2 changed files with 39 additions and 46 deletions
|
|
@ -58,16 +58,16 @@ func view(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func edit(w http.ResponseWriter, r *http.Request) {
|
||||
// user := r.Context().Value(middleware.ContextKey("user")).(string)
|
||||
user := r.Context().Value(middleware.ContextKey("user")).(string)
|
||||
|
||||
encodedTitle := r.PathValue("note")
|
||||
note, err := notes.LoadNote(encodedTitle)
|
||||
uid := r.PathValue("note")
|
||||
note, err := notes.LoadNote(uid)
|
||||
if err != nil {
|
||||
title := notes.DecodeTitle(encodedTitle)
|
||||
note = ¬es.Note{Title: title}
|
||||
note = ¬es.Note{Title: "", Uid: uid}
|
||||
note = notes.NewNote("", user)
|
||||
}
|
||||
|
||||
urlSave := myurls.Reverse("save", urls.Repl{"note": encodedTitle})
|
||||
urlSave := myurls.Reverse("save", urls.Repl{"note": uid})
|
||||
context := templ.Ctx{"note": note, "urlSave": urlSave, "text": string(note.Body)}
|
||||
err = templ.RenderTemplate(w, r, "edit.tmpl.html", context)
|
||||
if err != nil {
|
||||
|
|
@ -85,11 +85,9 @@ func new(w http.ResponseWriter, r *http.Request) {
|
|||
title = "<New Note>"
|
||||
}
|
||||
|
||||
note := ¬es.Note{Title: title, Owner: user}
|
||||
note.Save()
|
||||
notes.Notes.Add(note)
|
||||
note := notes.NewNote(title, user)
|
||||
|
||||
urlEdit := myurls.Reverse("edit", urls.Repl{"note": note.EncodedTitle()})
|
||||
urlEdit := myurls.Reverse("edit", urls.Repl{"note": note.Uid})
|
||||
http.Redirect(w, r, urlEdit, http.StatusFound)
|
||||
}
|
||||
|
||||
|
|
@ -110,8 +108,8 @@ func delete(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func save(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value(middleware.ContextKey("user")).(string)
|
||||
oldTitle := r.PathValue("note")
|
||||
note, ok := notes.Notes.GetOne(user, oldTitle)
|
||||
uid := r.PathValue("note")
|
||||
note, ok := notes.Notes.GetOne(user, uid)
|
||||
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
|
|
@ -125,11 +123,7 @@ func save(w http.ResponseWriter, r *http.Request) {
|
|||
note.Body = []byte(body)
|
||||
note.Save()
|
||||
|
||||
if oldTitle != note.EncodedTitle() {
|
||||
notes.DeleteNote(oldTitle)
|
||||
}
|
||||
|
||||
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": note.EncodedTitle()}), http.StatusFound)
|
||||
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": note.Uid}), http.StatusFound)
|
||||
}
|
||||
|
||||
func togglebox(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -150,7 +144,7 @@ func togglebox(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
note.ToggleBox(nthBox)
|
||||
|
||||
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": note.EncodedTitle()}), http.StatusFound)
|
||||
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": note.Uid}), http.StatusFound)
|
||||
}
|
||||
|
||||
type titleAndURL struct {
|
||||
|
|
@ -170,7 +164,7 @@ func list(w http.ResponseWriter, r *http.Request) {
|
|||
for _, note := range ns {
|
||||
titlesAndUrls = append(
|
||||
titlesAndUrls,
|
||||
titleAndURL{Title: note.Title, URL: myurls.Reverse("view", urls.Repl{"note": note.EncodedTitle()})},
|
||||
titleAndURL{Title: note.Title, URL: myurls.Reverse("view", urls.Repl{"note": note.Uid})},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue