|
|
|
@ -2,6 +2,10 @@
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/ImVexed/muon"
|
|
|
|
@ -26,7 +30,7 @@ func main() {
|
|
|
|
|
|
|
|
|
|
as := &AppState{
|
|
|
|
|
Settings: Settings{
|
|
|
|
|
Directory: ".",
|
|
|
|
|
Directory: "K:/private/aveldhousen/notes/posts",
|
|
|
|
|
Orientation: "vertical",
|
|
|
|
|
},
|
|
|
|
|
Notes: []Note{},
|
|
|
|
@ -62,13 +66,36 @@ type Settings struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type LoadNoteResult struct {
|
|
|
|
|
Error error
|
|
|
|
|
Notes []Note
|
|
|
|
|
Error error `json:"error,omitempty"`
|
|
|
|
|
Notes []Note `json:"notes"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (as *AppState) LoadNotes() LoadNoteResult {
|
|
|
|
|
notes := []Note{}
|
|
|
|
|
|
|
|
|
|
if err := filepath.Walk(as.Settings.Directory, func(path string, info os.FileInfo, err error) error {
|
|
|
|
|
fileExt := filepath.Ext(info.Name())
|
|
|
|
|
if fileExt == "md" || fileExt == "txt" || fileExt == "utf" || fileExt == "todo" {
|
|
|
|
|
content, err := ioutil.ReadFile(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notes = append(notes, Note{
|
|
|
|
|
Title: info.Name(),
|
|
|
|
|
LastModified: info.ModTime(),
|
|
|
|
|
Created: info.ModTime(),
|
|
|
|
|
Content: string(content),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}); err != nil {
|
|
|
|
|
return LoadNoteResult{Error: fmt.Errorf("could not enumerate notes: %w", err)}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return LoadNoteResult{
|
|
|
|
|
Notes: as.Notes,
|
|
|
|
|
Notes: notes,
|
|
|
|
|
Error: nil,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|