commit bb8b7b1ae35aadcd2e457c2a202c3721e5c45da8 (tree)
parent a2bf753f537481b38a1ccc5809a84c59fbc6d57f
Author: Motiejus Jakštys <desired.mta@gmail.com>
Date: Sun, 7 Jun 2020 23:36:33 +0300
wip trees
Diffstat:
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/src/joplin2site/internal/note/tree.go b/src/joplin2site/internal/note/tree.go
@@ -31,15 +31,15 @@ func ListNotes(dir string) (Notes, error) {
}
// SubPages returns immediate Pages of a tree
-func (t *Tree) SubPages(name string) ([]Page, error) {
+func (n Notes) SubPages(name string) (Notes, error) {
// Find the parent note that will be the parent of the sub-notebook.
var parentID string
- for _, inote := range t.Notes {
- if inote.Type != note.ItemTypeFolder {
+ for _, note := range n {
+ if note.Type != ItemTypeFolder {
continue
}
- if inote.Title == name {
- parentID = inote.ID
+ if note.Title == name {
+ parentID = note.ID
}
}
@@ -102,3 +102,25 @@ func (n Notes) getFolderID(title string) string {
return parentID
}
+
+type tree map[string]children
+type children map[string]struct{}
+
+func buildTree(notes Notes) tree {
+ ret := make(tree)
+ for _, note := range notes {
+ if _, ok := ret[note.ParentID]; !ok {
+ ret[note.ParentID] = make(children)
+ }
+ ret[note.ParentID][note.ID] = struct{}{}
+ }
+ return ret
+}
+
+// flatten returns all children of a tree
+func (t tree) flatten(id string, acc tree) {
+ acc[id] = struct{}{}
+ for child := range t {
+ flatten(child, acc)
+ }
+}