Files
donniemarko/internal/scanner/handler.go
adminoo 9d1254244f feat(release): v0.1.0
commit 06ed2c3cbe
Author: adminoo <git@kadath.corp>
Date:   Tue Feb 3 11:34:24 2026 +0100

    fix: changed detected by scanner but no updated by render layer

commit 01dcaf882a
Author: adminoo <git@kadath.corp>
Date:   Tue Feb 3 10:19:05 2026 +0100

    feat: VERSION bumb

commit 229223f77a
Author: adminoo <git@kadath.corp>
Date:   Tue Feb 3 09:53:08 2026 +0100

    feat: filter and search by tag

commit cb11e34798
Author: adminoo <git@kadath.corp>
Date:   Tue Feb 3 09:41:03 2026 +0100

    feat: tag system

commit 3f5cf0d673
Author: adminoo <git@kadath.corp>
Date:   Tue Feb 3 09:15:29 2026 +0100

    feat: sqlite storage draft

commit d6617cec02
Author: adminoo <git@kadath.corp>
Date:   Tue Feb 3 09:04:11 2026 +0100

    feat: metadata draft

commit 7238d02a13
Author: adminoo <git@kadath.corp>
Date:   Mon Feb 2 10:18:42 2026 +0100

    fix: body overflowing

commit 16ff836274
Author: adminoo <git@kadath.corp>
Date:   Mon Feb 2 10:09:01 2026 +0100

    feat: tests for http handlers and render package

commit 36ac3f03aa
Author: adminoo <git@kadath.corp>
Date:   Mon Feb 2 09:45:29 2026 +0100

    feat: Dark theme, placeholder metadata panel

commit e6923fa4f5
Author: adminoo <git@kadath.corp>
Date:   Sun Feb 1 18:26:59 2026 +0100

    fix: uneeded func + uneeded bogus note creation logic

commit 4458ba2d15
Author: adminoo <git@kadath.corp>
Date:   Sun Feb 1 18:26:21 2026 +0100

    feat: log when changing note states

commit 92a6f84540
Author: adminoo <git@kadath.corp>
Date:   Sun Feb 1 16:55:40 2026 +0100

    possibly first working draft

commit e27aadc603
Author: adminoo <git@kadath.corp>
Date:   Sun Feb 1 11:55:16 2026 +0100

    draft shits
2026-02-03 12:01:17 +01:00

71 lines
1.5 KiB
Go

package scanner
import (
"path/filepath"
"donniemarko/internal/note"
"donniemarko/internal/storage"
"log"
"os"
)
type NotesHandler struct {
storage storage.Storage
}
func NewNotesHandler(storage storage.Storage) *NotesHandler {
return &NotesHandler{storage: storage}
}
func (h *NotesHandler) HandleCreate(path string) error {
note, err := ParseNoteFile(path)
if err != nil {
return err
}
if err := h.storage.Create(note); err != nil {
return err
}
log.Printf("Created or updated note '%s'\n", path)
return nil
}
func (h *NotesHandler) HandleModify(path string) error {
return h.HandleCreate(path)
}
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 {
return nil, err
}
// Get file info to get modification time
fileInfo, err := os.Stat(path)
if err != nil {
return nil, err
}
id := note.GenerateNoteID(path)
nn := note.NewNote()
nn.ID = id
nn.Path = path
nn.Content = string(content)
nn.Title = note.ExtractTitle(nn.Content)
// Use filename as title if no heading found
if nn.Title == "" {
nn.Title = filepath.Base(path)
}
nn.UpdatedAt = fileInfo.ModTime()
nn.Size = fileInfo.Size()
return nn, nil
}