possibly first working draft
This commit is contained in:
@ -1,15 +1,22 @@
|
||||
package scanner
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"donniemarko/internal/note"
|
||||
"donniemarko/internal/storage"
|
||||
"os"
|
||||
// "log"
|
||||
)
|
||||
|
||||
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 {
|
||||
@ -34,9 +41,23 @@ func ParseNoteFile(path string) (*note.Note, error) {
|
||||
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.Content = string(content)
|
||||
nn.Title = note.ExtractTitle(nn.Content)
|
||||
if nn.Title == "" {
|
||||
// Use filename as title if no heading found
|
||||
nn.Title = filepath.Base(path)
|
||||
}
|
||||
nn.UpdatedAt = fileInfo.ModTime()
|
||||
nn.CreatedAt = fileInfo.ModTime()
|
||||
return nn, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user