feat: log when changing note states
This commit is contained in:
@ -6,7 +6,7 @@ import (
|
||||
"donniemarko/internal/note"
|
||||
"donniemarko/internal/storage"
|
||||
"os"
|
||||
// "log"
|
||||
"log"
|
||||
)
|
||||
|
||||
type NotesHandler struct {
|
||||
@ -23,6 +23,7 @@ func (h *NotesHandler) HandleCreate(path string) error {
|
||||
return err
|
||||
}
|
||||
h.storage.Create(note)
|
||||
log.Printf("Created or updated note '%s'\n", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -33,9 +34,12 @@ func (h *NotesHandler) HandleModify(path string) error {
|
||||
func (h *NotesHandler) HandleDelete(path string) error {
|
||||
id := note.GenerateNoteID(path)
|
||||
h.storage.Delete(id)
|
||||
log.Printf("Deleted note '%s' from index\n", path)
|
||||
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) {
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
@ -53,8 +57,8 @@ func ParseNoteFile(path string) (*note.Note, error) {
|
||||
nn.ID = id
|
||||
nn.Content = string(content)
|
||||
nn.Title = note.ExtractTitle(nn.Content)
|
||||
// Use filename as title if no heading found
|
||||
if nn.Title == "" {
|
||||
// Use filename as title if no heading found
|
||||
nn.Title = filepath.Base(path)
|
||||
}
|
||||
nn.UpdatedAt = fileInfo.ModTime()
|
||||
|
||||
Reference in New Issue
Block a user