feat: log when changing note states

This commit is contained in:
2026-02-01 18:26:21 +01:00
parent 92a6f84540
commit 4458ba2d15

View File

@ -6,7 +6,7 @@ import (
"donniemarko/internal/note" "donniemarko/internal/note"
"donniemarko/internal/storage" "donniemarko/internal/storage"
"os" "os"
// "log" "log"
) )
type NotesHandler struct { type NotesHandler struct {
@ -23,6 +23,7 @@ func (h *NotesHandler) HandleCreate(path string) error {
return err return err
} }
h.storage.Create(note) h.storage.Create(note)
log.Printf("Created or updated note '%s'\n", path)
return nil return nil
} }
@ -33,9 +34,12 @@ func (h *NotesHandler) HandleModify(path string) error {
func (h *NotesHandler) HandleDelete(path string) error { func (h *NotesHandler) HandleDelete(path string) error {
id := note.GenerateNoteID(path) id := note.GenerateNoteID(path)
h.storage.Delete(id) h.storage.Delete(id)
log.Printf("Deleted note '%s' from index\n", path)
return nil return nil
} }
// ParseNoteFile reads a note file on the file system and returns a note struct
// populated with the metadata and content extracted from the file
func ParseNoteFile(path string) (*note.Note, error) { func ParseNoteFile(path string) (*note.Note, error) {
content, err := os.ReadFile(path) content, err := os.ReadFile(path)
if err != nil { if err != nil {
@ -53,8 +57,8 @@ func ParseNoteFile(path string) (*note.Note, error) {
nn.ID = id nn.ID = id
nn.Content = string(content) nn.Content = string(content)
nn.Title = note.ExtractTitle(nn.Content) nn.Title = note.ExtractTitle(nn.Content)
if nn.Title == "" {
// Use filename as title if no heading found // Use filename as title if no heading found
if nn.Title == "" {
nn.Title = filepath.Base(path) nn.Title = filepath.Base(path)
} }
nn.UpdatedAt = fileInfo.ModTime() nn.UpdatedAt = fileInfo.ModTime()