From 71548c4e7f38245d752e80f9753da6ad7c0bd087 Mon Sep 17 00:00:00 2001 From: Joey Sabey Date: Sat, 18 May 2024 07:49:02 +0100 Subject: [PATCH] feature: update TagMap Reindex() to unmarshal actual Note objects --- tag/tagmap.go | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/tag/tagmap.go b/tag/tagmap.go index 7297511..1e943bf 100644 --- a/tag/tagmap.go +++ b/tag/tagmap.go @@ -5,9 +5,8 @@ import ( "os" "path/filepath" + "github.com/omnikron13/zelkata/note" "github.com/omnikron13/zelkata/paths" - - "gopkg.in/yaml.v3" ) // TagMap is a map of tag names to Tag structs, representing all tags in the system. @@ -77,30 +76,17 @@ func (m *TagMap) Reindex() error { return err } for _, file := range files { - // TODO: rework Note/Meta so they can be unmarshalled into properly and replace this hacky generic map - note := map[string]any{} - b, err := os.ReadFile(filepath.Join(paths.Notes(), file.Name())) - if err != nil { - return err - } - if err := yaml.Unmarshal(b, note); err != nil { + note, err := note.ReadFile(filepath.Join(paths.Notes(), file.Name())) + if err != nil { return err } - tags, ok := note["tags"].([]any) - if !ok { - return errors.New("Tags field is not an array") - } - for _, t := range tags { - t, ok := t.(string) - if !ok { - return errors.New("Tag is not a string") - } + for _, t := range note.Tags { tag := m.Get(t) if tag == nil { tag = &Tag{Name: t, Notes: []string{}} _ = m.Add(t, tag) } - tag.Notes = append(tag.Notes, note["id"].(string)) + tag.Notes = append(tag.Notes, note.ID) } } return nil