aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/index/index.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-05-01 16:32:27 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-05-02 17:15:25 -0400
commit966a1162a56652b4d56ffe003af05161841fb192 (patch)
treefe7facfaf5a1c75cbbd124077439500ab5988fd9 /pkg/index/index.go
parent35ec0f5afb9800b25bd813bccc57a16bc9f837c4 (diff)
Implement json output
Diffstat (limited to 'pkg/index/index.go')
-rw-r--r--pkg/index/index.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/pkg/index/index.go b/pkg/index/index.go
index 074b659..4bab21b 100644
--- a/pkg/index/index.go
+++ b/pkg/index/index.go
@@ -13,12 +13,12 @@ import (
)
type Document struct {
- Path string
- Title string `yaml:"title"`
- Date time.Time `yaml:"date"`
- FileTime time.Time
- Authors []string `yaml:"authors"`
- Tags []string `yaml:"tags"`
+ Path string `yaml:"-" json:"path"`
+ Title string `yaml:"title" json:"title"`
+ Date time.Time `yaml:"date" json:"date"`
+ FileTime time.Time `yaml:"-" json:"filetime"`
+ Authors []string `yaml:"authors" json:"authors"`
+ Tags []string `yaml:"tags" json:"tags"`
Links []string
OtherMeta string // unsure about how to handle this
}
@@ -205,7 +205,7 @@ func (idx Index) ParseOne(path string) (*Document, error) {
doc := &Document{}
doc.Path = path
- f, err := os.Open(string(path))
+ f, err := os.Open(path)
if err != nil {
return nil, err
}
@@ -224,12 +224,16 @@ func (idx Index) ParseOne(path string) (*Document, error) {
return nil, errors.New("Short read")
}
+ // FIXME: unmarshalling is **VERY** borked up rn
+ if err := yaml.Unmarshal(buf, &doc); err != nil {
+ return nil, err
+ }
// TODO: implement custom unmarshaller, for singular `Author`
- dec := yaml.NewDecoder(f)
+ // dec := yaml.NewDecoder(f)
// TODO: handle no yaml header error
- if err := dec.Decode(&doc); err != nil {
- panic(err)
- }
+ // if err := dec.Decode(&doc); err != nil {
+ // panic(err)
+ // }
// TODO: body parsing
@@ -239,6 +243,7 @@ func (idx Index) ParseOne(path string) (*Document, error) {
func (idx Index) Parse(paths []string, numWorkers uint) {
jobs := make(chan string, numWorkers)
results := make(chan Document, numWorkers)
+ idx.Documents = make(map[string]*Document, len(paths))
wg := &sync.WaitGroup{}
wg.Add(int(numWorkers))